Skip to content

Commit

Permalink
PS changes for Uppercase Transform (#19546)
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulbissa2727 authored Sep 22, 2022
1 parent 4ffd95b commit b62ec36
Show file tree
Hide file tree
Showing 6 changed files with 1,406 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,14 @@ public void TestApplicationGatewayFirewallPolicyWithCustomRules()
{
TestRunner.RunTestScript("Test-ApplicationGatewayFirewallPolicyWithCustomRules");
}


[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.nvadev_subset1)]
public void TestApplicationGatewayFirewallPolicyWithUppercaseTransform()
{
TestRunner.RunTestScript("Test-ApplicationGatewayFirewallPolicyWithUppercaseTransform");
}
}
}
51 changes: 51 additions & 0 deletions src/Network/Network.Test/ScenarioTests/ApplicationGatewayTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4208,3 +4208,54 @@ function Test-ApplicationGatewayFirewallPolicyWithCustomRules
Clean-ResourceGroup $rgname
}
}

function Test-ApplicationGatewayFirewallPolicyWithUppercaseTransform
{
# Setup
$location = Get-ProviderLocation "Microsoft.Network/applicationGateways" "West US 2"

$rgname = Get-ResourceGroupName
$wafPolicy = Get-ResourceName

try
{
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $location -Tags @{ testtag = "APPGw tag"}

# WAF Policy and Custom Rule
$variable = New-AzApplicationGatewayFirewallMatchVariable -VariableName RequestHeaders -Selector Content-Length
$condition = New-AzApplicationGatewayFirewallCondition -MatchVariable $variable -Operator GreaterThan -MatchValue 1000 -Transform Uppercase -NegationCondition $False
$rule = New-AzApplicationGatewayFirewallCustomRule -Name example -Priority 2 -RuleType MatchRule -MatchCondition $condition -Action Block
$policySettings = New-AzApplicationGatewayFirewallPolicySetting -Mode Prevention -State Enabled -MaxFileUploadInMb 70 -MaxRequestBodySizeInKb 70
$managedRuleSet = New-AzApplicationGatewayFirewallPolicyManagedRuleSet -RuleSetType "OWASP" -RuleSetVersion "3.2"
$managedRule = New-AzApplicationGatewayFirewallPolicyManagedRule -ManagedRuleSet $managedRuleSet
New-AzApplicationGatewayFirewallPolicy -Name $wafPolicy -ResourceGroupName $rgname -Location $location -ManagedRule $managedRule -PolicySetting $policySettings

$policy = Get-AzApplicationGatewayFirewallPolicy -Name $wafPolicy -ResourceGroupName $rgname
$policy.CustomRules = $rule
Set-AzApplicationGatewayFirewallPolicy -InputObject $policy

$policy = Get-AzApplicationGatewayFirewallPolicy -Name $wafPolicy -ResourceGroupName $rgname

# Second check firewll policy
Assert-AreEqual $policy.CustomRules[0].Name $rule.Name
Assert-AreEqual $policy.CustomRules[0].RuleType $rule.RuleType
Assert-AreEqual $policy.CustomRules[0].Action $rule.Action
Assert-AreEqual $policy.CustomRules[0].Priority $rule.Priority
Assert-AreEqual $policy.CustomRules[0].MatchConditions[0].OperatorProperty $rule.MatchConditions[0].OperatorProperty
Assert-AreEqual $policy.CustomRules[0].MatchConditions[0].Transforms[0] $rule.MatchConditions[0].Transforms[0]
Assert-AreEqual $policy.CustomRules[0].MatchConditions[0].NegationConditon $rule.MatchConditions[0].NegationConditon
Assert-AreEqual $policy.CustomRules[0].MatchConditions[0].MatchValues[0] $rule.MatchConditions[0].MatchValues[0]
Assert-AreEqual $policy.CustomRules[0].MatchConditions[0].MatchVariables[0].VariableName $rule.MatchConditions[0].MatchVariables[0].VariableName
Assert-AreEqual $policy.CustomRules[0].MatchConditions[0].MatchVariables[0].Selector $rule.MatchConditions[0].MatchVariables[0].Selector
Assert-AreEqual $policy.PolicySettings.FileUploadLimitInMb $policySettings.FileUploadLimitInMb
Assert-AreEqual $policy.PolicySettings.MaxRequestBodySizeInKb $policySettings.MaxRequestBodySizeInKb
Assert-AreEqual $policy.PolicySettings.RequestBodyCheck $policySettings.RequestBodyCheck
Assert-AreEqual $policy.PolicySettings.Mode $policySettings.Mode
Assert-AreEqual $policy.PolicySettings.State $policySettings.State
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Network/Network/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* Updated commandlets to support specifying an ASN on VPN Gateway
- `NewAzureRmVpnGatewayCommand.cs`
- `UpdateAzureRmVpnGatewayCommand.cs`
* Added Uppercase Transform in New-AzApplicationGatewayFirewallCondition

## Version 4.20.1
* Added breaking change notification for `Get-AzFirewall`, `New-AzFirewall`, `Set-AzFirewall` and `New-AzFirewallHubIpAddress`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class AzureApplicationGatewayFirewallConditionBase : NetworkBaseCmdlet
[Parameter(
Mandatory = false,
HelpMessage = "List of transforms.")]
[ValidateSet("Lowercase", "Trim", "UrlDecode", "UrlEncode", "RemoveNulls", "HtmlEntityDecode", IgnoreCase = true)]
[ValidateSet("Uppercase","Lowercase", "Trim", "UrlDecode", "UrlEncode", "RemoveNulls", "HtmlEntityDecode", IgnoreCase = true)]
[ValidateNotNullOrEmpty]
public string[] Transform { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Creates a match condition for custom rule

```
New-AzApplicationGatewayFirewallCondition -MatchVariable <PSApplicationGatewayFirewallMatchVariable[]>
-Operator <String> [-NegationCondition <Boolean>] -MatchValue <String[]> [-Transform <String[]>]
-Operator <String> [-NegationCondition <Boolean>] [-MatchValue <String[]>] [-Transform <String[]>]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

Expand Down Expand Up @@ -55,7 +55,7 @@ Type: System.String[]
Parameter Sets: (All)
Aliases:

Required: True
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Expand Down Expand Up @@ -115,7 +115,7 @@ List of transforms.
Type: System.String[]
Parameter Sets: (All)
Aliases:
Accepted values: Lowercase, Trim, UrlDecode, UrlEncode, RemoveNulls, HtmlEntityDecode
Accepted values: Uppercase, Lowercase, Trim, UrlDecode, UrlEncode, RemoveNulls, HtmlEntityDecode

Required: False
Position: Named
Expand Down

0 comments on commit b62ec36

Please sign in to comment.