From 2390ed737017598660ab560931907a4917b8294c Mon Sep 17 00:00:00 2001 From: Sacha Narinx Date: Tue, 27 Aug 2024 12:45:28 +0400 Subject: [PATCH] Refactor policy test to exclude certain policies and parameters (#1734) Co-authored-by: Jack Tracey <41163455+jtracey93@users.noreply.github.com> --- .../Test-ModifiedPolicies.Tests.ps1 | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/actions-pester/Test-ModifiedPolicies.Tests.ps1 b/.github/actions-pester/Test-ModifiedPolicies.Tests.ps1 index 6b49cb1531..b30e85f504 100644 --- a/.github/actions-pester/Test-ModifiedPolicies.Tests.ps1 +++ b/.github/actions-pester/Test-ModifiedPolicies.Tests.ps1 @@ -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 + } + } } } }