Skip to content
Open
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
6 changes: 3 additions & 3 deletions build/Test-MaesterModuleOutput.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Write-Host ' Verified: ORCA classes resolve inside the module'
# Check 5 — Runtime result details resolve companion Markdown from the bundle
# ──────────────────────────────────────────────────────────────────────────────

$MetadataProbeCommand = 'Test-MtCisaDlp'
$MetadataProbeCommand = 'Test-MtCisaDlpSensitiveInformation'
$MetadataProbeProperty = $TestMetadata.PSObject.Properties[$MetadataProbeCommand]
if (-not $MetadataProbeProperty) {
throw "Test metadata bundle is missing the runtime probe entry: $MetadataProbeCommand"
Expand All @@ -205,13 +205,13 @@ $MetadataProbeValue = 'Metadata bundle runtime probe'
$MetadataProbeResult = & $ImportedModule {
param($TestName, $ProbeValue)

function Test-MtCisaDlp {
function Test-MtCisaDlpSensitiveInformation {
param($Name, $Result)

Add-MtTestResultDetail -TestName $Name -TestTitle $Name -Result $Result
}

Test-MtCisaDlp -Name $TestName -Result $ProbeValue
Test-MtCisaDlpSensitiveInformation -Name $TestName -Result $ProbeValue
$__MtSession.TestResultDetail[$TestName]
} $MetadataProbeTestName $MetadataProbeValue

Expand Down
122 changes: 107 additions & 15 deletions build/golden/Export-MtLegacyIdTable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
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 test IDs, titles and
function names are read from the working tree. CurrentTestsHash identifies the built-in test files used.
Existing mappings are retained when their target still exists, so moving a check from a Pester wrapper
to a native test does not discard its legacy IDs.

.EXAMPLE
./build/golden/Export-MtLegacyIdTable.ps1
Expand Down Expand Up @@ -49,6 +50,21 @@ $RepoRoot = (Resolve-Path -Path $RepoRoot).Path
#region Manual overrides
# Reviewed by hand. Value is a current ID or 'retired'. Applied before every automatic rule.
$ManualOverrides = [ordered]@{
# Exchange DLP requirements consolidated into the Security Suite sensitive-information requirement.
'CISA.MS.EXO.08.1' = 'CISA.MS.SECURITYSUITE.3.1'
'CISA.MS.EXO.8.1' = 'CISA.MS.SECURITYSUITE.3.1'
'CISA.MS.EXO.8.2' = 'CISA.MS.SECURITYSUITE.3.1'
'CISA.MS.EXO.8.4' = 'CISA.MS.SECURITYSUITE.3.1'
'MS.EXO.08.1' = 'CISA.MS.SECURITYSUITE.3.1'
'MS.EXO.08.2' = 'CISA.MS.SECURITYSUITE.3.1'
'MS.EXO.08.4' = 'CISA.MS.SECURITYSUITE.3.1'
'MS.EXO.8.1' = 'CISA.MS.SECURITYSUITE.3.1'
'MS.EXO.8.2' = 'CISA.MS.SECURITYSUITE.3.1'
'MS.EXO.8.4' = 'CISA.MS.SECURITYSUITE.3.1'
# Preserve the existing targets when a native CIS check shares the historical title.
'Ensure MailTips are enabled for end users' = 'MT.1039'
'Ensure modern authentication for Exchange Online is enabled' = 'MT.1044'
'Ensure users installing Outlook add-ins is not allowed' = 'MT.1041'
# The original combined high-risk app permission check, later split into MT.1050 (direct) and MT.1051 (indirect).
'Ensure no graph application has permissions with a risk of having a direct or indirect path to Global Admin and full tenant takeover.' = 'MT.1050'
'MT.1050 Apps with high-risk permissions having a direct or indirect path to Global Admin' = 'MT.1050'
Expand Down Expand Up @@ -244,21 +260,81 @@ foreach ($commit in $commits) {
}
#endregion Scan history

#region Current IDs (from the tree of $generatedFrom)
#region Current IDs
$currentIds = [System.Collections.Generic.Dictionary[string, object]]::new([System.StringComparer]::OrdinalIgnoreCase)
$familyPrefixes = [System.Collections.Generic.SortedSet[string]]::new([System.StringComparer]::Ordinal)
$treeLines = Invoke-Git ls-tree -r $generatedFrom -- tests
foreach ($line in $treeLines) {
if ($line -notmatch '^\d+ blob ([0-9a-f]{40})\t(tests/.+\.tests\.ps1)$') { continue }
if ($Matches[2] -like 'tests/Custom/*') { continue }
$path = $Matches[2]
foreach ($it in (Get-BlobItInfo -Blob $Matches[1])) {
$split = Get-StaticSplit -Name $it.Name
if (-not $split) {
if ($it.Name -match '^([A-Za-z]+\.?\d+)\.(<|\$\()') { $null = $familyPrefixes.Add("$($Matches[1]).") }
continue
$testFiles = Get-ChildItem -Path (Join-Path $RepoRoot 'tests') -Recurse -File |
Where-Object {
$_.FullName -notmatch '[\\/]Custom[\\/]' -and
($_.Name -like '*.Tests.ps1' -or $_.Name -like 'Test.*.ps1')
}
$testFilesByPath = [System.Collections.Generic.Dictionary[string, System.IO.FileInfo]]::new([System.StringComparer]::Ordinal)
$testPaths = [System.Collections.Generic.List[string]]::new()
foreach ($file in $testFiles) {
$path = [System.IO.Path]::GetRelativePath($RepoRoot, $file.FullName).Replace('\', '/')
$testFilesByPath.Add($path, $file)
$testPaths.Add($path)
}
$testPaths.Sort([System.StringComparer]::Ordinal)
$testFileManifest = [System.Collections.Generic.List[string]]::new()
foreach ($path in $testPaths) {
$content = [System.IO.File]::ReadAllText($testFilesByPath[$path].FullName) -replace "`r`n|`r", "`n"
$fileHash = [System.Convert]::ToHexString(
[System.Security.Cryptography.SHA256]::HashData([System.Text.Encoding]::UTF8.GetBytes($content))
).ToLowerInvariant()
$testFileManifest.Add("$path`0$fileHash")
}
$currentTestsHash = [System.Convert]::ToHexString(
[System.Security.Cryptography.SHA256]::HashData(
[System.Text.Encoding]::UTF8.GetBytes(($testFileManifest -join "`n"))
)
).ToLowerInvariant()

foreach ($path in $testPaths) {
$file = $testFilesByPath[$path]
if ($file.Name -like '*.Tests.ps1') {
foreach ($it in (Get-ItInfo -Content ([System.IO.File]::ReadAllText($file.FullName)))) {
$split = Get-StaticSplit -Name $it.Name
if (-not $split) {
if ($it.Name -match '^([A-Za-z]+\.?\d+)\.(<|\$\()') { $null = $familyPrefixes.Add("$($Matches[1]).") }
continue
}
$currentIds[$split.Id] = [pscustomobject]@{
Id = $split.Id; Title = (Get-NormalizedTitle $split.Title); Functions = $it.Functions; Path = $path
}
}
$currentIds[$split.Id] = [pscustomobject]@{ Id = $split.Id; Title = (Get-NormalizedTitle $split.Title); Functions = $it.Functions; Path = $path }
continue
}

$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 = $path
}
}
Write-Verbose "Current static IDs: $($currentIds.Count); family prefixes: $($familyPrefixes -join ', ')"
Expand All @@ -276,6 +352,18 @@ foreach ($c in $currentIds.Values) {
}
#endregion Current IDs

#region Existing mappings
$priorMappings = @{}
if (Test-Path -LiteralPath $OutputPath) {
$priorTable = Get-Content -LiteralPath $OutputPath -Raw | ConvertFrom-Json
foreach ($entry in $priorTable.Entries) {
if ($entry.CurrentId -and $entry.CurrentId -ne 'retired') {
$priorMappings[$entry.LegacyId] = $entry
}
}
}
#endregion Existing mappings

#region Map
$entries = [System.Collections.Generic.List[object]]::new()
$review = [System.Collections.Generic.List[string]]::new()
Expand Down Expand Up @@ -303,6 +391,8 @@ foreach ($record in $history.Values) {
$currentId = $ManualOverrides[$record.Id]; $rule = 'manual'
} elseif ($prefixTarget) {
$currentId = $prefixTarget; $rule = 'prefix'
} elseif ($priorMappings.ContainsKey($record.Id) -and $currentIds.ContainsKey($priorMappings[$record.Id].CurrentId)) {
$currentId = $priorMappings[$record.Id].CurrentId; $rule = $priorMappings[$record.Id].Rule
} elseif ($titleCandidates.Count -eq 1) {
$currentId = @($titleCandidates)[0]; $rule = 'title'
if ($functionCandidates.Count -gt 0 -and -not $functionCandidates.Contains($currentId)) {
Expand Down Expand Up @@ -349,11 +439,13 @@ $sortedEntries | Group-Object { $_.Rule } | Sort-Object Name | ForEach-Object {
$retiredFamilies = @($historicalFamilies | Where-Object { -not $familyPrefixes.Contains($_) })
if ($retiredFamilies) { Write-Warning "Historical family prefixes no longer at HEAD: $($retiredFamilies -join ', ')" }
foreach ($line in ($review | Sort-Object)) { Write-Verbose "REVIEW $line" }
$familyPrefixes.UnionWith($historicalFamilies)
#endregion Report

$document = [ordered]@{
SchemaVersion = '1.0'
GeneratedFrom = $generatedFrom
CurrentTestsHash = $currentTestsHash
Entries = $sortedEntries
FamilyPrefixes = @($familyPrefixes)
}
Expand Down
3 changes: 3 additions & 0 deletions build/golden/Export-MtLegacyTagTable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ $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.
'CISA.MS.EXO.8.1' = 'CISA.MS.SECURITYSUITE.3.1'
'CISA.MS.EXO.8.2' = 'CISA.MS.SECURITYSUITE.3.1'
'CISA.MS.EXO.8.4' = 'CISA.MS.SECURITYSUITE.3.1'
}

# The typed selector that takes the place of a tag. Only tags with an obvious one are listed.
Expand Down
9 changes: 7 additions & 2 deletions build/golden/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ Regenerate it after a change to `tests/` that renames or removes a check:
script), `prefix` (known prefix renames such as `MS.` to `CISA.MS.`), `title`
(same normalised title), `function` (same single `Test-*` function called),
otherwise `retired`.
- Current native IDs, titles and function names are read from the working tree.
The former Exchange DLP checks 8.1, 8.2 and 8.4 map to `CISA.MS.SECURITYSUITE.3.1`.
- `-Verbose` prints counts by rule and a `REVIEW` line for each ambiguous, conflicting
or title-only match. Resolve ambiguous ones by adding them to `$ManualOverrides`.
- `GeneratedFrom` is the last commit that touched the scanned test files, so the
output only changes when `tests/` changes.
- `GeneratedFrom` is the last commit that touched the historical Pester test files.
Current built-in Pester and native test files are read from the working tree;
`CurrentTestsHash` is a SHA-256 fingerprint of their relative paths and contents.
- Existing mappings are retained when their targets still exist, so moving a check
from a Pester wrapper to a native test does not discard its legacy IDs.
- `powershell/tests/general/LegacyIds.Tests.ps1` checks that no legacy ID is a current ID
and that every target ID still exists. If it fails after you rename or remove a
check, regenerate the table.
Expand Down
Loading
Loading