Skip to content

Commit 1336ea5

Browse files
Added Icmp rule testing
1 parent ac37298 commit 1336ea5

File tree

2 files changed

+351
-303
lines changed

2 files changed

+351
-303
lines changed

src/Network/Network.Test/ScenarioTests/NetworkSecurityGroupTests.ps1

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,11 @@ function Test-NetworkSecurityGroup-MultiValuedRules
275275

276276
# Create SecurityRule
277277
$securityRule1 = New-AzNetworkSecurityRuleConfig -Name $securityRule1Name -Description "desciption" -Protocol Tcp -SourcePortRange 23-45,80-90 -DestinationPortRange 46-56,70-80 -SourceAddressPrefix 10.10.20.0/24,192.168.0.0/24 -DestinationAddressPrefix 10.10.30.0/24,192.168.2.0/24 -Access Allow -Priority 123 -Direction Inbound
278-
$securityRule2 = New-AzNetworkSecurityRuleConfig -Name $securityRule2Name -Description "desciption" -Protocol Tcp -SourcePortRange 10-20,30-40 -DestinationPortRange 10-20,30-40 -SourceAddressPrefix Storage -DestinationAddressPrefix Storage -Access Allow -Priority 120 -Direction Inbound
278+
$securityRule2 = New-AzNetworkSecurityRuleConfig -Name $securityRule2Name -Description "desciption" -Protocol Tcp -SourcePortRange 10-20,30-40 -DestinationPortRange 10-20,30-40 -SourceAddressPrefix Storage -DestinationAddressPrefix Storage -Access Allow -Priority 120 -Direction Inbound
279+
$securityRule3 = New-AzNetworkSecurityRuleConfig -Name $securityRule3Name -Description "desciption" -Protocol Icmp -SourcePortRange 50-60,100-110 -DestinationPortRange 120-130,131-140 -SourceAddressPrefix Storage -DestinationAddressPrefix Storage -Access Allow -Priority 125 -Direction Inbound
279280

280281
# Create NetworkSecurityGroup
281-
$nsg = New-AzNetworkSecurityGroup -name $nsgName -ResourceGroupName $rgname -Location $location -SecurityRules $securityRule1,$securityRule2
282+
$nsg = New-AzNetworkSecurityGroup -name $nsgName -ResourceGroupName $rgname -Location $location -SecurityRules $securityRule1,$securityRule2,$securityRule3
282283

283284
# Get NetworkSecurityGroup
284285
$getNsg = Get-AzNetworkSecurityGroup -name $nsgName -ResourceGroupName $rgName
@@ -288,7 +289,7 @@ function Test-NetworkSecurityGroup-MultiValuedRules
288289
Assert-AreEqual $nsgName $getNsg.Name
289290
Assert-NotNull $getNsg.Location
290291
Assert-NotNull $getNsg.Etag
291-
Assert-AreEqual 2 @($getNsg.SecurityRules).Count
292+
Assert-AreEqual 3 @($getNsg.SecurityRules).Count
292293
Assert-AreEqual 6 @($getNsg.DefaultSecurityRules).Count
293294
Assert-AreEqual "AllowVnetInBound" $getNsg.DefaultSecurityRules[0].Name
294295
Assert-AreEqual "AllowAzureLoadBalancerInBound" $getNsg.DefaultSecurityRules[1].Name
@@ -335,6 +336,23 @@ function Test-NetworkSecurityGroup-MultiValuedRules
335336
Assert-AreEqual "120" $getNsg.SecurityRules[1].Priority
336337
Assert-AreEqual "Inbound" $getNsg.SecurityRules[1].Direction
337338

339+
# verify rule 3
340+
Assert-AreEqual "desciption" $getNsg.SecurityRules[2].Description
341+
Assert-AreEqual "Icmp" $getNsg.SecurityRules[2].Protocol
342+
Assert-AreEqual 2 @($getNsg.SecurityRules[2].SourcePortRange).Count
343+
Assert-AreEqual "50-60" $getNsg.SecurityRules[2].SourcePortRange[0]
344+
Assert-AreEqual "100-110" $getNsg.SecurityRules[2].SourcePortRange[1]
345+
Assert-AreEqual 2 @($getNsg.SecurityRules[2].DestinationPortRange).Count
346+
Assert-AreEqual "120-130" $getNsg.SecurityRules[2].DestinationPortRange[0]
347+
Assert-AreEqual "131-140" $getNsg.SecurityRules[2].DestinationPortRange[1]
348+
Assert-AreEqual 1 @($getNsg.SecurityRules[2].SourceAddressPrefix).Count
349+
Assert-AreEqual "Storage" $getNsg.SecurityRules[2].SourceAddressPrefix[0]
350+
Assert-AreEqual 1 @($getNsg.SecurityRules[2].DestinationAddressPrefix).Count
351+
Assert-AreEqual "Storage" $getNsg.SecurityRules[2].DestinationAddressPrefix[0]
352+
Assert-AreEqual "Allow" $getNsg.SecurityRules[2].Access
353+
Assert-AreEqual "125" $getNsg.SecurityRules[2].Priority
354+
Assert-AreEqual "Inbound" $getNsg.SecurityRules[2].Direction
355+
338356
# list
339357
$list = Get-AzNetworkSecurityGroup -ResourceGroupName $rgname
340358
Assert-AreEqual 1 @($list).Count

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.NetworkSecurityGroupTests/TestNetworkSecurityGroupMultiValuedRules.json

Lines changed: 330 additions & 300 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)