@@ -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,17 @@ function Test-AzureFirewallCRUD {
96
107
$natRule1TranslatedAddress = " 10.1.2.3"
97
108
$natRule1TranslatedPort = " 91"
98
109
110
+ # AzureFirewallNatRule 2
111
+ $natRule2Name = " natRule2"
112
+ $natRule2Desc = " desc2"
113
+ $natRule2SourceAddress1 = " 10.0.0.0"
114
+ $natRule2SourceAddress2 = " 111.1.0.0/24"
115
+ $natRule2Protocol1 = " UDP"
116
+ $natRule2Protocol2 = " TCP"
117
+ $natRule2DestinationPort1 = " 95"
118
+ $natRule2TranslatedFqdn = " server1.internal.com"
119
+ $natRule2TranslatedPort = " 96"
120
+
99
121
try {
100
122
# Create the resource group
101
123
$resourceGroup = New-AzResourceGroup - Name $rgname - Location $location - Tags @ { testtag = " testval" }
@@ -189,6 +211,13 @@ function Test-AzureFirewallCRUD {
189
211
# Create Network Rule Collection
190
212
$netRc = New-AzFirewallNetworkRuleCollection - Name $networkRcName - Priority $networkRcPriority - Rule $networkRule - ActionType $networkRcActionType
191
213
214
+ # Create Second Network Rule
215
+ $networkRule2 = New-AzFirewallNetworkRule - Name $networkRule2Name - Description $networkRule2Desc - Protocol $networkRule2Protocol1 , $networkRule2Protocol2 - SourceAddress $networkRule2SourceAddress1 , $networkRule2SourceAddress2 - DestinationFqdn $networkRule2DestinationFqdn1 - DestinationPort $networkRule2DestinationPort1
216
+ $networkRule2.AddProtocol ($networkRule2Protocol3 )
217
+
218
+ # Add this second Network Rule to the rule collection
219
+ $netRc.AddRule ($networkRule2 )
220
+
192
221
# Create a NAT rule
193
222
$natRule = New-AzFirewallNatRule - Name $natRule1Name - Description $natRule1Desc - Protocol $natRule1Protocol1 - SourceAddress $natRule1SourceAddress1 , $natRule1SourceAddress2 - DestinationAddress $publicip.IpAddress - DestinationPort $natRule1DestinationPort1 - TranslatedAddress $natRule1TranslatedAddress - TranslatedPort $natRule1TranslatedPort
194
223
$natRule.AddProtocol ($natRule1Protocol2 )
@@ -203,9 +232,16 @@ function Test-AzureFirewallCRUD {
203
232
} " The argument `" ICMP`" does not belong to the set"
204
233
Assert-ThrowsContains { $natRule.AddProtocol (" ICMP" ) } " Invalid protocol"
205
234
235
+ # Create second NAT rule
236
+ $natRule2 = New-AzFirewallNatRule - Name $natRule2Name - Description $natRule2Desc - Protocol $natRule2Protocol1 - SourceAddress $natRule2SourceAddress1 , $natRule2SourceAddress2 - DestinationAddress $publicip.IpAddress - DestinationPort $natRule2DestinationPort1 - TranslatedFqdn $natRule2TranslatedFqdn - TranslatedPort $natRule2TranslatedPort
237
+ $natRule2.AddProtocol ($natRule2Protocol2 )
238
+
206
239
# Create a NAT Rule Collection
207
240
$natRc = New-AzFirewallNatRuleCollection - Name $natRcName - Priority $natRcPriority - Rule $natRule
208
241
242
+ # Add second NAT Rule to rule Collection
243
+ $natRc.AddRule ($natRule2 )
244
+
209
245
# Add ApplicationRuleCollections to the Firewall using method AddApplicationRuleCollection
210
246
$azureFirewall.AddApplicationRuleCollection ($appRc )
211
247
$azureFirewall.AddApplicationRuleCollection ($appRc2 )
@@ -245,10 +281,10 @@ function Test-AzureFirewallCRUD {
245
281
Assert-AreEqual 1 @ ($getAzureFirewall.ApplicationRuleCollections [1 ].Rules).Count
246
282
247
283
Assert-AreEqual 1 @ ($getAzureFirewall.NatRuleCollections ).Count
248
- Assert-AreEqual 1 @ ($getAzureFirewall.NatRuleCollections [0 ].Rules).Count
284
+ Assert-AreEqual 2 @ ($getAzureFirewall.NatRuleCollections [0 ].Rules).Count
249
285
250
286
Assert-AreEqual 1 @ ($getAzureFirewall.NetworkRuleCollections ).Count
251
- Assert-AreEqual 1 @ ($getAzureFirewall.NetworkRuleCollections [0 ].Rules).Count
287
+ Assert-AreEqual 2 @ ($getAzureFirewall.NetworkRuleCollections [0 ].Rules).Count
252
288
253
289
$appRc = $getAzureFirewall.GetApplicationRuleCollectionByName ($appRcName )
254
290
$appRule = $appRc.GetRuleByName ($appRule1Name )
@@ -329,7 +365,7 @@ function Test-AzureFirewallCRUD {
329
365
Assert-AreEqual $appRule1Fqdn1 $appRule.TargetFqdns [0 ]
330
366
Assert-AreEqual $appRule1Fqdn2 $appRule.TargetFqdns [1 ]
331
367
332
- # Verify NAT rule collection and NAT rule
368
+ # Verify NAT rule collection and NAT rules
333
369
$natRc = $getAzureFirewall.GetNatRuleCollectionByName ($natRcName )
334
370
$natRule = $natRc.GetRuleByName ($natRule1Name )
335
371
@@ -356,7 +392,29 @@ function Test-AzureFirewallCRUD {
356
392
Assert-AreEqual $natRule1TranslatedAddress $natRule.TranslatedAddress
357
393
Assert-AreEqual $natRule1TranslatedPort $natRule.TranslatedPort
358
394
359
- # Verify network rule collection and network rule
395
+ $natRule2 = $natRc.GetRuleByName ($natRule2Name )
396
+
397
+ Assert-AreEqual $natRule2Name $natRule2.Name
398
+ Assert-AreEqual $natRule2Desc $natRule2.Description
399
+
400
+ Assert-AreEqual 2 $natRule2.SourceAddresses.Count
401
+ Assert-AreEqual $natRule2SourceAddress1 $natRule2.SourceAddresses [0 ]
402
+ Assert-AreEqual $natRule2SourceAddress2 $natRule2.SourceAddresses [1 ]
403
+
404
+ Assert-AreEqual 1 $natRule2.DestinationAddresses.Count
405
+ Assert-AreEqual $publicip.IpAddress $natRule2.DestinationAddresses [0 ]
406
+
407
+ Assert-AreEqual 2 $natRule2.Protocols.Count
408
+ Assert-AreEqual $natRule2Protocol1 $natRule2.Protocols [0 ]
409
+ Assert-AreEqual $natRule2Protocol2 $natRule2.Protocols [1 ]
410
+
411
+ Assert-AreEqual 1 $natRule2.DestinationPorts.Count
412
+ Assert-AreEqual $natRule2DestinationPort1 $natRule2.DestinationPorts [0 ]
413
+
414
+ Assert-AreEqual $natRule2TranslatedFqdn $natRule2.TranslatedFqdn
415
+ Assert-AreEqual $natRule2TranslatedPort $natRule2.TranslatedPort
416
+
417
+ # Verify network rule collection and network rules
360
418
$networkRc = $getAzureFirewall.GetNetworkRuleCollectionByName ($networkRcName )
361
419
$networkRule = $networkRc.GetRuleByName ($networkRule1Name )
362
420
@@ -382,6 +440,26 @@ function Test-AzureFirewallCRUD {
382
440
Assert-AreEqual 1 $networkRule.DestinationPorts.Count
383
441
Assert-AreEqual $networkRule1DestinationPort1 $networkRule.DestinationPorts [0 ]
384
442
443
+ $networkRule2 = $networkRc.GetRuleByName ($networkRule2Name )
444
+
445
+ Assert-AreEqual $networkRule2Name $networkRule2.Name
446
+ Assert-AreEqual $networkRule2Desc $networkRule2.Description
447
+
448
+ Assert-AreEqual 2 $networkRule2.SourceAddresses.Count
449
+ Assert-AreEqual $networkRule2SourceAddress1 $networkRule2.SourceAddresses [0 ]
450
+ Assert-AreEqual $networkRule2SourceAddress2 $networkRule2.SourceAddresses [1 ]
451
+
452
+ Assert-AreEqual 1 $networkRule2.DestinationFqdns.Count
453
+ Assert-AreEqual $networkRule2DestinationFqdn1 $networkRule2.DestinationFqdns [0 ]
454
+
455
+ Assert-AreEqual 3 $networkRule2.Protocols.Count
456
+ Assert-AreEqual $networkRule2Protocol1 $networkRule2.Protocols [0 ]
457
+ Assert-AreEqual $networkRule2Protocol2 $networkRule2.Protocols [1 ]
458
+ Assert-AreEqual $networkRule2Protocol3 $networkRule2.Protocols [2 ]
459
+
460
+ Assert-AreEqual 1 $networkRule2.DestinationPorts.Count
461
+ Assert-AreEqual $networkRule2DestinationPort1 $networkRule2.DestinationPorts [0 ]
462
+
385
463
# Delete AzureFirewall
386
464
$delete = Remove-AzFirewall - ResourceGroupName $rgname - name $azureFirewallName - PassThru - Force
387
465
Assert-AreEqual true $delete
0 commit comments