Skip to content

Commit

Permalink
Snat cmdlet fwp (#20854)
Browse files Browse the repository at this point in the history
* Added Snat parameter to firewall policy cmdlets

* Generated help for new cmdlet and updated for the existing ones

* fixed pipeline analyze issue

* Removed SupportsShouldProcess

* suppressed static analyzer

* Updated help per PR review comments

---------

Co-authored-by: Gizachew Eshetie <[email protected]>
  • Loading branch information
Gizachew-Eshetie and Gizachew Eshetie authored Feb 14, 2023
1 parent 4d1b136 commit 80470b8
Show file tree
Hide file tree
Showing 13 changed files with 1,575 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,13 @@ public void TestAzureFirewallPolicyRuleDescription()
{
TestRunner.RunTestScript("Test-AzureFirewallPolicyRuleDescription");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.azurefirewall)]
public void TestAzureFirewallSnat()
{
TestRunner.RunTestScript("Test-AzureFirewallSnat");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1764,4 +1764,57 @@ function Test-AzureFirewallPolicyRuleDescription {
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Tests AzureFirewall SNAT
#>
function Test-AzureFirewallSnat {
$rgname = Get-ResourceGroupName
$azureFirewallPolicyName = Get-ResourceName
$resourceTypeParent = "Microsoft.Network/FirewallPolicies"
$location = "westus2"
$vnetName = Get-ResourceName
$privateRange = @("3.3.0.0/24", "98.0.0.0/8","10.227.16.0/20")
$privateRange2 = @("0.0.0.0/0", "66.92.0.0/16")

try {

# Create the resource group
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $location -Tags @{ testtag = "testval" }

$snat = New-AzFirewallPolicySnat -PrivateRange $privateRange -AutoLearnPrivateRange

# Create AzureFirewallPolicy (with SNAT)
$azureFirewallPolicy = New-AzFirewallPolicy -Name $azureFirewallPolicyName -ResourceGroupName $rgname -Location $location -Snat $snat

# Get AzureFirewallPolicy
$getAzureFirewallPolicy = Get-AzFirewallPolicy -Name $azureFirewallPolicyName -ResourceGroupName $rgname


#verification
Assert-AreEqual $rgName $getAzureFirewallPolicy.ResourceGroupName
Assert-AreEqual $azureFirewallPolicyName $getAzureFirewallPolicy.Name
Assert-NotNull $getAzureFirewallPolicy.Location
Assert-AreEqual (Normalize-Location $location) $getAzureFirewallPolicy.Location
Assert-NotNull $getAzureFirewallPolicy.Snat
Assert-AreEqualArray $privateRange $getAzureFirewallPolicy.Snat.PrivateRanges
Assert-AreEqual "Enabled" $getAzureFirewallPolicy.Snat.AutoLearnPrivateRanges

# Modify
$snat = New-AzFirewallPolicySnat -PrivateRange $privateRange2
# Set AzureFirewallPolicy
$azureFirewallPolicy.Snat = $snat
Set-AzFirewallPolicy -InputObject $azureFirewallPolicy
$policy = Get-AzFirewallPolicy -Name $azureFirewallPolicyName -ResourceGroupName $rgname

Assert-NotNull $policy.Snat
Assert-AreEqualArray $privateRange2 $policy.Snat.PrivateRanges
Assert-AreEqual "Disabled" $policy.Snat.AutoLearnPrivateRanges
}
finally {
# Cleanup
Clean-ResourceGroup $rgname
}
}
Loading

0 comments on commit 80470b8

Please sign in to comment.