diff --git a/build/golden/Export-MtGoldenFixture.ps1 b/build/golden/Export-MtGoldenFixture.ps1 index 05ef163c63..c0d6045e5e 100644 --- a/build/golden/Export-MtGoldenFixture.ps1 +++ b/build/golden/Export-MtGoldenFixture.ps1 @@ -482,7 +482,7 @@ function Get-InvokeMaesterSelection { # Reason codes of tests that selection leaves out. OptInServiceNotConnected stands for 2.x adding AD to # Filter.ExcludeTag when Active Directory is not connected. -$NotSelectedReasons = @('NotSelected', 'NotListed', 'Preview', 'LongRunning', 'ExcludedByTag', 'ExcludedById', 'DisabledByConfig', 'OptInServiceNotConnected') +$NotSelectedReasons = @('NotSelected', 'NotListed', 'Preview', 'LongRunning', 'ExcludedByTag', 'ExcludedById', 'ExcludedByProduct', 'DisabledByConfig', 'OptInServiceNotConnected') # An empty user folder: every built-in test is native and runs from the module. $workDir = Join-Path ([System.IO.Path]::GetTempPath()) "maester-golden-$([guid]::NewGuid().ToString('N'))" @@ -567,7 +567,7 @@ $selectionDocument = [ordered]@{ _meta = [ordered]@{ Description = 'Maester 2.x golden: Pester filter built by Invoke-Maester and the IDs it selects. Regenerate with build/golden/Export-MtGoldenFixture.ps1; never hand-edit.' FilterSource = 'The include and exclude tags of the real Invoke-Maester run context, run with -DryRun -SkipGraphConnect in an empty folder.' - SelectionSource = 'The rows of that dry run that selection did not leave out (any reason other than NotSelected, NotListed, Preview, LongRunning, ExcludedByTag, ExcludedById, DisabledByConfig or OptInServiceNotConnected). Families are listed by their 2.x prefix.' + SelectionSource = 'The rows of that dry run that selection did not leave out (any reason other than NotSelected, NotListed, Preview, LongRunning, ExcludedByTag, ExcludedById, ExcludedByProduct, DisabledByConfig or OptInServiceNotConnected). Families are listed by their 2.x prefix.' Assumptions = @( 'Not connected to Active Directory, so Invoke-Maester appends AD to Filter.ExcludeTag.', 'Run.Path "." is the installed tests folder (repo tests/ without Custom); "./tests/" maps to repo tests/.', diff --git a/build/parity/parity-allowlist.psd1 b/build/parity/parity-allowlist.psd1 index 363919b22d..2fc0d4382a 100644 --- a/build/parity/parity-allowlist.psd1 +++ b/build/parity/parity-allowlist.psd1 @@ -97,7 +97,7 @@ Field = 'Presence' Id = '^(MT\.1024|MT\.1033|MT\.1034|MT\.1059|MT1060)$' Old = '^$' - NewRow = @{ ReasonCode = '^(NoInstances|InstanceSourceFailed|InvalidInstanceId|NotSelected|ExcludedByTag|ExcludedById|DisabledByConfig|ServiceNotConnected|ServiceNotRegistered|LicenseNotFound|TenantTypeMismatch|CloudMismatch|PlatformMismatch)$' } + NewRow = @{ ReasonCode = '^(NoInstances|InstanceSourceFailed|InvalidInstanceId|NotSelected|ExcludedByTag|ExcludedById|ExcludedByProduct|DisabledByConfig|ServiceNotConnected|ServiceNotRegistered|LicenseNotFound|TenantTypeMismatch|CloudMismatch|PlatformMismatch)$' } } # 5.3 item 4: MT.1022 and MT.1023 gain the Describe tags that 2.x drops inside a Context. diff --git a/powershell/internal/engine/Resolve-MtNativePlan.ps1 b/powershell/internal/engine/Resolve-MtNativePlan.ps1 index 4307b83af3..47b0347339 100644 --- a/powershell/internal/engine/Resolve-MtNativePlan.ps1 +++ b/powershell/internal/engine/Resolve-MtNativePlan.ps1 @@ -5,8 +5,8 @@ function Resolve-MtNativePlan { .DESCRIPTION Gates apply in this order, and the first failing gate gives the reason (design section 6): - invalid metadata; disabled by config; selection (IDs, typed selectors, tags, opt-in service, Preview, - long-running); platform; tenant type; cloud; service; licence; parameter binding. + invalid metadata; disabled by config; selection (IDs, excluded products, typed selectors, tags, opt-in + service, Preview, long-running); platform; tenant type; cloud; service; licence; parameter binding. The default exclusions are decided by attribute, not by tag (test attribute design, section 4): a test with Lifecycle = 'Preview' or LongRunning is left out when the run excludes them by default @@ -112,6 +112,12 @@ function Resolve-MtNativePlan { & $set 'NotRun' 'ExcludedById' "Excluded by ID ($($excludedBy -join ', '))." [pscustomobject]$row; continue } + # -ExcludeProduct matches Product or RelatedProduct, and wins over -TestId and -Product. + $excludedBy = @(Test-MtProductExcluded -Selection $Selection -Product (@($t.Product) + @($t.RelatedProduct))) + if ($excludedBy) { + & $set 'NotRun' 'ExcludedByProduct' "Excluded by product ($($excludedBy -join ', '))." + [pscustomobject]$row; continue + } if ($Selection.TestId.Count -gt 0) { $includedBy = @(Test-MtIdMatch -Id $t.Id -Pattern $Selection.TestId) if (-not $includedBy -and $isFamily) { @@ -152,7 +158,7 @@ function Resolve-MtNativePlan { foreach ($pattern in $IncludeTag) { $via = & $matchTag $tags $pattern if (-not $via) { continue } - if ($via -eq 'Legacy') { $legacyTagUsed[$pattern] = $true } + if ($via -eq 'Legacy') { $legacyTagUsed[$pattern] = 'Include' } $included = $true break } @@ -186,7 +192,7 @@ function Resolve-MtNativePlan { $hits = @(foreach ($pattern in $userExcludeTag) { $via = & $matchTag $tags $pattern if (-not $via) { continue } - if ($via -eq 'Legacy') { $legacyTagUsed[$pattern] = $true } + if ($via -eq 'Legacy' -and -not $legacyTagUsed.Contains($pattern)) { $legacyTagUsed[$pattern] = 'Exclude' } $pattern }) if ($hits) { @@ -225,7 +231,7 @@ function Resolve-MtNativePlan { } # One warning per run when a tag of Maester 2.x did the selecting, with the typed selector that replaces it. - if ($legacyTagUsed.Count -gt 0) { Write-Warning (Get-MtLegacyTagWarning -Tag @($legacyTagUsed.Keys)) } + if ($legacyTagUsed.Count -gt 0) { Write-Warning (Get-MtLegacyTagWarning -Tag @($legacyTagUsed.Keys) -ExcludeTag @($legacyTagUsed.Keys | Where-Object { $legacyTagUsed[$_] -eq 'Exclude' })) } } function Get-MtLegacyTagWarning { @@ -235,19 +241,25 @@ function Get-MtLegacyTagWarning { .DESCRIPTION Names each tag and, where assets/Maester.LegacyTags.json gives one, the typed selector that replaces - it, for example -Tag CA and -Feature conditional-access (test attribute design, section 5.1). + it, for example -Tag CA and -Feature conditional-access (test attribute design, section 5.1). A product + tag used in -ExcludeTag names -ExcludeProduct: -ExcludeTag EXO is now -ExcludeProduct exchange. #> [CmdletBinding()] [OutputType([string])] param( # The -Tag and -ExcludeTag values that matched a test only through a 2.x tag. - [Parameter(Mandatory)] [string[]] $Tag + [Parameter(Mandatory)] [string[]] $Tag, + # Those of the tags that matched a test only through -ExcludeTag. + [Parameter()] [AllowEmptyCollection()] [string[]] $ExcludeTag = @() ) $table = Get-MtLegacyTagTable $named = foreach ($t in $Tag) { $replacement = $null - if ($table.Replacement.TryGetValue($t, [ref] $replacement)) { "'$t' (now $replacement)" } else { "'$t'" } + if ($table.Replacement.TryGetValue($t, [ref] $replacement)) { + if ($t -in $ExcludeTag -and $replacement -like '-Product *') { $replacement = $replacement -replace '^-Product ', '-ExcludeProduct ' } + "'$t' (now $replacement)" + } else { "'$t'" } } if (@($named).Count -eq 1) { "The tag $named is a Maester 2.x tag. It still selects the same built-in tests, but tests added after Maester 3.0 do not carry it." diff --git a/powershell/internal/engine/Resolve-MtRunConfig.ps1 b/powershell/internal/engine/Resolve-MtRunConfig.ps1 index 60282405c5..1b2957bcc6 100644 --- a/powershell/internal/engine/Resolve-MtRunConfig.ps1 +++ b/powershell/internal/engine/Resolve-MtRunConfig.ps1 @@ -248,6 +248,7 @@ function Complete-MtRunConfig { TestId = @() ExcludeTestId = @() Product = @() + ExcludeProduct = @() Feature = @() Area = @() Severity = @() @@ -262,7 +263,7 @@ function Complete-MtRunConfig { $Config.Selection | Add-Member -MemberType NoteProperty -Name $key -Value $selectionDefaults[$key] -Force } } - foreach ($key in 'Tag', 'ExcludeTag', 'TestId', 'ExcludeTestId', 'Product', 'Feature', 'Area', 'Severity', 'Suite', 'Pack') { + foreach ($key in 'Tag', 'ExcludeTag', 'TestId', 'ExcludeTestId', 'Product', 'ExcludeProduct', 'Feature', 'Area', 'Severity', 'Suite', 'Pack') { $Config.Selection.$key = @($Config.Selection.$key | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }) } if ($Config.Selection.DefaultAction -notin 'Run', 'Skip') { diff --git a/powershell/internal/engine/Resolve-MtSelection.ps1 b/powershell/internal/engine/Resolve-MtSelection.ps1 index 4336cef4f5..a5d74e5b56 100644 --- a/powershell/internal/engine/Resolve-MtSelection.ps1 +++ b/powershell/internal/engine/Resolve-MtSelection.ps1 @@ -5,8 +5,9 @@ function Resolve-MtSelection { .DESCRIPTION -Tag, -TestId and the typed selectors (-Product, -Feature, -Area, -Severity, -Suite) replace the config - lists, and so does -Pack; -ExcludeTag and -ExcludeTestId add to them; the include switches are true when either source - sets them. A product named by an alias, such as Entra ID, becomes its key. + lists, and so does -Pack; -ExcludeTag, -ExcludeTestId and -ExcludeProduct add to them; the include switches are true + when either source sets them. A product named by an alias, such as Entra ID, becomes its key, in -Product and + -ExcludeProduct alike. .EXAMPLE Resolve-MtSelection -RunConfig $config -BoundParameters $PSBoundParameters @@ -22,6 +23,7 @@ function Resolve-MtSelection { [Parameter()] [string[]] $TestId, [Parameter()] [string[]] $ExcludeTestId, [Parameter()] [string[]] $Product, + [Parameter()] [string[]] $ExcludeProduct, [Parameter()] [string[]] $Feature, [Parameter()] [string[]] $Area, [Parameter()] [string[]] $Severity, @@ -38,16 +40,24 @@ function Resolve-MtSelection { $list = if ($value) { $value } elseif ($s.PSObject.Properties[$name]) { $s.$name } else { @() } foreach ($item in @($list)) { if (-not [string]::IsNullOrWhiteSpace($item)) { [string]$item } } } - $products = foreach ($item in @(& $selector $Product 'Product')) { + # A product name becomes its key; a wildcard pattern stays as it is. + $productKey = { + param($item) $key = if ($item.Contains('*')) { $null } else { Resolve-MtProductKey -Name $item } if ($key) { $key } else { $item } } + $products = foreach ($item in @(& $selector $Product 'Product')) { & $productKey $item } + $configExcludeProduct = if ($s.PSObject.Properties['ExcludeProduct']) { @($s.ExcludeProduct) } else { @() } + $excludeProducts = foreach ($item in @($configExcludeProduct) + @($ExcludeProduct)) { + if (-not [string]::IsNullOrWhiteSpace($item)) { & $productKey ([string]$item) } + } [pscustomobject]@{ Tag = @(if ($Tag) { $Tag } else { $s.Tag }) ExcludeTag = @(@($s.ExcludeTag) + @($ExcludeTag) | Where-Object { $_ } | Select-Object -Unique) TestId = @(if ($TestId) { $TestId } else { $s.TestId }) ExcludeTestId = @(@($s.ExcludeTestId) + @($ExcludeTestId) | Where-Object { $_ } | Select-Object -Unique) Product = [string[]]@($products) + ExcludeProduct = [string[]]@($excludeProducts | Select-Object -Unique) Feature = [string[]]@(& $selector $Feature 'Feature') Area = [string[]]@(& $selector $Area 'Area') Severity = [string[]]@(& $selector $Severity 'Severity') @@ -118,6 +128,31 @@ function Test-MtSelectorInUse { $false } +function Test-MtProductExcluded { + <# + .SYNOPSIS + Returns the -ExcludeProduct patterns that match a test's Product or RelatedProduct values. + + .DESCRIPTION + The patterns are product keys or '*' wildcards, as for -Product. A test that has no product, such as a + Pester-format test, matches none: -ExcludeProduct never leaves it out, unlike -Product. + #> + [CmdletBinding()] + [OutputType([string])] + param( + # Output of Resolve-MtSelection. + [Parameter(Mandatory)] [pscustomobject] $Selection, + # The test's Product and RelatedProduct values. + [Parameter()] [AllowNull()] [AllowEmptyCollection()] [string[]] $Product + ) + + if (-not $Selection.PSObject.Properties['ExcludeProduct']) { return } + $values = @($Product | Where-Object { $_ }) + foreach ($pattern in @($Selection.ExcludeProduct | Where-Object { $_ })) { + if ($values | Where-Object { $_ -like $pattern }) { $pattern } + } +} + function Test-MtIdMatch { <# .SYNOPSIS @@ -152,8 +187,8 @@ function Get-MtPesterSelectionPlan { family through its literal ID prefix. A Pester-format test has no Product, Feature or Area, so a run that selects by one of them leaves it - out. Its Suite is that of its file (-FileOrigin), and its severity is known before the run only from a - TestSettings row. + out, and -ExcludeProduct never excludes it. Its Suite is that of its file (-FileOrigin), and its severity + is known before the run only from a TestSettings row. Returns: ExcludeLines (file:line strings), Reasons (file:line -> reason object), LiftPreview and LiftLongRunning (an exact -TestId names a Preview or long-running test, so the default tag diff --git a/powershell/public/run/Invoke-Maester.ps1 b/powershell/public/run/Invoke-Maester.ps1 index 999caa788e..6fe6e0be97 100644 --- a/powershell/public/run/Invoke-Maester.ps1 +++ b/powershell/public/run/Invoke-Maester.ps1 @@ -10,7 +10,10 @@ By default, Invoke-Maester runs the tests that ship with Maester and the custom tests in the Custom folder of the current directory, except Active Directory tests, preview tests and long-running tests. With -Path, native custom tests (Test.*.ps1) are found anywhere under the path and Pester-format custom tests (*.Tests.ps1) only in a Custom folder. Folders are searched up to three levels deep. Active Directory tests run only after an explicit Connect-Maester -Service ActiveDirectory call succeeds. - -Product, -Feature, -Area, -Severity and -Suite select tests by their typed attributes. Each takes a list: the values of one selector are alternatives, and different selectors must all match. They combine the same way with -Tag and -TestId. The tags of Maester 2.x, such as CA or CIS, still select the same built-in tests. + -Product, -Feature, -Area, -Severity and -Suite select tests by their typed attributes. Each takes a list: the values of one selector are alternatives, and different selectors must all match. They combine the same way with -Tag and -TestId. -ExcludeProduct leaves out the tests of a product and wins over every selector. The tags of Maester 2.x, such as CA or CIS, still select the same built-in tests. + + .PARAMETER ExcludeProduct + Do not run the tests of these products: keys such as entra or exchange, or an alias such as 'exo' or 'Entra ID'. Matches a test's Product or any of its RelatedProduct values, and '*' wildcards are allowed, as for -Product. Adds to Selection.ExcludeProduct in the run configuration and wins over -Product, -TestId and the other selectors. Excluded tests are reported as NotRun with the reason code ExcludedByProduct. A test without a product, such as a Pester-format custom test, is never excluded. .PARAMETER IncludeLongRunning Include tests that can take a long time to run in tenants with a large number of objects. @@ -52,6 +55,11 @@ Runs the Entra ID tests whose severity is Critical or High. Values of one selector are alternatives; different selectors must all match. + .EXAMPLE + Invoke-Maester -ExcludeProduct exchange + + Runs the tests that ship with Maester and the custom tests, except the tests about Exchange Online (a test whose Product or RelatedProduct is exchange). Pester-format custom tests have no product and still run. + .EXAMPLE Invoke-Maester -Suite cisa -Area authentication @@ -174,6 +182,10 @@ # Matches a test's Product or any of its RelatedProduct values. '*' wildcards are allowed. [string[]] $Product, + # Do not run the tests of these products, matched like -Product. Wins over every selector. + # A test without a product, such as a Pester-format custom test, is never excluded. + [string[]] $ExcludeProduct, + # Only run the tests about these features of a product, for example conditional-access. '*' wildcards are allowed. [string[]] $Feature, @@ -514,12 +526,12 @@ } $selection = Resolve-MtSelection -RunConfig $runConfig -Tag $Tag -ExcludeTag $ExcludeTag -TestId $TestId -ExcludeTestId $ExcludeTestId ` - -Product $Product -Feature $Feature -Area $Area -Severity $Severity -Suite $Suite -Pack $Pack ` + -Product $Product -ExcludeProduct $ExcludeProduct -Feature $Feature -Area $Area -Severity $Severity -Suite $Suite -Pack $Pack ` -IncludePreview:$IncludePreview -IncludeLongRunning:$IncludeLongRunning if ($SkipBuiltIn) { $selection.BuiltIn = 'None' } # The selectors live in $selection from here on. A test runs in a child scope of this function, so a # test that reads a $Severity or $Product it never set would otherwise see the value of the parameter. - $Product = $Feature = $Area = $Severity = $Suite = $Pack = $null + $Product = $ExcludeProduct = $Feature = $Area = $Severity = $Suite = $Pack = $null $Tag = $selection.Tag $ExcludeTag = $selection.ExcludeTag $IncludePreview = [switch]$selection.IncludePreview @@ -839,7 +851,9 @@ # Stages 2, 5 and 6 for native tests: the tenant context, then selection and applicability. $nativeTests = @($nativeBuiltIn) + @($nativeCustom) + @($nativePack) - $neededServices = @($nativeTests | ForEach-Object { $_.Service } | Where-Object { $_ } | Select-Object -Unique) + # A service that only the tests of excluded products need is not read or connected. + $neededServices = @($nativeTests | Where-Object { -not (Test-MtProductExcluded -Selection $selection -Product (@($_.Product) + @($_.RelatedProduct))) } | + ForEach-Object { $_.Service } | Where-Object { $_ } | Select-Object -Unique) Write-MtProgress -Activity 'Starting Maester' -Status 'Reading the tenant context...' -Force # The dashboard shows the tenant and the services while they are read, and fills in each answer as it comes. $tenantStep = if ($console.Mode -eq 'Interactive') { Start-MtDashboardTenant -Renderer $renderer -Console $console -Service $(if ($neededServices) { $neededServices } else { @('Graph') }) } diff --git a/powershell/tests/fixtures/golden/selection.json b/powershell/tests/fixtures/golden/selection.json index 62134eff2d..c738b62de3 100644 --- a/powershell/tests/fixtures/golden/selection.json +++ b/powershell/tests/fixtures/golden/selection.json @@ -2,7 +2,7 @@ "_meta": { "Description": "Maester 2.x golden: Pester filter built by Invoke-Maester and the IDs it selects. Regenerate with build/golden/Export-MtGoldenFixture.ps1; never hand-edit.", "FilterSource": "The include and exclude tags of the real Invoke-Maester run context, run with -DryRun -SkipGraphConnect in an empty folder.", - "SelectionSource": "The rows of that dry run that selection did not leave out (any reason other than NotSelected, NotListed, Preview, LongRunning, ExcludedByTag, ExcludedById, DisabledByConfig or OptInServiceNotConnected). Families are listed by their 2.x prefix.", + "SelectionSource": "The rows of that dry run that selection did not leave out (any reason other than NotSelected, NotListed, Preview, LongRunning, ExcludedByTag, ExcludedById, ExcludedByProduct, DisabledByConfig or OptInServiceNotConnected). Families are listed by their 2.x prefix.", "Assumptions": [ "Not connected to Active Directory, so Invoke-Maester appends AD to Filter.ExcludeTag.", "Run.Path \".\" is the installed tests folder (repo tests/ without Custom); \"./tests/\" maps to repo tests/.", diff --git a/powershell/tests/functions/engine/Get-MtPesterSelectionPlan.Tests.ps1 b/powershell/tests/functions/engine/Get-MtPesterSelectionPlan.Tests.ps1 index d0ed60d1e7..740cb6c502 100644 --- a/powershell/tests/functions/engine/Get-MtPesterSelectionPlan.Tests.ps1 +++ b/powershell/tests/functions/engine/Get-MtPesterSelectionPlan.Tests.ps1 @@ -100,6 +100,10 @@ Describe 'Get-MtPesterSelectionPlan' { Get-Reason $plan 'S.1004' | Should -Be 'ExcludedById' } + It 'Excludes no Pester-format test with ExcludeProduct, because none has a product' { + (Get-Plan -Selection @{ ExcludeProduct = @('*') }).ExcludeLines.Count | Should -Be 0 + } + It 'Lifts the Preview exclusion for an exact ID but not for a wildcard' { $exact = Get-Plan -Selection @{ TestId = @('S.1002') } $exact.LiftPreview | Should -BeTrue diff --git a/powershell/tests/functions/engine/TestAttributes.Tests.ps1 b/powershell/tests/functions/engine/TestAttributes.Tests.ps1 index df24c5668a..523da88084 100644 --- a/powershell/tests/functions/engine/TestAttributes.Tests.ps1 +++ b/powershell/tests/functions/engine/TestAttributes.Tests.ps1 @@ -566,6 +566,52 @@ Describe 'Typed selectors and default exclusions' { (Get-Plan @{ Product = 'teams' } | Where-Object { $_.Test.Id -eq 'SEL.1' }).ReasonDetail | Should -Be 'Not selected by -Product (teams).' } + It '-ExcludeProduct runs ' -ForEach @( + @{ Value = 'exchange'; Expected = 'SEL.1,SEL.3,SEL.4,SEL.5,SEL.6' } + @{ Value = 'EXO'; Expected = 'SEL.1,SEL.3,SEL.4,SEL.5,SEL.6' } + @{ Value = 'contoso*'; Expected = 'SEL.1,SEL.2,SEL.4,SEL.5,SEL.6' } + # SEL.2 is about exchange with entra as its RelatedProduct. SEL.4 and SEL.6 have no product and stay. + @{ Value = 'Entra ID'; Expected = 'SEL.3,SEL.4,SEL.6' } + @{ Value = @('entra', 'Contoso CRM'); Expected = 'SEL.4,SEL.6' } + @{ Value = '*'; Expected = 'SEL.4,SEL.6' } + ) { + (Get-Selected @{ ExcludeProduct = $Value }) -join ',' | Should -Be $Expected + } + + It 'Reports a test left out by -ExcludeProduct as ExcludedByProduct' { + $row = Get-Plan @{ ExcludeProduct = 'exo' } | Where-Object { $_.Test.Id -eq 'SEL.2' } + $row.Disposition | Should -Be 'NotRun' + $row.ReasonCode | Should -Be 'ExcludedByProduct' + $row.ReasonDetail | Should -Be 'Excluded by product (exchange).' + } + + It 'Lets -ExcludeProduct win over -Product and -TestId' { + (Get-Selected @{ Product = 'entra'; ExcludeProduct = 'exchange' }) -join ',' | Should -Be 'SEL.1,SEL.5' + (Get-Selected @{ Product = 'entra'; ExcludeProduct = 'entra' }) | Should -BeNullOrEmpty + (Get-Selected @{ TestId = 'SEL.2', 'SEL.3'; ExcludeProduct = 'exchange' }) -join ',' | Should -Be 'SEL.3' + (Get-Plan @{ TestId = 'SEL.2'; ExcludeProduct = 'exchange' } | Where-Object { $_.Test.Id -eq 'SEL.2' }).ReasonCode | Should -Be 'ExcludedByProduct' + } + + It 'Adds -ExcludeProduct to Selection.ExcludeProduct of the run configuration' { + $config = @{ Selection = @{ ExcludeProduct = @('Entra ID') } } + (Get-Selected -Config $config) -join ',' | Should -Be 'SEL.3,SEL.4,SEL.6' + (Get-Selected @{ ExcludeProduct = 'contoso*' } -Config $config) -join ',' | Should -Be 'SEL.4,SEL.6' + $selection = InModuleScope Maester -Parameters @{ C = $config } { Resolve-MtSelection -RunConfig (Resolve-MtRunConfig -Config $C) -ExcludeProduct 'exo', 'entra' } + $selection.ExcludeProduct | Should -Be @('entra', 'exchange') + $resolved = InModuleScope Maester { (Resolve-MtRunConfig -Config @{}).Selection } + , $resolved.ExcludeProduct | Should -BeOfType [array] + @($resolved.ExcludeProduct).Count | Should -Be 0 + } + + It 'Does not count -ExcludeProduct as selecting by attribute' { + InModuleScope Maester { + $selection = Resolve-MtSelection -RunConfig (Resolve-MtRunConfig -Config @{}) -ExcludeProduct 'entra' + Test-MtSelectorInUse -Selection $selection | Should -BeFalse + @(Test-MtProductExcluded -Selection $selection -Product @()) | Should -HaveCount 0 + @(Test-MtProductExcluded -Selection $selection -Product 'exchange', 'entra') | Should -Be @('entra') + } + } + It 'Matches -Severity against the severity the run configuration sets for a test' { $config = @{ TestSettings = @(@{ Id = 'SEL.2'; Severity = 'High' }, @{ Id = 'SEL.1'; Severity = 'Low' }) } (Get-Selected @{ Severity = 'High' } -Config $config) -join ',' | Should -Be 'SEL.2,SEL.4' @@ -644,6 +690,7 @@ Describe 'Typed selectors and default exclusions' { @(Get-MtTest -Suite cisa).Count | Should -BeGreaterThan 50 @(Get-MtTest -Product ad | Where-Object { $_.Product -ne 'ad' -and $_.RelatedProduct -notcontains 'ad' }) | Should -HaveCount 0 (Get-Command Invoke-Maester).Parameters.Keys | Should -Contain 'Product' + (Get-Command Invoke-Maester).Parameters['ExcludeProduct'].ParameterType | Should -Be ([string[]]) foreach ($name in 'Product', 'Feature', 'Area', 'Severity', 'Suite') { (Get-Command Invoke-Maester).Parameters[$name].ParameterType | Should -Be ([string[]]) -Because $name (Get-Command Get-MtTest).Parameters[$name].ParameterType | Should -Be ([string[]]) -Because $name @@ -685,6 +732,12 @@ Describe 'Selecting with Maester 2.x tags' { @($r.Plan | Where-Object ReasonCode -EQ 'ExcludedByTag').Count | Should -Be 2 } + It 'Names -ExcludeProduct for a 2.x product tag used to exclude' { + $r = Get-TagPlan -ExcludeTag 'EXO' + $r.Warnings[0] | Should -BeLike "*'EXO' (now -ExcludeProduct exchange)*" + (Get-TagPlan -Tag 'EXO').Warnings[0] | Should -BeLike "*'EXO' (now -Product exchange)*" + } + It 'Excludes with a 2.x tag' { $r = Get-TagPlan -ExcludeTag 'EIDSCA' @($r.Plan | Where-Object ReasonCode -EQ 'ExcludedByTag').Count | Should -Be 44 @@ -735,6 +788,7 @@ Describe 'Rows, Taxonomy and warnings of a run' { IncludePreview = '-SkipBuiltIn -IncludePreview' AnyTag = '-SkipBuiltIn -Tag contoso-suite' Product = '-SkipBuiltIn -Product entra -DryRun' + ExcludeProduct = '-SkipBuiltIn -ExcludeProduct exo -DryRun' SuiteSelector = '-SkipBuiltIn -Suite contoso -DryRun' ConfigSelector = "-SkipBuiltIn -DryRun -Config @{ Selection = @{ Feature = @('Billing') } }" LegacyTag = '-Tag CA, EXO -ExcludeTag MS.EXO -DryRun' @@ -851,6 +905,14 @@ Describe 'Rows, Taxonomy and warnings of a run' { ((Get-Run 'AnyTag').Tests | Where-Object Id -EQ 'ROW.3').Result | Should -Be 'Passed' } + It 'Keeps a Pester-format test in a dry run that excludes a product' { + $r = Get-Run 'ExcludeProduct' + # ROW.1 is about entra with exchange as its RelatedProduct; the Pester-format test has no product and stays. + ($r.Tests | Where-Object Id -EQ 'ROW.1').ReasonCode | Should -Be 'ExcludedByProduct' + ($r.Tests | Where-Object Id -EQ 'ROW.2').ReasonCode | Should -Be 'DryRun' + ($r.Tests | Where-Object Id -EQ 'PES.1').ReasonCode | Should -Be 'DryRun' + } + It 'Leaves a Pester-format test out of a run that selects by product, and keeps it in a run that selects by its suite' { $r = Get-Run 'Product' $pester = $r.Tests | Where-Object Id -EQ 'PES.1' diff --git a/website/docs/configuration/applicability.md b/website/docs/configuration/applicability.md index fbee36b533..8760bed6b5 100644 --- a/website/docs/configuration/applicability.md +++ b/website/docs/configuration/applicability.md @@ -29,7 +29,7 @@ row has exactly one reason. | 1 | The test file is valid, loads, has a unique ID and does not need a newer Maester | `Error` | | 2 | The test is not disabled in `TestSettings` | `NotRun` | | 3 | `Selection.DefaultAction = Skip` and no `TestSettings` row enables it | `NotRun` | -| 4 | Selection by ID: `-ExcludeTestId`, then `-TestId` | `NotRun` | +| 4 | Selection by ID and excluded product: `-ExcludeTestId`, then `-ExcludeProduct`, then `-TestId` | `NotRun` | | 5 | Selection by attribute and tag: `-Product`, `-Feature`, `-Area`, `-Severity` and `-Suite`, then `-Tag`, then the Active Directory opt-in, preview and long-running tests, then `-ExcludeTag` | `NotRun` | | 6 | Platform: the operating system Maester runs on | `Skipped` | | 7 | Tenant type (only when enforced) | `Skipped` | @@ -93,6 +93,7 @@ The test was not run because of what you asked for. | `DisabledByConfig` | A `TestSettings` row sets `"Enabled": false`. `ReasonDetail` is the row's `Reason`, if any. | Remove the row or set `Enabled` to `true`. | | `NotListed` | `Selection.DefaultAction` is `Skip` and no `TestSettings` row sets `"Enabled": true` for this test (or, for a family, for its parent or any instance). | Add `{ "Id": "", "Enabled": true }`, or use `DefaultAction: Run`. | | `ExcludedById` | The ID matches `-ExcludeTestId` or `Selection.ExcludeTestId`. | Remove the pattern. | +| `ExcludedByProduct` | The test's `Product` or one of its `RelatedProduct` values matches `-ExcludeProduct` or `Selection.ExcludeProduct`. A test with no product, such as a Pester-format test, is never excluded this way. | Remove the product from the exclusions. | | `NotSelected` | `-TestId` (or `Selection.TestId`) was given and does not match this test, or `-Tag` was given and none of the tags selects the test, or the test does not match one of `-Product`, `-Feature`, `-Area`, `-Severity` and `-Suite`; `ReasonDetail` names that selector. For a family, an instance that a `-TestId` naming other instances did not cover. A Pester-format test is `NotSelected` whenever the run selects by product, feature or area, because it has none. | Add the ID, value or tag, or drop the filter. | | `ExcludedByTag` | A tag in `-ExcludeTag`, `Selection.ExcludeTag` or `PesterConfiguration.Filter.ExcludeTag` selects the test. | Remove the tag from the exclusions. | | `Preview` | A test with `Lifecycle = 'Preview'` (in a Pester-format test, the `Preview` tag), excluded by default. | `-IncludePreview`, any `-Tag`, `Selection.IncludePreview`, or name its exact ID in `-TestId`. | diff --git a/website/docs/configuration/run-configuration.md b/website/docs/configuration/run-configuration.md index 8042a7c046..ca7d51889f 100644 --- a/website/docs/configuration/run-configuration.md +++ b/website/docs/configuration/run-configuration.md @@ -64,8 +64,8 @@ the config with `-Config` if that is what you want. `-Verbose` logs the full pat - Every other object merges per key, recursively. - Arrays and plain values replace. An empty array in a higher layer clears the lower one. - On the command line, `-Tag` and `-TestId` replace the config's `Selection.Tag` and `Selection.TestId`; - `-ExcludeTag` and `-ExcludeTestId` add to the config's lists; `-IncludePreview` and `-IncludeLongRunning` turn - the setting on when either source does. + `-ExcludeTag`, `-ExcludeTestId` and `-ExcludeProduct` add to the config's lists; `-IncludePreview` and + `-IncludeLongRunning` turn the setting on when either source does. Keys Maester does not know are kept and passed through, so they do no harm. The 2.x keys `ModuleVersion` and `ConfigVersion` are ignored. @@ -85,6 +85,7 @@ Keys Maester does not know are kept and passed through, so they do no harm. The "BuiltIn": "All", "DefaultAction": "Run", "Product": [], + "ExcludeProduct": [], "Feature": [], "Area": [], "Severity": [], @@ -150,6 +151,7 @@ Which tests run. Every key has a command-line equivalent. | `BuiltIn` | `All`, `None` | `All` | `None` runs only your custom tests, like `-SkipBuiltIn`. | | `DefaultAction` | `Run`, `Skip` | `Run` | `Skip` is allow-list mode: a test runs only if a `TestSettings` row for its ID sets `"Enabled": true`. Others are `NotRun` with reason `NotListed`. | | `Product` | array | `[]` | Run only tests of these products (like `-Product`): keys such as `entra` or `exchange`, or an alias such as `Entra ID`. Matches a test's `Product` or any of its `RelatedProduct` values. | +| `ExcludeProduct` | array | `[]` | Do not run tests of these products (like `-ExcludeProduct`), matched like `Product`. Wins over `Product`, `TestId` and the other selectors. A test with no product is never excluded. | | `Feature` | array | `[]` | Run only tests about these features (like `-Feature`), for example `conditional-access`. | | `Area` | array | `[]` | Run only tests of these security areas (like `-Area`), for example `authentication`. | | `Severity` | array | `[]` | Run only tests with these severities (like `-Severity`). The severity a `TestSettings` row sets is the one that counts. | @@ -173,7 +175,12 @@ Rules: and each result names the ones it uses under `Taxonomy`. - A Pester-format test has no product, feature or area, so a run that selects by one of them leaves it out. Its suite is that of its folder, and its severity counts only when a `TestSettings` row sets it. -- A command-line value replaces the list of the same name in the config. +- `ExcludeProduct` leaves out the tests whose `Product` or `RelatedProduct` matches, with the reason + `ExcludedByProduct`: `-ExcludeProduct exchange` runs everything except the Exchange Online tests, and + `-Product entra -ExcludeProduct entra` runs nothing. Unlike `Product`, it never leaves out a Pester-format + test, which has no product. Services that only the excluded tests need are not read or connected. +- A command-line value replaces the list of the same name in the config, except `-ExcludeTag`, + `-ExcludeTestId` and `-ExcludeProduct`, which add to it. - Tags and IDs are compared case-insensitively. Tag lists match any tag; `*` wildcards are allowed. - Test IDs are exact or use `*` wildcards (`CISA.MS.AAD.3.*`). An ID named exactly runs even if the test is preview or long-running; a wildcard match does not lift those exclusions. @@ -206,7 +213,7 @@ to the selectors when you can: | 2.x tag | Example | Now | | --- | --- | --- | | Suite | `CISA`, `Maester` | `-Suite cisa` | -| Product or service | `EXO`, `Entra` | `-Product exchange` | +| Product or service | `EXO`, `Entra` | `-Product exchange`; `-ExcludeTag EXO` is `-ExcludeProduct exchange` | | Topic | `CA`, `Privileged` | `-Feature conditional-access`, `-Area privileged-access` | | Benchmark control ID | `MS.AAD.3.5` | `-TestId CISA.MS.AAD.3.5` | | Severity | `Severity:High` | `-Severity High` | diff --git a/website/docs/upgrading-from-2x.md b/website/docs/upgrading-from-2x.md index 2b4b501bea..7270930992 100644 --- a/website/docs/upgrading-from-2x.md +++ b/website/docs/upgrading-from-2x.md @@ -120,6 +120,7 @@ New `Invoke-Maester` parameters: | Parameter | Effect | | --- | --- | | `-Product` | Run only the tests of these products: keys such as `entra` or `exchange`, or an alias such as `Entra ID`. | +| `-ExcludeProduct` | Do not run the tests of these products, matched like `-Product`. Wins over the other selectors. Pester-format tests, which have no product, still run. | | `-Feature` | Run only the tests about these features of a product, for example `conditional-access`. | | `-Area` | Run only the tests of these security areas, for example `authentication` or `privileged-access`. | | `-Severity` | Run only the tests with these severities. | @@ -150,8 +151,8 @@ Every existing parameter stays. Changed behaviour: exact ID is in `-TestId`. - **Active Directory tests are chosen by their service.** A test that needs Active Directory runs only after `Connect-Maester -Service ActiveDirectory`. The `AD` tag no longer decides this. -- **Deselected tests carry a reason.** `NotRun` rows say why: not selected, excluded by tag or ID, disabled, - preview, long-running, Active Directory not connected. See +- **Deselected tests carry a reason.** `NotRun` rows say why: not selected, excluded by tag, ID or product, + disabled, preview, long-running, Active Directory not connected. See [Applicability and reason codes](./configuration/applicability.md). - **`-Verbosity Normal`** prints one line per finished test, and `Detailed` also a line when each test starts. @@ -169,6 +170,7 @@ carry 2.x tags, so a tag no longer grows with the product; a selector does. | --- | --- | | `-Tag CISA`, `-Tag Maester` | `-Suite cisa`, `-Suite maester` | | `-Tag EXO`, `-Tag Entra` | `-Product exchange`, `-Product entra` | +| `-ExcludeTag EXO`, `-ExcludeTag Entra` | `-ExcludeProduct exchange`, `-ExcludeProduct entra` | | `-Tag CA`, `-Tag Privileged` | `-Feature conditional-access`, `-Area privileged-access` | | `-Tag MS.AAD.3.5` | `-TestId CISA.MS.AAD.3.5` | | `-Tag Severity:High` | `-Severity High` | diff --git a/website/src/pages/index.js b/website/src/pages/index.js index 9d743ddcea..ff3e014de7 100644 --- a/website/src/pages/index.js +++ b/website/src/pages/index.js @@ -131,7 +131,8 @@ const suites = [ title: "ASD Essential Eight", desc: "Australian Signals Directorate Essential Eight requirements and ISM controls.", count: "14 tests", - href: "/docs/tests/asd", + // /docs/ serves the released docs, which predate the ASD suite. Use /docs/tests/asd once a release includes it. + href: "/docs/next/tests/asd", }, { emoji: "📨",