@@ -238,7 +238,6 @@ function Test-AzureFirewallPolicyCRUD {
238238 }
239239}
240240
241-
242241<#
243242. SYNOPSIS
244243Tests AzureFirewallPolicyCRUD with ThreatIntelWhitelist.
@@ -260,7 +259,7 @@ function Test-AzureFirewallPolicyWithThreatIntelWhitelistCRUD {
260259 try {
261260 # Create the resource group
262261 $resourceGroup = New-AzResourceGroup - Name $rgname - Location $location - Tags @ { testtag = " testval" }
263-
262+
264263 $tiWhiteList = New-AzFirewallPolicyThreatIntelWhitelist - IpAddress $threatIntelWhiteListIp1 , $threatIntelWhiteListIp2 - FQDN $threatIntelWhiteListFqdn1
265264
266265 # Create AzureFirewallPolicy (with no rules, ThreatIntel is in Alert mode by default)
@@ -282,12 +281,12 @@ function Test-AzureFirewallPolicyWithThreatIntelWhitelistCRUD {
282281
283282 # # Update ThreatIntel Whitelist
284283 $azureFirewallPolicy.ThreatIntelWhitelist.IpAddresses [0 ] = $threatIntelWhiteListIp3
285-
284+
286285 # Set AzureFirewallPolicy
287286 Set-AzFirewallPolicy - InputObject $azureFirewallPolicy
288287 # Get AzureFirewallPolicy
289288 $getAzureFirewallPolicy = Get-AzFirewallPolicy - Name $azureFirewallPolicyName - ResourceGroupName $rgName
290-
289+
291290 # #verification
292291 Assert-AreEqual $rgName $getAzureFirewallPolicy.ResourceGroupName
293292 Assert-AreEqual $azureFirewallPolicyName $getAzureFirewallPolicy.Name
@@ -318,7 +317,7 @@ function Test-AzureFirewallPolicyWithDNSSettings {
318317 try {
319318 # Create the resource group
320319 $resourceGroup = New-AzResourceGroup - Name $rgname - Location $location - Tags @ { testtag = " testval" }
321-
320+
322321 # Create AzureFirewallPolicy with No DNS Settings
323322 $azureFirewallPolicy = New-AzFirewallPolicy - Name $azureFirewallPolicyName - ResourceGroupName $rgname - Location $location
324323
@@ -330,7 +329,7 @@ function Test-AzureFirewallPolicyWithDNSSettings {
330329 Assert-AreEqual $azureFirewallPolicyName $getAzureFirewallPolicy.Name
331330 Assert-NotNull $getAzureFirewallPolicy.Location
332331 Assert-AreEqual (Normalize- Location $location ) $getAzureFirewallPolicy.Location
333-
332+
334333 # Check DNS Proxy
335334 Assert-Null $getAzureFirewallPolicy.DnsSettings.EnableProxy
336335 Assert-Null $getAzureFirewallPolicy.DnsSettings.Servers
@@ -350,7 +349,7 @@ function Test-AzureFirewallPolicyWithDNSSettings {
350349 Assert-AreEqual $azureFirewallPolicyName $getAzureFirewallPolicy.Name
351350 Assert-NotNull $getAzureFirewallPolicy.Location
352351 Assert-AreEqual (Normalize- Location $location ) $getAzureFirewallPolicy.Location
353-
352+
354353 # Check DNS Proxy
355354 Assert-AreEqual true $getAzureFirewallPolicy.DnsSettings.EnableProxy
356355 Assert-AreEqualArray $dnsServers $getAzureFirewallPolicy.DnsSettings.Servers
@@ -369,7 +368,7 @@ function Test-AzureFirewallPolicyWithDNSSettings {
369368 Assert-AreEqual $azureFirewallPolicyName $getAzureFirewallPolicy.Name
370369 Assert-NotNull $getAzureFirewallPolicy.Location
371370 Assert-AreEqual (Normalize- Location $location ) $getAzureFirewallPolicy.Location
372-
371+
373372 # Check DNS Proxy
374373 Assert-AreEqual true $getAzureFirewallPolicy.DnsSettings.EnableProxy
375374 Assert-AreEqualArray $dnsServers $getAzureFirewallPolicy.DnsSettings.Servers
@@ -403,7 +402,7 @@ function Test-AzureFirewallPolicyWithDNSSettings {
403402
404403<#
405404. SYNOPSIS
406- Tests AzureFirewallPolicyCRUD .
405+ Tests function Test-AzureFirewallPolicyCRUDWithNetworkRuleDestinationFQDNs .
407406#>
408407function Test-AzureFirewallPolicyCRUDWithNetworkRuleDestinationFQDNs {
409408 # Setup
@@ -522,3 +521,242 @@ function Test-AzureFirewallPolicyCRUDWithNetworkRuleDestinationFQDNs {
522521 }
523522}
524523
524+ <#
525+ . SYNOPSIS
526+ Tests AzureFirewallPolicyWithIpGroups.
527+ #>
528+ function Test-AzureFirewallPolicyWithIpGroups {
529+ # Setup
530+ $rgname = Get-ResourceGroupName
531+ $azureFirewallPolicyName = Get-ResourceName
532+ $azureFirewallPolicyAsJobName = Get-ResourceName
533+ $resourceTypeParent = " Microsoft.Network/FirewallPolicies"
534+ $location = " eastus2euap"
535+ $ipGroupLocation = Get-ProviderLocation ResourceManagement " eastus2euap"
536+ $ipGroupName1 = Get-ResourceName
537+ $ipGroupName2 = Get-ResourceName
538+
539+ $ruleGroupName = Get-ResourceName
540+
541+ # AzureFirewallPolicyApplicationRuleCollection
542+ $appRcName = " appRc"
543+ $appRcPriority = 400
544+ $appRcActionType = " Allow"
545+
546+ $pipelineRcPriority = 154
547+
548+ # AzureFirewallPolicyApplicationRule 1
549+ $appRule1Name = " appRule"
550+ $appRule1Desc = " desc1"
551+ $appRule1Fqdn1 = " *google.com"
552+ $appRule1Fqdn2 = " *microsoft.com"
553+ $appRule1Protocol1 = " http:80"
554+ $appRule1Port1 = 80
555+ $appRule1ProtocolType1 = " http"
556+ $appRule1Protocol2 = " https:443"
557+ $appRule1Port2 = 443
558+ $appRule1ProtocolType2 = " https"
559+
560+ # AzureFirewallPolicyApplicationRule 2
561+ $appRule2Name = " appRule2"
562+ $appRule2Fqdn1 = " *bing.com"
563+ $appRule2Protocol1 = " http:8080"
564+ $appRule2Protocol2 = " https:443"
565+ $appRule2Port1 = 8080
566+ $appRule2ProtocolType1 = " http"
567+
568+ # AzureFirewallPolicyNetworkRuleCollection
569+ $networkRcName = " networkRc"
570+ $networkRcPriority = 200
571+ $networkRcActionType = " Deny"
572+
573+ # AzureFirewallPolicyNetworkRule 1
574+ $networkRule1Name = " networkRule"
575+ $networkRule1Desc = " desc1"
576+ $networkRule1Protocol1 = " UDP"
577+ $networkRule1Protocol2 = " TCP"
578+ $networkRule1Protocol3 = " ICMP"
579+ $networkRule1DestinationAddress1 = " 10.10.10.1"
580+ $networkRule1DestinationPort1 = " 90"
581+
582+ # AzureFirewallPolicyNatRuleCollection
583+ $natRcName = " natRc"
584+ $natRcPriority = 100
585+ $natRcActionType = " Dnat"
586+
587+ # AzureFirewallPolicyNatRule 1
588+ $natRule1Name = " natRule"
589+ $natRule1Desc = " desc1"
590+ $natRule1Protocol1 = " UDP"
591+ $natRule1Protocol2 = " TCP"
592+ $natRule1DestinationPort1 = " 90"
593+ $natRule1TranslatedAddress = " 10.1.2.3"
594+ $natRule1TranslatedPort = " 91"
595+
596+ try {
597+ # Create the resource group
598+ $resourceGroup = New-AzResourceGroup - Name $rgname - Location $location - Tags @ { testtag = " testval" }
599+
600+ # Create AzureFirewallPolicy (with no rules, ThreatIntel is in Alert mode by default)
601+ $azureFirewallPolicy = New-AzFirewallPolicy - Name $azureFirewallPolicyName - ResourceGroupName $rgname - Location $location
602+
603+ # Get AzureFirewallPolicy
604+ $getAzureFirewallPolicy = Get-AzFirewallPolicy - Name $azureFirewallPolicyName - ResourceGroupName $rgname
605+
606+ # verification
607+ Assert-AreEqual $rgName $getAzureFirewallPolicy.ResourceGroupName
608+ Assert-AreEqual $azureFirewallPolicyName $getAzureFirewallPolicy.Name
609+ Assert-NotNull $getAzureFirewallPolicy.Location
610+ Assert-AreEqual (Normalize- Location $location ) $getAzureFirewallPolicy.Location
611+ Assert-AreEqual " Alert" $getAzureFirewallPolicy.ThreatIntelMode
612+
613+ # Create IpGroup
614+ $ipGroup1 = New-AzIpGroup - ResourceGroupName $rgname - location $ipgroupLocation - Name $ipGroupName1 - IpAddress 10.0 .0.0 / 24 , 11.9 .0.0 / 24
615+ $returnedIpGroup1 = Get-AzIpGroup - ResourceGroupName $rgname - Name $ipGroupName1
616+ Assert-AreEqual $returnedIpGroup1.ResourceGroupName $ipGroup1.ResourceGroupName
617+ Assert-AreEqual $returnedIpGroup1.Name $ipGroup1.Name
618+
619+ $ipGroup2 = New-AzIpGroup - ResourceGroupName $rgname - location $ipgroupLocation - Name $ipGroupName2 - IpAddress 12.0 .0.0 / 24 , 13.9 .0.0 / 24
620+ $returnedIpGroup2 = Get-AzIpGroup - ResourceGroupName $rgname - Name $ipGroupName2
621+ Assert-AreEqual $returnedIpGroup2.ResourceGroupName $ipGroup2.ResourceGroupName
622+ Assert-AreEqual $returnedIpGroup2.Name $ipGroup2.Name
623+
624+
625+ # Create Application Rules
626+ $appRule = New-AzFirewallPolicyApplicationRule - Name $appRule1Name - Description $appRule1Desc - Protocol $appRule1Protocol1 , $appRule1Protocol2 - TargetFqdn $appRule1Fqdn1 , $appRule1Fqdn2 - SourceIpGroup $ipGroup1.Id
627+ $appRule2 = New-AzFirewallPolicyApplicationRule - Name $appRule2Name - Description $appRule1Desc - Protocol $appRule2Protocol1 , $appRule2Protocol2 - TargetFqdn $appRule2Fqdn1 - SourceIpGroup $ipGroup1.Id , $ipGroup2.Id
628+
629+ # Create Network Rule
630+ $networkRule = New-AzFirewallPolicyNetworkRule - Name $networkRule1Name - Description $networkRule1Desc - Protocol $networkRule1Protocol1 , $networkRule1Protocol2 - SourceIpGroup $ipGroup1.Id - DestinationIpGroup $ipGroup2.Id - DestinationPort $networkRule1DestinationPort1
631+
632+
633+ # Create Filter Rule with 2 application rules
634+ $appRc = New-AzFirewallPolicyFilterRuleCollection - Name $appRcName - Priority $appRcPriority - Rule $appRule , $appRule2 - ActionType $appRcActionType
635+
636+ # Create a second Filter Rule Collection with 1 network rule
637+ $appRc2 = New-AzFirewallPolicyFilterRuleCollection - Name $networkRcName - Priority $networkRcPriority - Rule $networkRule - ActionType $networkRcActionType
638+
639+
640+ # Create NAT rule
641+ $natRule = New-AzFirewallPolicyNatRule - Name $natRule1Name - Description $natRule1Desc - Protocol $natRule1Protocol1 , $natRule1Protocol2 - SourceIpGroup $ipGroup1.Id , $ipGroup2.Id - DestinationAddress $networkRule1DestinationAddress1 - DestinationPort $natRule1DestinationPort1 - TranslatedAddress $natRule1TranslatedAddress - TranslatedPort $natRule1TranslatedPort
642+
643+ # Create a NAT Rule Collection
644+ $natRc = New-AzFirewallPolicyNatRuleCollection - Name $natRcName - ActionType $natRcActionType - Priority $natRcPriority - Rule $natRule
645+
646+ New-AzFirewallPolicyRuleCollectionGroup - Name $ruleGroupName - Priority 100 - RuleCollection $appRc , $appRc2 , $natRc - FirewallPolicyObject $azureFirewallPolicy
647+
648+
649+ # # Update ThreatIntel mode
650+ $azureFirewallPolicy.ThreatIntelMode = " Deny"
651+ # Set AzureFirewallPolicy
652+ Set-AzFirewallPolicy - InputObject $azureFirewallPolicy
653+ # Get AzureFirewallPolicy
654+ $getAzureFirewallPolicy = Get-AzFirewallPolicy - Name $azureFirewallPolicyName - ResourceGroupName $rgName
655+
656+ # verification
657+ Assert-AreEqual $rgName $getAzureFirewallPolicy.ResourceGroupName
658+ Assert-AreEqual $azureFirewallPolicyName $getAzureFirewallPolicy.Name
659+ Assert-NotNull $getAzureFirewallPolicy.Location
660+ Assert-AreEqual $location $getAzureFirewallPolicy.Location
661+ Assert-AreEqual " Deny" $getAzureFirewallPolicy.ThreatIntelMode
662+
663+ # Check rule groups count
664+ Assert-AreEqual 1 @ ($getAzureFirewallPolicy.RuleCollectionGroups ).Count
665+
666+ $getRg = Get-AzFirewallPolicyRuleCollectionGroup - Name $ruleGroupName - AzureFirewallPolicy $getAzureFirewallPolicy
667+
668+ Assert-AreEqual 3 @ ($getRg.properties.ruleCollection ).Count
669+
670+ $filterRuleCollection1 = $getRg.Properties.GetRuleCollectionByName ($appRcName )
671+ $filterRuleCollection2 = $getRg.Properties.GetRuleCollectionByName ($networkRcName )
672+ $natRuleCollection = $getRg.Properties.GetRuleCollectionByName ($natRcName )
673+
674+ # Verify Filter Rule Collection1
675+ Assert-AreEqual $appRcName $filterRuleCollection1.Name
676+ Assert-AreEqual $appRcPriority $filterRuleCollection1.Priority
677+ Assert-AreEqual $appRcActionType $filterRuleCollection1.Action.Type
678+ Assert-AreEqual 2 $filterRuleCollection1.Rules.Count
679+
680+ $appRule = $filterRuleCollection1.GetRuleByName ($appRule1Name )
681+ # Verify application rule 1
682+ Assert-AreEqual $appRule1Name $appRule.Name
683+
684+ Assert-AreEqual 1 $appRule.SourceIpGroups.Count
685+
686+ Assert-AreEqual 2 $appRule.Protocols.Count
687+ Assert-AreEqual $appRule1ProtocolType1 $appRule.Protocols [0 ].ProtocolType
688+ Assert-AreEqual $appRule1ProtocolType2 $appRule.Protocols [1 ].ProtocolType
689+ Assert-AreEqual $appRule1Port1 $appRule.Protocols [0 ].Port
690+ Assert-AreEqual $appRule1Port2 $appRule.Protocols [1 ].Port
691+
692+ Assert-AreEqual 2 $appRule.TargetFqdns.Count
693+ Assert-AreEqual $appRule1Fqdn1 $appRule.TargetFqdns [0 ]
694+ Assert-AreEqual $appRule1Fqdn2 $appRule.TargetFqdns [1 ]
695+
696+ # Verify application rule 2
697+ $appRule2 = $filterRuleCollection1.GetRuleByName ($appRule2Name )
698+ Assert-AreEqual $appRule2Name $appRule2.Name
699+
700+ Assert-AreEqual 2 $appRule2.SourceIpGroups.Count
701+
702+ Assert-AreEqual 2 $appRule.TargetFqdns.Count
703+ Assert-AreEqual $appRule1Fqdn1 $appRule.TargetFqdns [0 ]
704+ Assert-AreEqual $appRule1Fqdn2 $appRule.TargetFqdns [1 ]
705+
706+ # Verify Filter Rule Collection2
707+ Assert-AreEqual $networkRcName $filterRuleCollection2.Name
708+ Assert-AreEqual $networkRcPriority $filterRuleCollection2.Priority
709+ Assert-AreEqual $networkRcActionType $filterRuleCollection2.Action.Type
710+ Assert-AreEqual 1 $filterRuleCollection2.Rules.Count
711+
712+ $networkRule = $filterRuleCollection2.GetRuleByName ($networkRule1Name )
713+ # Verify Network rule
714+ Assert-AreEqual $networkRule1Name $networkRule.Name
715+
716+ Assert-AreEqual 1 $networkRule.SourceIpGroups.Count
717+ Assert-AreEqual 1 $networkRule.DestinationIpGroups.Count
718+
719+ Assert-AreEqual 2 $networkRule.Protocols.Count
720+ Assert-AreEqual $networkRule1Protocol1 $networkRule.Protocols [0 ]
721+ Assert-AreEqual $networkRule1Protocol2 $networkRule.Protocols [1 ]
722+
723+ Assert-AreEqual 1 $networkRule.DestinationPorts.Count
724+ Assert-AreEqual $networkRule1DestinationPort1 $networkRule.DestinationPorts [0 ]
725+
726+ # Verify NAT rule collection and NAT rule
727+ $natRule = $natRuleCollection.GetRuleByName ($natRule1Name )
728+
729+ Assert-AreEqual $natRcName $natRuleCollection.Name
730+ Assert-AreEqual $natRcPriority $natRuleCollection.Priority
731+
732+ Assert-AreEqual $natRule1Name $natRule.Name
733+
734+ Assert-AreEqual 2 $natRule.SourceIpGroups.Count
735+
736+ Assert-AreEqual 1 $natRule.DestinationAddresses.Count
737+
738+ Assert-AreEqual 2 $natRule.Protocols.Count
739+ Assert-AreEqual $natRule1Protocol1 $natRule.Protocols [0 ]
740+ Assert-AreEqual $natRule1Protocol2 $natRule.Protocols [1 ]
741+
742+ Assert-AreEqual 1 $natRule.DestinationPorts.Count
743+ Assert-AreEqual $natRule1DestinationPort1 $natRule.DestinationPorts [0 ]
744+
745+ Assert-AreEqual $natRule1TranslatedAddress $natRule.TranslatedAddress
746+ Assert-AreEqual $natRule1TranslatedPort $natRule.TranslatedPort
747+
748+
749+ $testPipelineRg = Get-AzFirewallPolicyRuleCollectionGroup - Name $ruleGroupName - AzureFirewallPolicyName $getAzureFirewallPolicy.Name - ResourceGroupName $rgname
750+ $testPipelineRg | Set-AzFirewallPolicyRuleCollectionGroup - Priority $pipelineRcPriority
751+ $testPipelineRg = Get-AzFirewallPolicyRuleCollectionGroup - Name $ruleGroupName - AzureFirewallPolicyName $getAzureFirewallPolicy.Name - ResourceGroupName $rgname
752+ Assert-AreEqual $pipelineRcPriority $testPipelineRg.properties.Priority
753+
754+ $azureFirewallPolicyAsJob = New-AzFirewallPolicy - Name $azureFirewallPolicyAsJobName - ResourceGroupName $rgname - Location $location - AsJob
755+ $result = $azureFirewallPolicyAsJob | Wait-Job
756+ Assert-AreEqual " Completed" $result.State
757+ }
758+ finally {
759+ # Cleanup
760+ Clean - ResourceGroup $rgname
761+ }
762+ }
0 commit comments