16
16
. SYNOPSIS
17
17
Tests AzureFirewallCRUD.
18
18
#>
19
- function Test-AzureFirewallCRUD
20
- {
19
+ function Test-AzureFirewallCRUD {
21
20
# Setup
22
21
$rgname = Get-ResourceGroupName
23
22
$azureFirewallName = Get-ResourceName
@@ -97,8 +96,7 @@ function Test-AzureFirewallCRUD
97
96
$natRule1TranslatedAddress = " 10.1.2.3"
98
97
$natRule1TranslatedPort = " 91"
99
98
100
- try
101
- {
99
+ try {
102
100
# Create the resource group
103
101
$resourceGroup = New-AzResourceGroup - Name $rgname - Location $location - Tags @ { testtag = " testval" }
104
102
@@ -201,7 +199,7 @@ function Test-AzureFirewallCRUD
201
199
Assert-ThrowsContains { $natRule.AddProtocol (" ABCD" ) } " Invalid protocol"
202
200
# Test handling of ICMP protocol
203
201
Assert-ThrowsContains {
204
- New-AzFirewallNatRule - Name $natRule1Name - Protocol $natRule1Protocol1 , " ICMP" - SourceAddress $natRule1SourceAddress1 - DestinationAddress $natRule1DestinationAddress1 - DestinationPort $natRule1DestinationPort1 - TranslatedAddress $natRule1TranslatedAddress - TranslatedPort $natRule1TranslatedPort
202
+ New-AzFirewallNatRule - Name $natRule1Name - Protocol $natRule1Protocol1 , " ICMP" - SourceAddress $natRule1SourceAddress1 - DestinationAddress $natRule1DestinationAddress1 - DestinationPort $natRule1DestinationPort1 - TranslatedAddress $natRule1TranslatedAddress - TranslatedPort $natRule1TranslatedPort
205
203
} " The argument `" ICMP`" does not belong to the set"
206
204
Assert-ThrowsContains { $natRule.AddProtocol (" ICMP" ) } " Invalid protocol"
207
205
@@ -395,8 +393,7 @@ function Test-AzureFirewallCRUD
395
393
$list = Get-AzFirewall - ResourceGroupName $rgname
396
394
Assert-AreEqual 0 @ ($list ).Count
397
395
}
398
- finally
399
- {
396
+ finally {
400
397
# Cleanup
401
398
Clean - ResourceGroup $rgname
402
399
}
@@ -406,8 +403,7 @@ function Test-AzureFirewallCRUD
406
403
. SYNOPSIS
407
404
Tests AzureFirewallCRUD With Availability Zones.
408
405
#>
409
- function Test-AzureFirewallCRUDWithZones
410
- {
406
+ function Test-AzureFirewallCRUDWithZones {
411
407
# Setup
412
408
$rgname = Get-ResourceGroupName
413
409
$azureFirewallName = Get-ResourceName
@@ -480,8 +476,7 @@ function Test-AzureFirewallCRUDWithZones
480
476
$natRule1TranslatedAddress = " 10.1.2.3"
481
477
$natRule1TranslatedPort = " 91"
482
478
483
- try
484
- {
479
+ try {
485
480
# Create the resource group
486
481
$resourceGroup = New-AzResourceGroup - Name $rgname - Location $location - Tags @ { testtag = " testval" }
487
482
@@ -493,7 +488,7 @@ function Test-AzureFirewallCRUDWithZones
493
488
$publicip = New-AzPublicIpAddress - ResourceGroupName $rgname - name $publicIpName - location $location - AllocationMethod Static - Sku Standard
494
489
495
490
# Create AzureFirewall (with no rules, ThreatIntel is in Alert mode by default)
496
- $azureFirewall = New-AzFirewall –Name $azureFirewallName - ResourceGroupName $rgname - Location $location - VirtualNetworkName $vnetName - PublicIpName $publicIpName - Zone 1 , 2 , 3
491
+ $azureFirewall = New-AzFirewall –Name $azureFirewallName - ResourceGroupName $rgname - Location $location - VirtualNetworkName $vnetName - PublicIpName $publicIpName - Zone 1 , 2 , 3
497
492
498
493
# Get AzureFirewall
499
494
$getAzureFirewall = Get-AzFirewall - name $azureFirewallName - ResourceGroupName $rgname
@@ -577,7 +572,7 @@ function Test-AzureFirewallCRUDWithZones
577
572
Assert-ThrowsContains { $natRule.AddProtocol (" ABCD" ) } " Invalid protocol"
578
573
# Test handling of ICMP protocol
579
574
Assert-ThrowsContains {
580
- New-AzFirewallNatRule - Name $natRule1Name - Protocol $natRule1Protocol1 , " ICMP" - SourceAddress $natRule1SourceAddress1 - DestinationAddress $natRule1DestinationAddress1 - DestinationPort $natRule1DestinationPort1 - TranslatedAddress $natRule1TranslatedAddress - TranslatedPort $natRule1TranslatedPort
575
+ New-AzFirewallNatRule - Name $natRule1Name - Protocol $natRule1Protocol1 , " ICMP" - SourceAddress $natRule1SourceAddress1 - DestinationAddress $natRule1DestinationAddress1 - DestinationPort $natRule1DestinationPort1 - TranslatedAddress $natRule1TranslatedAddress - TranslatedPort $natRule1TranslatedPort
581
576
} " The argument `" ICMP`" does not belong to the set"
582
577
Assert-ThrowsContains { $natRule.AddProtocol (" ICMP" ) } " Invalid protocol"
583
578
@@ -594,8 +589,8 @@ function Test-AzureFirewallCRUDWithZones
594
589
# Add NetworkRuleCollections to the Firewall using method AddNetworkRuleCollection
595
590
$azureFirewall.AddNetworkRuleCollection ($netRc )
596
591
597
- # Update ThreatIntel mode
598
- $azureFirewall.ThreatIntelMode = " Deny"
592
+ # Update ThreatIntel mode
593
+ $azureFirewall.ThreatIntelMode = " Deny"
599
594
600
595
# Set AzureFirewall
601
596
Set-AzFirewall - AzureFirewall $azureFirewall
@@ -610,7 +605,7 @@ function Test-AzureFirewallCRUDWithZones
610
605
Assert-NotNull $getAzureFirewall.Location
611
606
Assert-AreEqual $location $getAzureFirewall.Location
612
607
Assert-NotNull $getAzureFirewall.Etag
613
- Assert-AreEqual " Deny" $getAzureFirewall.ThreatIntelMode
608
+ Assert-AreEqual " Deny" $getAzureFirewall.ThreatIntelMode
614
609
615
610
Assert-AreEqual 1 @ ($getAzureFirewall.IpConfigurations ).Count
616
611
Assert-NotNull $azureFirewallIpConfiguration [0 ].Subnet.Id
@@ -760,8 +755,7 @@ function Test-AzureFirewallCRUDWithZones
760
755
$list = Get-AzFirewall - ResourceGroupName $rgname
761
756
Assert-AreEqual 0 @ ($list ).Count
762
757
}
763
- finally
764
- {
758
+ finally {
765
759
# Cleanup
766
760
Clean - ResourceGroup $rgname
767
761
}
@@ -771,8 +765,7 @@ function Test-AzureFirewallCRUDWithZones
771
765
. SYNOPSIS
772
766
Tests AzureFirewall with new style params for VNET and Public IPs - objects instead of strings
773
767
#>
774
- function Test-AzureFirewallPIPAndVNETObjectTypeParams
775
- {
768
+ function Test-AzureFirewallPIPAndVNETObjectTypeParams {
776
769
# Setup
777
770
$rgname = Get-ResourceGroupName
778
771
$azureFirewallName = Get-ResourceName
@@ -784,8 +777,7 @@ function Test-AzureFirewallPIPAndVNETObjectTypeParams
784
777
$publicIp1Name = Get-ResourceName
785
778
$publicIp2Name = Get-ResourceName
786
779
787
- try
788
- {
780
+ try {
789
781
# Create the resource group
790
782
$resourceGroup = New-AzResourceGroup - Name $rgname - Location $location - Tags @ { testtag = " testval" }
791
783
@@ -917,8 +909,7 @@ function Test-AzureFirewallPIPAndVNETObjectTypeParams
917
909
$list = Get-AzFirewall - ResourceGroupName $rgname
918
910
Assert-AreEqual 0 @ ($list ).Count
919
911
}
920
- finally
921
- {
912
+ finally {
922
913
# Cleanup
923
914
Clean - ResourceGroup $rgname
924
915
}
@@ -928,8 +919,7 @@ function Test-AzureFirewallPIPAndVNETObjectTypeParams
928
919
. SYNOPSIS
929
920
Tests AzureFirewall Set and Remove IpConfiguration
930
921
#>
931
- function Test-AzureFirewallAllocateAndDeallocate
932
- {
922
+ function Test-AzureFirewallAllocateAndDeallocate {
933
923
# Setup
934
924
$rgname = Get-ResourceGroupName
935
925
$azureFirewallName = Get-ResourceName
@@ -940,8 +930,7 @@ function Test-AzureFirewallAllocateAndDeallocate
940
930
$subnetName = " AzureFirewallSubnet"
941
931
$publicIpName = Get-ResourceName
942
932
943
- try
944
- {
933
+ try {
945
934
# Create the resource group
946
935
$resourceGroup = New-AzResourceGroup - Name $rgname - Location $location - Tags @ { testtag = " testval" }
947
936
@@ -1031,8 +1020,60 @@ function Test-AzureFirewallAllocateAndDeallocate
1031
1020
$list = Get-AzFirewall - ResourceGroupName $rgname
1032
1021
Assert-AreEqual 0 @ ($list ).Count
1033
1022
}
1034
- finally
1035
- {
1023
+ finally {
1024
+ # Cleanup
1025
+ Clean - ResourceGroup $rgname
1026
+ }
1027
+ }
1028
+
1029
+ <#
1030
+ . SYNOPSIS
1031
+ Tests AzureFirewall Set and Remove IpConfiguration
1032
+ #>
1033
+ function Test-AzureFirewallVirtualHubCRUD {
1034
+ # Setup
1035
+ $rgname = Get-ResourceGroupName
1036
+ $azureFirewallName = Get-ResourceName
1037
+ $resourceTypeParent = " Microsoft.Network/AzureFirewalls"
1038
+ $policyLocation = " westcentralus"
1039
+ $location = Get-ProviderLocation $resourceTypeParent
1040
+ $azureFirewallPolicyName = Get-ResourceName
1041
+ $sku = " AZFW_Hub"
1042
+ $tier = " Standard"
1043
+
1044
+ try {
1045
+ # Create the resource group
1046
+ $resourceGroup = New-AzResourceGroup - Name $rgname - Location $location - Tags @ { testtag = " testval" }
1047
+
1048
+ # Create AzureFirewallPolicy (with no rules, ThreatIntel is in Alert mode by default)
1049
+ $azureFirewallPolicy = New-AzFirewallPolicy - Name $azureFirewallPolicyName - ResourceGroupName $rgname - Location $policyLocation
1050
+
1051
+ # Get the AzureFirewallPolicy
1052
+ $getazureFirewallPolicy = Get-AzFirewallPolicy - Name $azureFirewallPolicyName - ResourceGroupName $rgname
1053
+
1054
+
1055
+ Assert-NotNull $azureFirewallPolicy
1056
+ Assert-NotNull $getazureFirewallPolicy.Id
1057
+
1058
+ $azureFirewallPolicyId = $getazureFirewallPolicy.Id
1059
+
1060
+ New-AzFirewall –Name $azureFirewallName - ResourceGroupName $rgname - Location $location - Sku $sku - FirewallPolicyId $azureFirewallPolicyId
1061
+
1062
+ # Get AzureFirewall
1063
+ $getAzureFirewall = Get-AzFirewall - name $azureFirewallName - ResourceGroupName $rgname
1064
+
1065
+ # verification
1066
+ Assert-AreEqual $rgName $getAzureFirewall.ResourceGroupName
1067
+ Assert-AreEqual $azureFirewallName $getAzureFirewall.Name
1068
+ Assert-NotNull $getAzureFirewall.Location
1069
+ Assert-AreEqual (Normalize- Location $location ) $getAzureFirewall.Location
1070
+ Assert-NotNull $sku $getAzureFirewall.Sku
1071
+ Assert-AreEqual $sku $getAzureFirewall.Sku.Name
1072
+ Assert-AreEqual $tier $getAzureFirewall.Sku.Tier
1073
+ Assert-NotNull $getAzureFirewall.FirewallPolicy
1074
+ Assert-AreEqual $azureFirewallPolicyId $getAzureFirewall.FirewallPolicy.Id
1075
+ }
1076
+ finally {
1036
1077
# Cleanup
1037
1078
Clean - ResourceGroup $rgname
1038
1079
}
0 commit comments