Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 53 additions & 3 deletions build/golden/Export-MtLegacyIdTable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
function - the single check function called in the It body is called by exactly one current test
retired - nothing matched

The output is deterministic: GeneratedFrom is the last commit that touched the scanned test files,
and current IDs are read from that commit's tree, so rerunning on a later commit that does not touch
tests/ produces identical output.
GeneratedFrom is the last commit that touched the scanned Pester test files. Current native test IDs,
titles and function names are read from the working tree so legacy checks can map to their native replacements.

.EXAMPLE
./build/golden/Export-MtLegacyIdTable.ps1
Expand Down Expand Up @@ -55,6 +54,21 @@ $ManualOverrides = [ordered]@{
# Pre-colon names of the split checks; the current titles say 'Global Administrator' and both call one function.
'MT.1050 Apps with high-risk permissions having a direct path to Global Admin' = 'MT.1050'
'MT.1051 Apps with high-risk permissions having an indirect path to Global Admin' = 'MT.1051'
# CISA moved the email malware checks to the Security Suite baseline.
'CISA.MS.EXO.09.5' = 'CISA.MS.SECURITYSUITE.1.1'
'CISA.MS.EXO.9.5' = 'CISA.MS.SECURITYSUITE.1.1'
'CISA.MS.EXO.10.3' = 'CISA.MS.SECURITYSUITE.1.2'
'CISA.MS.EXO.9.1' = 'CISA.MS.SECURITYSUITE.1.1'
'CISA.MS.EXO.9.3' = 'CISA.MS.SECURITYSUITE.1.1'
'CISA.MS.EXO.10.1' = 'CISA.MS.SECURITYSUITE.1.3'
'CISA.MS.EXO.10.2' = 'CISA.MS.SECURITYSUITE.1.3'
'MS.EXO.09.5' = 'CISA.MS.SECURITYSUITE.1.1'
'MS.EXO.9.5' = 'CISA.MS.SECURITYSUITE.1.1'
'MS.EXO.10.3' = 'CISA.MS.SECURITYSUITE.1.2'
'MS.EXO.9.1' = 'CISA.MS.SECURITYSUITE.1.1'
'MS.EXO.9.3' = 'CISA.MS.SECURITYSUITE.1.1'
'MS.EXO.10.1' = 'CISA.MS.SECURITYSUITE.1.3'
'MS.EXO.10.2' = 'CISA.MS.SECURITYSUITE.1.3'
# Mock-based unit tests that briefly lived under tests/; they were never security checks.
'MFA for All users should pass even if not targeting guests' = 'retired'
'MFA for All users that excludes any guest type should fail' = 'retired'
Expand Down Expand Up @@ -263,6 +277,42 @@ foreach ($line in $treeLines) {
}
Write-Verbose "Current static IDs: $($currentIds.Count); family prefixes: $($familyPrefixes -join ', ')"

# Native tests are current checks after migration from the Pester format.
$nativeTestFiles = Get-ChildItem -Path (Join-Path $RepoRoot 'tests') -Recurse -File -Filter 'Test.*.ps1' |
Where-Object { $_.FullName -notmatch '[\\/]Custom[\\/]' }
foreach ($file in $nativeTestFiles) {
$tokens = $null
$parseErrors = $null
$ast = [System.Management.Automation.Language.Parser]::ParseFile($file.FullName, [ref]$tokens, [ref]$parseErrors)
if ($parseErrors.Count -gt 0) {
throw "Cannot parse native test '$($file.FullName)': $($parseErrors[0].Message)"
}

$function = $ast.FindAll({
param($node)
$node -is [System.Management.Automation.Language.FunctionDefinitionAst] -and
$node.Body.ParamBlock -and
($node.Body.ParamBlock.Attributes | Where-Object { $_.TypeName.Name -in 'MaesterTest', 'MaesterTestAttribute' })
}, $true) | Select-Object -First 1
if (-not $function) {
throw "Native test '$($file.FullName)' has no MaesterTest attribute."
}

$attribute = $function.Body.ParamBlock.Attributes | Where-Object { $_.TypeName.Name -in 'MaesterTest', 'MaesterTestAttribute' } | Select-Object -First 1
$id = $file.BaseName.Substring('Test.'.Length)
$title = $attribute.NamedArguments | Where-Object { $_.ArgumentName -eq 'Title' } | Select-Object -First 1
if (-not $title -or $title.Argument -isnot [System.Management.Automation.Language.StringConstantExpressionAst]) {
throw "Native test '$($file.FullName)' has no static title."
}

$currentIds[$id] = [pscustomobject]@{
Id = $id
Title = Get-NormalizedTitle $title.Argument.Value
Functions = @($function.Name)
Path = $file.FullName.Substring($RepoRoot.Length + 1).Replace('\', '/')
}
}

$titleIndex = @{}
$functionIndex = @{}
foreach ($c in $currentIds.Values) {
Expand Down
8 changes: 7 additions & 1 deletion build/golden/Export-MtLegacyTagTable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ $fixtures = Join-Path $RepoRoot 'powershell/tests/fixtures/golden'

# 2.x IDs that have another ID in 3.0.
$RenamedIds = @{
'MT1060' = 'MT.1060' # The drift family: four Its per folder in 2.x, one native family in 3.0.
'MT1060' = 'MT.1060' # The drift family: four Its per folder in 2.x, one native family in 3.0.
'CISA.MS.EXO.9.1' = 'CISA.MS.SECURITYSUITE.1.1'
'CISA.MS.EXO.9.3' = 'CISA.MS.SECURITYSUITE.1.1'
'CISA.MS.EXO.9.5' = 'CISA.MS.SECURITYSUITE.1.1'
'CISA.MS.EXO.10.1' = 'CISA.MS.SECURITYSUITE.1.3'
'CISA.MS.EXO.10.2' = 'CISA.MS.SECURITYSUITE.1.3'
'CISA.MS.EXO.10.3' = 'CISA.MS.SECURITYSUITE.1.2'
}

# The typed selector that takes the place of a tag. Only tags with an obvious one are listed.
Expand Down
4 changes: 4 additions & 0 deletions powershell/Maester.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ $__MtSession = @{
SpoCache = @{} # Cache for SharePoint Online tenant settings retrieved via PnP
FabricCache = @{} # Fabric admin API data cached for the current test run
GitHubCache = @{} # Per-session REST response cache; cleared each Invoke-Maester run
TeamsCache = @{} # Teams admin API data cached for the current test run
TeamsAuthCache = @{} # Teams unified settings MSAL client; retained until disconnect
TeamsUseDeviceCode = $false # Whether Connect-Maester requested device-code authentication
TeamsEnvironmentName = $null # Explicit Teams PowerShell environment, when provided
ADCache = @{} # Active Directory data cache
ADConnection = $null # Active Directory connection state
ADCredential = $null # Active Directory credential retained only for the connected session
Expand Down
Loading
Loading