Skip to content

Commit

Permalink
Refactor policy test to exclude certain policies and parameters (#1734)
Browse files Browse the repository at this point in the history
Co-authored-by: Jack Tracey <[email protected]>
  • Loading branch information
Springstone and jtracey93 authored Aug 27, 2024
1 parent 9443a67 commit 2390ed7
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions .github/actions-pester/Test-ModifiedPolicies.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,26 @@ Describe 'UnitTest-ModifiedPolicies' {
$ModifiedAddedFiles | ForEach-Object {
$PolicyJson = Get-Content -Path $_ -Raw | ConvertFrom-Json
$PolicyFile = Split-Path $_ -Leaf
$PolicyParameters = $PolicyJson.properties.parameters
if ($PolicyParameters | Get-Member -MemberType NoteProperty)
$PolicyMetadataName = $PolicyJson.name
$ExcludePolicy = @("Deploy-Private-DNS-Zones","Deploy-Vm-autoShutdown","Deploy-Custom-Route-Table","Deploy-DDoSProtection","Deploy-Default-Udr")
$ExcludeParams = @("allowedVnets","userAssignedIdentityName","identityResourceGroup","resourceName","logAnalytics","ddosPlanResourceId","modifyUdrNextHopIpAddress","emailSecurityContact","contactEmails","contactGroups","contactRoles","privateDnsZoneId","resourceType","groupId","azureAcrPrivateDnsZoneId","userWorkspaceResourceId","workspaceRegion","dcrName","dcrResourceGroup","dcrId","keyVaultNonIntegratedCaValue","excludedSubnets","excludedDestinations","allowedBypassOptions","ports","denyMgmtFromInternetPorts","allowedVmSizes","allowedKinds","predefinedPolicyName","privateLinkDnsZones","locations","tagValues","ascExportResourceGroupLocation","ascExportResourceGroupName","vulnerabilityAssessmentsEmail","vulnerabilityAssessmentsStorageID","listOfResourceTypesAllowed","listOfResourceTypesNotAllowed","synapseAllowedTenantIds","storageAllowedNetworkAclsBypass","keyVaultIntegratedCaValue","keyVaultHmsCurveNamesValue")
if ($PolicyMetadataName -notin $ExcludePolicy)
{
$Parameters = $PolicyParameters | Get-Member -MemberType NoteProperty | Select-Object -Expand Name
Write-Warning "$($PolicyFile) - These are the params: $($Parameters)"
$Parameters = $PolicyParameters | Get-Member -MemberType NoteProperty
$Parameters | ForEach-Object {
$key = $_.name
$defaultValue = $PolicyParameters.$key | Get-Member -MemberType NoteProperty | Where-Object Name -EQ "defaultValue"
Write-Warning "$($PolicyFile) - Parameter: $($key) - Default Value: $($defaultValue)"
$PolicyParameters.$key.defaultValue | Should -Not -BeNullOrEmpty
$PolicyParameters = $PolicyJson.properties.parameters
if ($PolicyParameters | Get-Member -MemberType NoteProperty)
{
$Parameters = $PolicyParameters | Get-Member -MemberType NoteProperty | Select-Object -Expand Name
Write-Warning "$($PolicyFile) - These are the params: $($Parameters)"
$Parameters = $PolicyParameters | Get-Member -MemberType NoteProperty
$Parameters | ForEach-Object {
$key = $_.name
if ($key -notin $ExcludeParams)
{
$defaultValue = $PolicyParameters.$key | Get-Member -MemberType NoteProperty | Where-Object Name -EQ "defaultValue"
Write-Warning "$($PolicyFile) - Parameter: $($key) - Default Value: $($defaultValue)"
$PolicyParameters.$key.defaultValue | Should -Not -BeNullOrEmpty
}
}
}
}
}
Expand Down

0 comments on commit 2390ed7

Please sign in to comment.