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
17 changes: 9 additions & 8 deletions .github/workflows/attribute-review.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,17 @@ jobs:
exit 0
}

$changed = gh api "repos/$env:REPO/pulls/$env:PR_NUMBER/files" --paginate --jq '.[] | select(.status != "removed") | .filename'
$changed = @(gh api "repos/$env:REPO/pulls/$env:PR_NUMBER/files" --paginate --jq '.[] | {status, filename, previous_filename} | @json' | ForEach-Object { $_ | ConvertFrom-Json })
if ($LASTEXITCODE -ne 0) { throw 'Could not list the files of the pull request.' }

# Test files only, with plain path characters, so a file name cannot point outside the temp folder.
$tests = @($changed | Where-Object { $_ -match '^tests/[A-Za-z0-9._/-]+/Test\.[A-Za-z0-9._-]+\.(ps1|md)$' -and $_ -notmatch '\.\.' })
if ($tests.Count -gt 400) { throw "The pull request changes $($tests.Count) test files, more than this job downloads. Ask a maintainer to review the attributes." }
# Keep deleted and renamed-old paths for the related-test index; download only paths present at head.
. ./build/review/Get-MtReviewPullRequestFile.ps1
$tests = Get-MtReviewPullRequestFile -Changed $changed

$head = Join-Path $env:RUNNER_TEMP 'pr-head'
$null = New-Item -ItemType Directory -Path $head -Force
$headers = @{ Authorization = "Bearer $env:GH_TOKEN"; Accept = 'application/vnd.github.raw'; 'X-GitHub-Api-Version' = '2022-11-28' }
foreach ($path in $tests) {
foreach ($path in $tests.Download) {
$target = Join-Path $head $path
$null = New-Item -ItemType Directory -Path (Split-Path $target) -Force
$encoded = ($path -split '/' | ForEach-Object { [uri]::EscapeDataString($_) }) -join '/'
Expand All @@ -87,9 +88,9 @@ jobs:
if ((Get-Item -LiteralPath $target).Length -gt 512KB) { throw "$path is larger than 512 KB." }
}

$tests | Set-Content (Join-Path $env:RUNNER_TEMP 'pr-files.txt')
"count=$($tests.Count)" >> $env:GITHUB_OUTPUT
Write-Host "Downloaded $($tests.Count) test file(s)."
$tests.Review | Set-Content (Join-Path $env:RUNNER_TEMP 'pr-files.txt')
"count=$($tests.Review.Count)" >> $env:GITHUB_OUTPUT
Write-Host "Downloaded $($tests.Download.Count) test file(s); listed $($tests.Review.Count) for review."

- name: Review the attributes against the rubric
id: review
Expand Down
8 changes: 7 additions & 1 deletion build/docs/Export-MtTestCatalogForDocs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
requirement relates to. Benchmark is null for every other test. Frameworks at the top level gives the Name,
Version and Url of each framework by Key.

TestReplacements maps retired native test IDs to surviving checks so the website
preserves their historical test-page URLs after consolidation.

Packs lists the packs that ship with Maester (packs/<name>/maester-pack.json) with the tests of their catalog,
such as the Zero Trust Assessment's, so the site can show them beside the built-in checks. The Taxonomy names
the keys and techniques that the packs' tests use as well.
Expand Down Expand Up @@ -162,7 +165,10 @@ $frameworks = @([System.Linq.Enumerable]::OrderBy([object[]]$declared, [Func[obj
[ordered]@{ Key = $_.Key; Name = $_.Name; Version = $_.Version; Url = $_.Url }
})

$json = ConvertTo-Json -InputObject ([ordered]@{ Taxonomy = $taxonomy; Frameworks = $frameworks; Packs = @($packs); Tests = @($catalog) }) -Depth 6
$replacements = Import-PowerShellDataFile -LiteralPath (Join-Path $repoRoot 'build/golden/native-test-replacements.psd1')
$orderedReplacements = [ordered]@{}
foreach ($id in ($replacements.Keys | Sort-Object)) { $orderedReplacements[$id] = $replacements[$id] }
$json = ConvertTo-Json -InputObject ([ordered]@{ Taxonomy = $taxonomy; Frameworks = $frameworks; Packs = @($packs); Tests = @($catalog); TestReplacements = $orderedReplacements }) -Depth 6
$json = $json.Replace("`r`n", "`n") + "`n"
$outDir = Split-Path $OutputPath -Parent
if ($outDir -and -not (Test-Path $outDir)) { New-Item -ItemType Directory -Path $outDir -Force | Out-Null }
Expand Down
12 changes: 6 additions & 6 deletions build/golden/Export-MtLegacyTagTable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
-Tag CA, -Tag CIS, -ExcludeTag MS.AAD.3.5 and every other 2.x tag keep selecting the same tests, the
module ships a table that maps each 2.x tag to the IDs of the built-in tests that carried it.

The table is derived from two frozen files and nothing else, so the output never changes with tests/:
The table is derived from two frozen files and explicit native test replacements:

powershell/tests/fixtures/golden/tags-and-blocks.json the tags of every built-in test in 2.x
powershell/tests/fixtures/golden/tags-3.0-preview.json tags the 3.0 previews added (for example AI)
build/golden/native-test-replacements.psd1 intentional renames and consolidations

Rules:
- A tag is matched case-insensitively; the table keeps the first spelling of the snapshot.
Expand All @@ -22,7 +23,8 @@
obvious one ($Replacements below, and -Severity for Severity:<value>). The engine names it in the
warning it writes when a run selects through the tag.

Tests added after 3.0 are not in the table. The file is generated once and is not edited by hand;
Tests added after 3.0 are not in the table unless they replace a historical check.
Regenerate when native replacements change; never edit the table by hand.
powershell/tests/functions/golden/Golden.Tests.ps1 checks that it is what this script produces.

.EXAMPLE
Expand All @@ -49,10 +51,8 @@ $ErrorActionPreference = 'Stop'
$RepoRoot = (Resolve-Path -Path $RepoRoot).Path
$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.
}
# Explicit replacements, never a dynamic filter that could hide an accidental test deletion.
$RenamedIds = Import-PowerShellDataFile -LiteralPath (Join-Path $RepoRoot 'build/golden/native-test-replacements.psd1')

# The typed selector that takes the place of a tag. Only tags with an obvious one are listed.
$Replacements = [ordered]@{
Expand Down
22 changes: 22 additions & 0 deletions build/golden/native-test-replacements.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@{
# Explicit replacements preserve historical selection without hiding accidental deletions.
'MT1060' = 'MT.1060'
'AD-GPO-03' = 'AD-GPO-02'
'AD-GPO-05' = 'AD-GPO-04'
'AD-GPOL-06' = 'AD-GPOL-03'
'AD-GPOREP-02' = 'AD-GPOREP-01'
'AD-GPOREP-04' = 'AD-GPOREP-03'
'AD-GPOREP-08' = 'AD-GPOREP-07'
'AD-GPOREP-11' = 'AD-GPOREP-10'
'AD-GPOREP-13' = 'AD-GPOREP-12'
'AD-GPOREP-16' = 'AD-GPOREP-15'
'AD-GPOREP-18' = 'AD-GPOREP-17'
'AD-GPOREP-19' = 'AD-GPOREP-17'
'AD-GPOREP-20' = 'AD-GPOREP-17'
'AD-GPOS-01' = 'AD-GPO-01'
'AD-GPOS-03' = 'AD-GPOS-02'
'AD-GPOS-05' = 'AD-GPOS-04'
'AD-GPOS-06' = 'AD-GPOS-04'
'AD-GPOS-07' = 'AD-GPOS-04'
'AD-GPOS-09' = 'AD-GPOS-08'
}
35 changes: 35 additions & 0 deletions build/review/Get-MtReviewPullRequestFile.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function Get-MtReviewPullRequestFile {
<#
.SYNOPSIS
Selects safe test paths for review and head downloads from the pull request files API.
#>
[CmdletBinding()]
[OutputType([pscustomobject])]
param(
[AllowEmptyCollection()]
[object[]] $Changed,

[int] $MaxFiles = 400
)

$review = [System.Collections.Generic.List[string]]::new()
$download = [System.Collections.Generic.List[string]]::new()
$seen = [System.Collections.Generic.HashSet[string]]::new([StringComparer]::Ordinal)
foreach ($file in $Changed) {
$paths = @([string] $file.filename)
if ($file.status -eq 'renamed' -and $file.PSObject.Properties['previous_filename'] -and $file.previous_filename) {
$paths += [string] $file.previous_filename
}
foreach ($path in $paths) {
if ($path -notmatch '^tests/[A-Za-z0-9._/-]+/Test\.[A-Za-z0-9._-]+\.(ps1|md)$' -or $path -match '\.\.') { continue }
if ($seen.Add($path)) { $review.Add($path) }
if ($path -eq $file.filename -and $file.status -ne 'removed' -and $path -notin $download) {
$download.Add($path)
}
}
}
if ($review.Count -gt $MaxFiles) {
throw "The pull request changes $($review.Count) test files, more than this job downloads. Ask a maintainer to review the attributes."
}
[pscustomobject]@{ Review = $review.ToArray(); Download = $download.ToArray() }
}
5 changes: 5 additions & 0 deletions build/review/Invoke-MtAttributeReview.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ function Get-MtReviewTarget {
Sort-Object -Unique

foreach ($path in $testPaths) {
# A listed .ps1 absent from the downloaded head was deleted (or renamed). Do not fall back to the
# trusted base copy; that fallback is only for a Markdown-only change whose .ps1 was not listed.
if ($path -in @($File | Where-Object { $_ } | ForEach-Object { $_ -replace '\\', '/' }) -and
-not (Test-Path -LiteralPath (Join-Path $HeadRoot $path) -PathType Leaf) -and
(Resolve-Path $HeadRoot).Path -ne (Resolve-Path $Root).Path) { continue }
$source = Get-MtReviewContent -Root $Root -HeadRoot $HeadRoot -BaseRef $BaseRef -RelativePath $path
if ($null -eq $source.Head) { continue } # the test was deleted
$markdown = Get-MtReviewContent -Root $Root -HeadRoot $HeadRoot -BaseRef $BaseRef -RelativePath ($path -replace '\.ps1$', '.md')
Expand Down
149 changes: 111 additions & 38 deletions powershell/assets/Maester.LegacyTags.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,44 +146,26 @@
"AD-GMC-11",
"AD-GPO-01",
"AD-GPO-02",
"AD-GPO-03",
"AD-GPO-04",
"AD-GPO-05",
"AD-GPOL-01",
"AD-GPOL-02",
"AD-GPOL-03",
"AD-GPOL-04",
"AD-GPOL-05",
"AD-GPOL-06",
"AD-GPOREP-01",
"AD-GPOREP-02",
"AD-GPOREP-03",
"AD-GPOREP-04",
"AD-GPOREP-05",
"AD-GPOREP-06",
"AD-GPOREP-07",
"AD-GPOREP-08",
"AD-GPOREP-09",
"AD-GPOREP-10",
"AD-GPOREP-11",
"AD-GPOREP-12",
"AD-GPOREP-13",
"AD-GPOREP-14",
"AD-GPOREP-15",
"AD-GPOREP-16",
"AD-GPOREP-17",
"AD-GPOREP-18",
"AD-GPOREP-19",
"AD-GPOREP-20",
"AD-GPOS-01",
"AD-GPOS-02",
"AD-GPOS-03",
"AD-GPOS-04",
"AD-GPOS-05",
"AD-GPOS-06",
"AD-GPOS-07",
"AD-GPOS-08",
"AD-GPOS-09",
"AD-GRP-01",
"AD-GRP-02",
"AD-GRP-03",
Expand Down Expand Up @@ -288,6 +270,114 @@
"AD-USER-29"
]
},
{
"Tag": "AD-GPO-03",
"Tests": [
"AD-GPO-02"
]
},
{
"Tag": "AD-GPO-05",
"Tests": [
"AD-GPO-04"
]
},
{
"Tag": "AD-GPOL-06",
"Tests": [
"AD-GPOL-03"
]
},
{
"Tag": "AD-GPOREP-02",
"Tests": [
"AD-GPOREP-01"
]
},
{
"Tag": "AD-GPOREP-04",
"Tests": [
"AD-GPOREP-03"
]
},
{
"Tag": "AD-GPOREP-08",
"Tests": [
"AD-GPOREP-07"
]
},
{
"Tag": "AD-GPOREP-11",
"Tests": [
"AD-GPOREP-10"
]
},
{
"Tag": "AD-GPOREP-13",
"Tests": [
"AD-GPOREP-12"
]
},
{
"Tag": "AD-GPOREP-16",
"Tests": [
"AD-GPOREP-15"
]
},
{
"Tag": "AD-GPOREP-18",
"Tests": [
"AD-GPOREP-17"
]
},
{
"Tag": "AD-GPOREP-19",
"Tests": [
"AD-GPOREP-17"
]
},
{
"Tag": "AD-GPOREP-20",
"Tests": [
"AD-GPOREP-17"
]
},
{
"Tag": "AD-GPOS-01",
"Tests": [
"AD-GPO-01"
]
},
{
"Tag": "AD-GPOS-03",
"Tests": [
"AD-GPOS-02"
]
},
{
"Tag": "AD-GPOS-05",
"Tests": [
"AD-GPOS-04"
]
},
{
"Tag": "AD-GPOS-06",
"Tests": [
"AD-GPOS-04"
]
},
{
"Tag": "AD-GPOS-07",
"Tests": [
"AD-GPOS-04"
]
},
{
"Tag": "AD-GPOS-09",
"Tests": [
"AD-GPOS-08"
]
},
{
"Tag": "AD.Computer",
"Tests": [
Expand Down Expand Up @@ -444,49 +534,32 @@
"Tests": [
"AD-GPO-01",
"AD-GPO-02",
"AD-GPO-03",
"AD-GPO-04",
"AD-GPO-05",
"AD-GPOL-01",
"AD-GPOL-02",
"AD-GPOL-03",
"AD-GPOL-04",
"AD-GPOL-05",
"AD-GPOL-06"
"AD-GPOL-05"
]
},
{
"Tag": "AD.GPOState",
"Tests": [
"AD-GPO-01",
"AD-GPOREP-01",
"AD-GPOREP-02",
"AD-GPOREP-03",
"AD-GPOREP-04",
"AD-GPOREP-05",
"AD-GPOREP-06",
"AD-GPOREP-07",
"AD-GPOREP-08",
"AD-GPOREP-09",
"AD-GPOREP-10",
"AD-GPOREP-11",
"AD-GPOREP-12",
"AD-GPOREP-13",
"AD-GPOREP-14",
"AD-GPOREP-15",
"AD-GPOREP-16",
"AD-GPOREP-17",
"AD-GPOREP-18",
"AD-GPOREP-19",
"AD-GPOREP-20",
"AD-GPOS-01",
"AD-GPOS-02",
"AD-GPOS-03",
"AD-GPOS-04",
"AD-GPOS-05",
"AD-GPOS-06",
"AD-GPOS-07",
"AD-GPOS-08",
"AD-GPOS-09"
"AD-GPOS-08"
]
},
{
Expand Down
Loading
Loading