@@ -80,6 +80,17 @@ function Test-AzureFirewallCRUD {
80
80
$networkRule1Protocol3 = " ICMP"
81
81
$networkRule1DestinationPort1 = " 90"
82
82
83
+ # AzureFirewallNetworkRule 2
84
+ $networkRule2Name = " networkRule2"
85
+ $networkRule2Desc = " desc2"
86
+ $networkRule2SourceAddress1 = " 10.0.0.0"
87
+ $networkRule2SourceAddress2 = " 111.1.0.0/24"
88
+ $networkRule2DestinationFqdn1 = " www.bing.com"
89
+ $networkRule2Protocol1 = " UDP"
90
+ $networkRule2Protocol2 = " TCP"
91
+ $networkRule2Protocol3 = " ICMP"
92
+ $networkRule2DestinationPort1 = " 80"
93
+
83
94
# AzureFirewallNatRuleCollection
84
95
$natRcName = " natRc"
85
96
$natRcPriority = 200
@@ -96,6 +107,18 @@ function Test-AzureFirewallCRUD {
96
107
$natRule1TranslatedAddress = " 10.1.2.3"
97
108
$natRule1TranslatedPort = " 91"
98
109
110
+ # AzureFirewallNatRule 2
111
+ $natRule1Name = " natRule2"
112
+ $natRule1Desc = " desc2"
113
+ $natRule1SourceAddress1 = " 10.0.0.0"
114
+ $natRule1SourceAddress2 = " 111.1.0.0/24"
115
+ $natRule1DestinationAddress1 = " 1.2.3.4"
116
+ $natRule1Protocol1 = " UDP"
117
+ $natRule1Protocol2 = " TCP"
118
+ $natRule1DestinationPort1 = " 95"
119
+ $natRule1TranslatedFqdn = " server1.internal.com"
120
+ $natRule1TranslatedPort = " 96"
121
+
99
122
try {
100
123
# Create the resource group
101
124
$resourceGroup = New-AzResourceGroup - Name $rgname - Location $location - Tags @ { testtag = " testval" }
@@ -189,6 +212,13 @@ function Test-AzureFirewallCRUD {
189
212
# Create Network Rule Collection
190
213
$netRc = New-AzFirewallNetworkRuleCollection - Name $networkRcName - Priority $networkRcPriority - Rule $networkRule - ActionType $networkRcActionType
191
214
215
+ # Create Second Network Rule
216
+ $networkRule2 = New-AzFirewallNetworkRule - Name $networkRule2Name - Description $networkRule2Desc - Protocol $networkRule2Protocol1 , $networkRule2Protocol2 - SourceAddress $networkRule2SourceAddress1 , $networkRule2SourceAddress2 - DestinationFqdn $networkRule2DestinationFqdn1 - DestinationPort $networkRule2DestinationPort1
217
+ $networkRule2.AddProtocol ($networkRule2Protocol3 )
218
+
219
+ # Add this second Network Rule to the rule collection
220
+ $netRc.AddRule ($networkRule2 )
221
+
192
222
# Create a NAT rule
193
223
$natRule = New-AzFirewallNatRule - Name $natRule1Name - Description $natRule1Desc - Protocol $natRule1Protocol1 - SourceAddress $natRule1SourceAddress1 , $natRule1SourceAddress2 - DestinationAddress $publicip.IpAddress - DestinationPort $natRule1DestinationPort1 - TranslatedAddress $natRule1TranslatedAddress - TranslatedPort $natRule1TranslatedPort
194
224
$natRule.AddProtocol ($natRule1Protocol2 )
@@ -203,9 +233,16 @@ function Test-AzureFirewallCRUD {
203
233
} " The argument `" ICMP`" does not belong to the set"
204
234
Assert-ThrowsContains { $natRule.AddProtocol (" ICMP" ) } " Invalid protocol"
205
235
236
+ # Create second NAT rule
237
+ $natRule2 = New-AzFirewallNatRule - Name $natRule2Name - Description $natRule2Desc - Protocol $natRule2Protocol1 - SourceAddress $natRule2SourceAddress1 , $natRule2SourceAddress2 - DestinationAddress $publicip.IpAddress - DestinationPort $natRule2DestinationPort1 - TranslatedFqdn $natRule2TranslatedFqdn - TranslatedPort $natRule2TranslatedPort
238
+ $natRule2.AddProtocol ($natRule2Protocol2 )
239
+
206
240
# Create a NAT Rule Collection
207
241
$natRc = New-AzFirewallNatRuleCollection - Name $natRcName - Priority $natRcPriority - Rule $natRule
208
242
243
+ # Add second NAT Rule to rule Collection
244
+ $natRc.AddRule ($$ natRule2)
245
+
209
246
# Add ApplicationRuleCollections to the Firewall using method AddApplicationRuleCollection
210
247
$azureFirewall.AddApplicationRuleCollection ($appRc )
211
248
$azureFirewall.AddApplicationRuleCollection ($appRc2 )
@@ -245,10 +282,10 @@ function Test-AzureFirewallCRUD {
245
282
Assert-AreEqual 1 @ ($getAzureFirewall.ApplicationRuleCollections [1 ].Rules).Count
246
283
247
284
Assert-AreEqual 1 @ ($getAzureFirewall.NatRuleCollections ).Count
248
- Assert-AreEqual 1 @ ($getAzureFirewall.NatRuleCollections [0 ].Rules).Count
285
+ Assert-AreEqual 2 @ ($getAzureFirewall.NatRuleCollections [0 ].Rules).Count
249
286
250
287
Assert-AreEqual 1 @ ($getAzureFirewall.NetworkRuleCollections ).Count
251
- Assert-AreEqual 1 @ ($getAzureFirewall.NetworkRuleCollections [0 ].Rules).Count
288
+ Assert-AreEqual 2 @ ($getAzureFirewall.NetworkRuleCollections [0 ].Rules).Count
252
289
253
290
$appRc = $getAzureFirewall.GetApplicationRuleCollectionByName ($appRcName )
254
291
$appRule = $appRc.GetRuleByName ($appRule1Name )
@@ -329,7 +366,7 @@ function Test-AzureFirewallCRUD {
329
366
Assert-AreEqual $appRule1Fqdn1 $appRule.TargetFqdns [0 ]
330
367
Assert-AreEqual $appRule1Fqdn2 $appRule.TargetFqdns [1 ]
331
368
332
- # Verify NAT rule collection and NAT rule
369
+ # Verify NAT rule collection and NAT rules
333
370
$natRc = $getAzureFirewall.GetNatRuleCollectionByName ($natRcName )
334
371
$natRule = $natRc.GetRuleByName ($natRule1Name )
335
372
@@ -356,7 +393,29 @@ function Test-AzureFirewallCRUD {
356
393
Assert-AreEqual $natRule1TranslatedAddress $natRule.TranslatedAddress
357
394
Assert-AreEqual $natRule1TranslatedPort $natRule.TranslatedPort
358
395
359
- # Verify network rule collection and network rule
396
+ $natRule2 = $natRc.GetRuleByName ($natRule2Name )
397
+
398
+ Assert-AreEqual $natRule2Name $natRule2.Name
399
+ Assert-AreEqual $natRule2Desc $natRule2.Description
400
+
401
+ Assert-AreEqual 2 $natRule2.SourceAddresses.Count
402
+ Assert-AreEqual $natRule2SourceAddress1 $natRule2.SourceAddresses [0 ]
403
+ Assert-AreEqual $natRule2SourceAddress2 $natRule2.SourceAddresses [1 ]
404
+
405
+ Assert-AreEqual 1 $natRule2.DestinationAddresses.Count
406
+ Assert-AreEqual $publicip.IpAddress $natRule2.DestinationAddresses [0 ]
407
+
408
+ Assert-AreEqual 2 $natRule2.Protocols.Count
409
+ Assert-AreEqual $natRule2Protocol1 $natRule2.Protocols [0 ]
410
+ Assert-AreEqual $natRule2Protocol2 $natRule2.Protocols [1 ]
411
+
412
+ Assert-AreEqual 1 $natRule2.DestinationPorts.Count
413
+ Assert-AreEqual $natRule2DestinationPort1 $natRule2.DestinationPorts [0 ]
414
+
415
+ Assert-AreEqual $natRule2TranslatedFqdn $natRule2.TranslatedFqdn
416
+ Assert-AreEqual $natRule2TranslatedPort $natRule2.TranslatedPort
417
+
418
+ # Verify network rule collection and network rules
360
419
$networkRc = $getAzureFirewall.GetNetworkRuleCollectionByName ($networkRcName )
361
420
$networkRule = $networkRc.GetRuleByName ($networkRule1Name )
362
421
@@ -382,6 +441,26 @@ function Test-AzureFirewallCRUD {
382
441
Assert-AreEqual 1 $networkRule.DestinationPorts.Count
383
442
Assert-AreEqual $networkRule1DestinationPort1 $networkRule.DestinationPorts [0 ]
384
443
444
+ $networkRule2 = $networkRc.GetRuleByName ($networkRule2Name )
445
+
446
+ Assert-AreEqual $networkRule2Name $networkRule2.Name
447
+ Assert-AreEqual $networkRule2Desc $networkRule2.Description
448
+
449
+ Assert-AreEqual 2 $networkRule2.SourceAddresses.Count
450
+ Assert-AreEqual $networkRule2SourceAddress1 $networkRule2.SourceAddresses [0 ]
451
+ Assert-AreEqual $networkRule2SourceAddress2 $networkRule2.SourceAddresses [1 ]
452
+
453
+ Assert-AreEqual 1 $networkRule2.DestinationAddresses.Count
454
+ Assert-AreEqual $networkRule2DestinationAddress1 $networkRule2.DestinationAddresses [0 ]
455
+
456
+ Assert-AreEqual 3 $networkRule2.Protocols.Count
457
+ Assert-AreEqual $networkRule2Protocol1 $networkRule2.Protocols [0 ]
458
+ Assert-AreEqual $networkRule2Protocol2 $networkRule2.Protocols [1 ]
459
+ Assert-AreEqual $networkRule2Protocol3 $networkRule2.Protocols [2 ]
460
+
461
+ Assert-AreEqual 1 $networkRule2.DestinationPorts.Count
462
+ Assert-AreEqual $networkRule2DestinationPort1 $networkRule2.DestinationPorts [0 ]
463
+
385
464
# Delete AzureFirewall
386
465
$delete = Remove-AzFirewall - ResourceGroupName $rgname - name $azureFirewallName - PassThru - Force
387
466
Assert-AreEqual true $delete
@@ -449,6 +528,11 @@ function Test-AzureFirewallCRUDWithZones {
449
528
$networkRcPriority = 200
450
529
$networkRcActionType = " Deny"
451
530
531
+ # AzureFirewallNetworkRuleCollection2
532
+ $networkRcName2 = " networkRc2"
533
+ $networkRcPriority2 = 300
534
+ $networkRcActionType = " Deny"
535
+
452
536
# AzureFirewallNetworkRule 1
453
537
$networkRule1Name = " networkRule"
454
538
$networkRule1Desc = " desc1"
@@ -476,6 +560,18 @@ function Test-AzureFirewallCRUDWithZones {
476
560
$natRule1TranslatedAddress = " 10.1.2.3"
477
561
$natRule1TranslatedPort = " 91"
478
562
563
+ # AzureFirewallNatRule 2
564
+ $natRule2Name = " natRule2"
565
+ $natRule2Desc = " desc2"
566
+ $natRule2SourceAddress1 = " 10.0.0.0"
567
+ $natRule2SourceAddress2 = " 111.1.0.0/24"
568
+ $natRule2DestinationAddress1 = " 1.2.3.4"
569
+ $natRule2Protocol1 = " UDP"
570
+ $natRule2Protocol2 = " TCP"
571
+ $natRule2DestinationPort1 = " 9001"
572
+ $natRule2TranslatedFqdn = " httpserver.internal.com"
573
+ $natRule2TranslatedPort = " 9001"
574
+
479
575
try {
480
576
# Create the resource group
481
577
$resourceGroup = New-AzResourceGroup - Name $rgname - Location $location - Tags @ { testtag = " testval" }
0 commit comments