diff --git a/build/Test-MaesterModuleOutput.ps1 b/build/Test-MaesterModuleOutput.ps1 index a32a1c87b0..60f1e6f7ca 100644 --- a/build/Test-MaesterModuleOutput.ps1 +++ b/build/Test-MaesterModuleOutput.ps1 @@ -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" @@ -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 diff --git a/build/golden/Export-MtLegacyIdTable.ps1 b/build/golden/Export-MtLegacyIdTable.ps1 index e5a8d8ea9e..a6a01fdb84 100644 --- a/build/golden/Export-MtLegacyIdTable.ps1 +++ b/build/golden/Export-MtLegacyIdTable.ps1 @@ -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 @@ -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' @@ -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 ', ')" @@ -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() @@ -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)) { @@ -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) } diff --git a/build/golden/Export-MtLegacyTagTable.ps1 b/build/golden/Export-MtLegacyTagTable.ps1 index 33da8e4eff..9b1ff7d9f2 100644 --- a/build/golden/Export-MtLegacyTagTable.ps1 +++ b/build/golden/Export-MtLegacyTagTable.ps1 @@ -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. diff --git a/build/golden/README.md b/build/golden/README.md index 2ec873cc51..12fef15a47 100644 --- a/build/golden/README.md +++ b/build/golden/README.md @@ -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. diff --git a/powershell/assets/Maester.LegacyIds.json b/powershell/assets/Maester.LegacyIds.json index d0681e44a6..32c5d321a7 100644 --- a/powershell/assets/Maester.LegacyIds.json +++ b/powershell/assets/Maester.LegacyIds.json @@ -1,6 +1,7 @@ { "SchemaVersion": "1.0", - "GeneratedFrom": "fc6a9078bcdd59b5b2f788682fdcd2be27e15b9c", + "GeneratedFrom": "eb13e7a116e4063bec204e901e4847ae67c1f6f6", + "CurrentTestsHash": "29cbff210eb9a560ee7c1f92d7b38fc7256b3aa70a39584e85f8b28a80ad6e19", "Entries": [ { "LegacyId": "1.1.1 (L1) Ensure Administrative accounts are cloud-only", @@ -29,7 +30,7 @@ { "LegacyId": "2.1.3 (L1) Ensure notifications for internal users sending malware is Enabled", "CurrentId": "CIS.M365.2.1.3", - "Rule": "function", + "Rule": "title", "FirstSeenCommit": "6e0a967fc7e6c2ba3d711ae650b49402f145f624", "LastSeenCommit": "6e0a967fc7e6c2ba3d711ae650b49402f145f624", "LastSeenFile": "tests/cis/Test-MtCisInternalMalwareNotification.Tests.ps1" @@ -37,7 +38,7 @@ { "LegacyId": "2.1.3 (L1) Ensure notifications for internal users sending malware is Enabled (Only Checks Default Policy)", "CurrentId": "CIS.M365.2.1.3", - "Rule": "title", + "Rule": "function", "FirstSeenCommit": "7e35b57b0f8c01aedc4a29d057a810830a98d873", "LastSeenCommit": "7e35b57b0f8c01aedc4a29d057a810830a98d873", "LastSeenFile": "tests/cis/Test-MtCisInternalMalwareNotification.Tests.ps1" @@ -53,7 +54,7 @@ { "LegacyId": "2.1.4 (L2) Ensure Safe Attachments policy is enabled (Only Checks Default Policy)", "CurrentId": "CIS.M365.2.1.4", - "Rule": "title", + "Rule": "function", "FirstSeenCommit": "7e35b57b0f8c01aedc4a29d057a810830a98d873", "LastSeenCommit": "7e35b57b0f8c01aedc4a29d057a810830a98d873", "LastSeenFile": "tests/cis/Test-MtCisSafeAttachment.Tests.ps1" @@ -69,7 +70,7 @@ { "LegacyId": "2.1.6 (L1) Ensure Exchange Online Spam Policies are set to notify administrators", "CurrentId": "CIS.M365.2.1.6", - "Rule": "function", + "Rule": "title", "FirstSeenCommit": "811ca62ea0cd22285c9393b56acdd3e338ad5f0f", "LastSeenCommit": "d559e19379a79601c1b0fbe83e21f0e1392ffebe", "LastSeenFile": "tests/cis/Test-MtCisOutboundSpamFilterPolicy.Tests.ps1" @@ -77,7 +78,7 @@ { "LegacyId": "2.1.6 (L1) Ensure Exchange Online Spam Policies are set to notify administrators (Only Checks Default Policy)", "CurrentId": "CIS.M365.2.1.6", - "Rule": "title", + "Rule": "function", "FirstSeenCommit": "7e35b57b0f8c01aedc4a29d057a810830a98d873", "LastSeenCommit": "7e35b57b0f8c01aedc4a29d057a810830a98d873", "LastSeenFile": "tests/cis/Test-MtCisOutboundSpamFilterPolicy.Tests.ps1" @@ -85,7 +86,7 @@ { "LegacyId": "2.1.7 (L1) Ensure that an anti-phishing policy has been created (Only Checks Default Policy)", "CurrentId": "CIS.M365.2.1.7", - "Rule": "title", + "Rule": "function", "FirstSeenCommit": "2487d220155d59d0a35da593584baf23d58bdf41", "LastSeenCommit": "2487d220155d59d0a35da593584baf23d58bdf41", "LastSeenFile": "tests/cis/Test-MtCisSafeAntiPhishingPolicy.Tests.ps1" @@ -957,7 +958,7 @@ { "LegacyId": "CIS 2.1.3 (L1) Ensure notifications for internal users sending malware is Enabled (Only Checks Default Policy)", "CurrentId": "CIS.M365.2.1.3", - "Rule": "title", + "Rule": "function", "FirstSeenCommit": "4df9d3e671e648ae838c919e29aa1d03e50474b4", "LastSeenCommit": "8a08dabc56545cf42ebac9321351463a9f1b121e", "LastSeenFile": "tests/cis/Test-MtCisInternalMalwareNotification.Tests.ps1" @@ -965,7 +966,7 @@ { "LegacyId": "CIS 2.1.4 (L2) Ensure Safe Attachments policy is enabled (Only Checks Default Policy)", "CurrentId": "CIS.M365.2.1.4", - "Rule": "title", + "Rule": "function", "FirstSeenCommit": "4df9d3e671e648ae838c919e29aa1d03e50474b4", "LastSeenCommit": "8a08dabc56545cf42ebac9321351463a9f1b121e", "LastSeenFile": "tests/cis/Test-MtCisSafeAttachment.Tests.ps1" @@ -981,7 +982,7 @@ { "LegacyId": "CIS 2.1.6 (L1) Ensure Exchange Online Spam Policies are set to notify administrators (Only Checks Default Policy)", "CurrentId": "CIS.M365.2.1.6", - "Rule": "title", + "Rule": "function", "FirstSeenCommit": "4df9d3e671e648ae838c919e29aa1d03e50474b4", "LastSeenCommit": "8a08dabc56545cf42ebac9321351463a9f1b121e", "LastSeenFile": "tests/cis/Test-MtCisOutboundSpamFilterPolicy.Tests.ps1" @@ -989,7 +990,7 @@ { "LegacyId": "CIS 2.1.7 (L1) Ensure that an anti-phishing policy has been created (Only Checks Default Policy)", "CurrentId": "CIS.M365.2.1.7", - "Rule": "title", + "Rule": "function", "FirstSeenCommit": "4df9d3e671e648ae838c919e29aa1d03e50474b4", "LastSeenCommit": "8a08dabc56545cf42ebac9321351463a9f1b121e", "LastSeenFile": "tests/cis/Test-MtCisSafeAntiPhishingPolicy.Tests.ps1" @@ -1108,8 +1109,8 @@ }, { "LegacyId": "CISA.MS.EXO.08.1", - "CurrentId": "CISA.MS.EXO.8.1", - "Rule": "title", + "CurrentId": "CISA.MS.SECURITYSUITE.3.1", + "Rule": "manual", "FirstSeenCommit": "d176a815b8cfef203cfe0672af5bc092385f05b9", "LastSeenCommit": "5810a0dc37538fe0c4884f55938f23f5c7d1d6cc", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaDlp.Tests.ps1" @@ -1130,6 +1131,30 @@ "LastSeenCommit": "5810a0dc37538fe0c4884f55938f23f5c7d1d6cc", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaBlockExecutable.Tests.ps1" }, + { + "LegacyId": "CISA.MS.EXO.8.1", + "CurrentId": "CISA.MS.SECURITYSUITE.3.1", + "Rule": "manual", + "FirstSeenCommit": "b2513b049671c82eede6415f708bb3560e6a8d06", + "LastSeenCommit": "eb38f4357cdf3576600aeca7d8da3138f77a37ca", + "LastSeenFile": "tests/cisa/exchange/Test-MtCisaDlp.Tests.ps1" + }, + { + "LegacyId": "CISA.MS.EXO.8.2", + "CurrentId": "CISA.MS.SECURITYSUITE.3.1", + "Rule": "manual", + "FirstSeenCommit": "d176a815b8cfef203cfe0672af5bc092385f05b9", + "LastSeenCommit": "eb38f4357cdf3576600aeca7d8da3138f77a37ca", + "LastSeenFile": "tests/cisa/exchange/Test-MtCisaDlpPii.Tests.ps1" + }, + { + "LegacyId": "CISA.MS.EXO.8.4", + "CurrentId": "CISA.MS.SECURITYSUITE.3.1", + "Rule": "manual", + "FirstSeenCommit": "d176a815b8cfef203cfe0672af5bc092385f05b9", + "LastSeenCommit": "eb38f4357cdf3576600aeca7d8da3138f77a37ca", + "LastSeenFile": "tests/cisa/exchange/Test-MtCisaDlpBaselineRule.Tests.ps1" + }, { "LegacyId": "Configure which users are allowed to present in Teams meetings", "CurrentId": "retired", @@ -1141,7 +1166,7 @@ { "LegacyId": "Ensure MailTips are enabled for end users", "CurrentId": "MT.1039", - "Rule": "title", + "Rule": "manual", "FirstSeenCommit": "7cd563adfc02cdecb49b1b5e755f5c541bdd4beb", "LastSeenCommit": "7cd563adfc02cdecb49b1b5e755f5c541bdd4beb", "LastSeenFile": "tests/Maester/Exchange/Test-ExchangeSetting.Tests.ps1" @@ -1189,7 +1214,7 @@ { "LegacyId": "Ensure modern authentication for Exchange Online is enabled", "CurrentId": "MT.1044", - "Rule": "title", + "Rule": "manual", "FirstSeenCommit": "7cd563adfc02cdecb49b1b5e755f5c541bdd4beb", "LastSeenCommit": "7cd563adfc02cdecb49b1b5e755f5c541bdd4beb", "LastSeenFile": "tests/Maester/Exchange/Test-ExchangeSetting.Tests.ps1" @@ -1205,7 +1230,7 @@ { "LegacyId": "Ensure users installing Outlook add-ins is not allowed", "CurrentId": "MT.1041", - "Rule": "title", + "Rule": "manual", "FirstSeenCommit": "7cd563adfc02cdecb49b1b5e755f5c541bdd4beb", "LastSeenCommit": "7cd563adfc02cdecb49b1b5e755f5c541bdd4beb", "LastSeenFile": "tests/Maester/Exchange/Test-ExchangeSetting.Tests.ps1" @@ -1764,16 +1789,16 @@ }, { "LegacyId": "MS.EXO.08.1", - "CurrentId": "CISA.MS.EXO.8.1", - "Rule": "title", + "CurrentId": "CISA.MS.SECURITYSUITE.3.1", + "Rule": "manual", "FirstSeenCommit": "062c1e6a1e0566789256aaea1e37b73dcdb11aed", "LastSeenCommit": "062c1e6a1e0566789256aaea1e37b73dcdb11aed", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaDlp.Tests.ps1" }, { "LegacyId": "MS.EXO.08.2", - "CurrentId": "CISA.MS.EXO.8.2", - "Rule": "title", + "CurrentId": "CISA.MS.SECURITYSUITE.3.1", + "Rule": "manual", "FirstSeenCommit": "062c1e6a1e0566789256aaea1e37b73dcdb11aed", "LastSeenCommit": "062c1e6a1e0566789256aaea1e37b73dcdb11aed", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaDlpPii.Tests.ps1" @@ -1788,8 +1813,8 @@ }, { "LegacyId": "MS.EXO.08.4", - "CurrentId": "CISA.MS.EXO.8.4", - "Rule": "title", + "CurrentId": "CISA.MS.SECURITYSUITE.3.1", + "Rule": "manual", "FirstSeenCommit": "062c1e6a1e0566789256aaea1e37b73dcdb11aed", "LastSeenCommit": "062c1e6a1e0566789256aaea1e37b73dcdb11aed", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaDlpBaselineRule.Tests.ps1" @@ -2092,16 +2117,16 @@ }, { "LegacyId": "MS.EXO.8.1", - "CurrentId": "CISA.MS.EXO.8.1", - "Rule": "prefix", + "CurrentId": "CISA.MS.SECURITYSUITE.3.1", + "Rule": "manual", "FirstSeenCommit": "bc80f82ffe04bf0223eef9fce6513b5e037268dc", "LastSeenCommit": "726b9fd3bc414db3c41db8c6ec9a825c0713b34e", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaDlp.Tests.ps1" }, { "LegacyId": "MS.EXO.8.2", - "CurrentId": "CISA.MS.EXO.8.2", - "Rule": "prefix", + "CurrentId": "CISA.MS.SECURITYSUITE.3.1", + "Rule": "manual", "FirstSeenCommit": "b9e70bfde94c09265882356710b8317955e009bb", "LastSeenCommit": "b9e70bfde94c09265882356710b8317955e009bb", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaDlpPii.Tests.ps1" @@ -2116,8 +2141,8 @@ }, { "LegacyId": "MS.EXO.8.4", - "CurrentId": "CISA.MS.EXO.8.4", - "Rule": "prefix", + "CurrentId": "CISA.MS.SECURITYSUITE.3.1", + "Rule": "manual", "FirstSeenCommit": "833400f78d84f3666605959b2da53c78c0f1893f", "LastSeenCommit": "833400f78d84f3666605959b2da53c78c0f1893f", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaDlpBaselineRule.Tests.ps1" diff --git a/powershell/assets/Maester.LegacyTags.json b/powershell/assets/Maester.LegacyTags.json index 2ba8db3c4b..1b23edbb7d 100644 --- a/powershell/assets/Maester.LegacyTags.json +++ b/powershell/assets/Maester.LegacyTags.json @@ -1192,15 +1192,13 @@ "CISA.MS.EXO.6.1", "CISA.MS.EXO.6.2", "CISA.MS.EXO.7.1", - "CISA.MS.EXO.8.1", - "CISA.MS.EXO.8.2", "CISA.MS.EXO.8.3", - "CISA.MS.EXO.8.4", "CISA.MS.EXO.9.1", "CISA.MS.EXO.9.2", "CISA.MS.EXO.9.3", "CISA.MS.EXO.9.4", "CISA.MS.EXO.9.5", + "CISA.MS.SECURITYSUITE.3.1", "CISA.MS.SHAREPOINT.1.1", "CISA.MS.SHAREPOINT.1.2", "CISA.MS.SHAREPOINT.1.3", @@ -1211,6 +1209,24 @@ "CISA.MS.SHAREPOINT.3.3" ] }, + { + "Tag": "CISA.MS.EXO.8.1", + "Tests": [ + "CISA.MS.SECURITYSUITE.3.1" + ] + }, + { + "Tag": "CISA.MS.EXO.8.2", + "Tests": [ + "CISA.MS.SECURITYSUITE.3.1" + ] + }, + { + "Tag": "CISA.MS.EXO.8.4", + "Tests": [ + "CISA.MS.SECURITYSUITE.3.1" + ] + }, { "Tag": "CopilotStudio", "Replacement": "-Product copilot-studio", @@ -2183,15 +2199,13 @@ "CISA.MS.EXO.6.1", "CISA.MS.EXO.6.2", "CISA.MS.EXO.7.1", - "CISA.MS.EXO.8.1", - "CISA.MS.EXO.8.2", "CISA.MS.EXO.8.3", - "CISA.MS.EXO.8.4", "CISA.MS.EXO.9.1", "CISA.MS.EXO.9.2", "CISA.MS.EXO.9.3", "CISA.MS.EXO.9.4", - "CISA.MS.EXO.9.5" + "CISA.MS.EXO.9.5", + "CISA.MS.SECURITYSUITE.3.1" ] }, { @@ -2389,13 +2403,13 @@ { "Tag": "MS.EXO.8.1", "Tests": [ - "CISA.MS.EXO.8.1" + "CISA.MS.SECURITYSUITE.3.1" ] }, { "Tag": "MS.EXO.8.2", "Tests": [ - "CISA.MS.EXO.8.2" + "CISA.MS.SECURITYSUITE.3.1" ] }, { @@ -2407,7 +2421,7 @@ { "Tag": "MS.EXO.8.4", "Tests": [ - "CISA.MS.EXO.8.4" + "CISA.MS.SECURITYSUITE.3.1" ] }, { diff --git a/powershell/internal/checks/cisa/purview/Get-MtCisaSensitiveDlpRule.ps1 b/powershell/internal/checks/cisa/purview/Get-MtCisaSensitiveDlpRule.ps1 new file mode 100644 index 0000000000..2dbbfbb3c2 --- /dev/null +++ b/powershell/internal/checks/cisa/purview/Get-MtCisaSensitiveDlpRule.ps1 @@ -0,0 +1,83 @@ +function Get-MtCisaSensitiveDlpRule { + [CmdletBinding()] + [OutputType([object[]])] + param() + + $policies = @(Get-MtExo -Request DlpCompliancePolicy) + $rules = @(Get-MtExo -Request DlpComplianceRule) + $sensitiveTypeIds = @( + '50842eb7-edc8-4019-85dd-5a5c1f2bb085', + 'a44669fe-0d48-453d-a9b1-2cc83f2cba77', + 'e55e2a32-f92d-4985-a35d-a0b269eb687b' + ) + $sensitiveTypes = @( + [pscustomobject]@{ Name = 'Credit Card Number'; Id = $sensitiveTypeIds[0] } + [pscustomobject]@{ Name = 'U.S. Social Security Number (SSN)'; Id = $sensitiveTypeIds[1] } + [pscustomobject]@{ Name = 'U.S. Individual Taxpayer Identification Number (ITIN)'; Id = $sensitiveTypeIds[2] } + ) + + $enabledPolicies = @( + $policies | Where-Object { $_.Enabled -eq $true -and $_.Mode -eq 'Enable' } | + ForEach-Object { + [pscustomobject]@{ + Name = $_.Name + Policy = $_ + } + } + ) + + $sensitiveRules = foreach ($rule in $rules) { + if ($rule.Disabled -ne $false) { + continue + } + + $parentPolicy = $enabledPolicies | + Where-Object { $_.Name -eq $rule.ParentPolicyName -or $_.Policy.Identity -eq $rule.ParentPolicyName } | + Select-Object -First 1 + if (-not $parentPolicy) { + continue + } + + $matchedTypes = [System.Collections.Generic.List[string]]::new() + if ($rule.IsAdvancedRule -eq $false) { + foreach ($contentType in @($rule.ContentContainsSensitiveInformation)) { + $contentName = if ($contentType -is [string]) { + $contentType + } elseif ($contentType.Name) { + [string]$contentType.Name + } else { + [string]$contentType.DisplayName + } + + foreach ($sensitiveType in $sensitiveTypes) { + if ($contentName -ieq $sensitiveType.Name -and $sensitiveType.Name -notin $matchedTypes) { + $matchedTypes.Add($sensitiveType.Name) + } + } + } + } + + elseif ($rule.IsAdvancedRule -eq $true) { + $advancedRule = [string]$rule.AdvancedRule + foreach ($sensitiveType in $sensitiveTypes) { + if ( + ($advancedRule -match [regex]::Escape($sensitiveType.Name) -or + $advancedRule -match [regex]::Escape($sensitiveType.Id)) -and + $sensitiveType.Name -notin $matchedTypes + ) { + $matchedTypes.Add($sensitiveType.Name) + } + } + } + + if ($matchedTypes.Count -gt 0) { + [pscustomobject]@{ + Policy = $parentPolicy.Policy + Rule = $rule + SensitiveTypes = [string[]]$matchedTypes.ToArray() + } + } + } + + return @($sensitiveRules) +} diff --git a/powershell/tests/fixtures/golden/selection.json b/powershell/tests/fixtures/golden/selection.json index ae970e7cfd..ee2dc93cb9 100644 --- a/powershell/tests/fixtures/golden/selection.json +++ b/powershell/tests/fixtures/golden/selection.json @@ -21,7 +21,7 @@ "AD" ] }, - "SelectedCount": 582, + "SelectedCount": 584, "SelectedFamilies": [ "MT.1024", "MT.1059", @@ -297,15 +297,17 @@ "CISA.MS.EXO.6.1", "CISA.MS.EXO.6.2", "CISA.MS.EXO.7.1", - "CISA.MS.EXO.8.1", - "CISA.MS.EXO.8.2", "CISA.MS.EXO.8.3", - "CISA.MS.EXO.8.4", "CISA.MS.EXO.9.1", "CISA.MS.EXO.9.2", "CISA.MS.EXO.9.3", "CISA.MS.EXO.9.4", "CISA.MS.EXO.9.5", + "CISA.MS.SECURITYSUITE.3.1", + "CISA.MS.SECURITYSUITE.3.2", + "CISA.MS.SECURITYSUITE.3.3", + "CISA.MS.SECURITYSUITE.3.4", + "CISA.MS.SECURITYSUITE.3.5", "CISA.MS.SHAREPOINT.1.1", "CISA.MS.SHAREPOINT.1.2", "CISA.MS.SHAREPOINT.1.3", @@ -771,7 +773,7 @@ "AD" ] }, - "SelectedCount": 538, + "SelectedCount": 540, "SelectedFamilies": [ "MT.1024", "MT.1059", @@ -1047,15 +1049,17 @@ "CISA.MS.EXO.6.1", "CISA.MS.EXO.6.2", "CISA.MS.EXO.7.1", - "CISA.MS.EXO.8.1", - "CISA.MS.EXO.8.2", "CISA.MS.EXO.8.3", - "CISA.MS.EXO.8.4", "CISA.MS.EXO.9.1", "CISA.MS.EXO.9.2", "CISA.MS.EXO.9.3", "CISA.MS.EXO.9.4", "CISA.MS.EXO.9.5", + "CISA.MS.SECURITYSUITE.3.1", + "CISA.MS.SECURITYSUITE.3.2", + "CISA.MS.SECURITYSUITE.3.3", + "CISA.MS.SECURITYSUITE.3.4", + "CISA.MS.SECURITYSUITE.3.5", "CISA.MS.SHAREPOINT.1.1", "CISA.MS.SHAREPOINT.1.2", "CISA.MS.SHAREPOINT.1.3", @@ -1330,7 +1334,7 @@ "AD" ] }, - "SelectedCount": 598, + "SelectedCount": 600, "SelectedFamilies": [ "MT.1024", "MT.1033", @@ -1609,15 +1613,17 @@ "CISA.MS.EXO.6.1", "CISA.MS.EXO.6.2", "CISA.MS.EXO.7.1", - "CISA.MS.EXO.8.1", - "CISA.MS.EXO.8.2", "CISA.MS.EXO.8.3", - "CISA.MS.EXO.8.4", "CISA.MS.EXO.9.1", "CISA.MS.EXO.9.2", "CISA.MS.EXO.9.3", "CISA.MS.EXO.9.4", "CISA.MS.EXO.9.5", + "CISA.MS.SECURITYSUITE.3.1", + "CISA.MS.SECURITYSUITE.3.2", + "CISA.MS.SECURITYSUITE.3.3", + "CISA.MS.SECURITYSUITE.3.4", + "CISA.MS.SECURITYSUITE.3.5", "CISA.MS.SHAREPOINT.1.1", "CISA.MS.SHAREPOINT.1.2", "CISA.MS.SHAREPOINT.1.3", @@ -1951,7 +1957,7 @@ "AD" ] }, - "SelectedCount": 609, + "SelectedCount": 611, "SelectedFamilies": [ "MT.1024", "MT.1059", @@ -2228,15 +2234,17 @@ "CISA.MS.EXO.6.1", "CISA.MS.EXO.6.2", "CISA.MS.EXO.7.1", - "CISA.MS.EXO.8.1", - "CISA.MS.EXO.8.2", "CISA.MS.EXO.8.3", - "CISA.MS.EXO.8.4", "CISA.MS.EXO.9.1", "CISA.MS.EXO.9.2", "CISA.MS.EXO.9.3", "CISA.MS.EXO.9.4", "CISA.MS.EXO.9.5", + "CISA.MS.SECURITYSUITE.3.1", + "CISA.MS.SECURITYSUITE.3.2", + "CISA.MS.SECURITYSUITE.3.3", + "CISA.MS.SECURITYSUITE.3.4", + "CISA.MS.SECURITYSUITE.3.5", "CISA.MS.SHAREPOINT.1.1", "CISA.MS.SHAREPOINT.1.2", "CISA.MS.SHAREPOINT.1.3", @@ -2581,7 +2589,7 @@ "AD" ] }, - "SelectedCount": 639, + "SelectedCount": 641, "SelectedFamilies": [ "MT.1024", "MT.1033", @@ -2861,15 +2869,17 @@ "CISA.MS.EXO.6.1", "CISA.MS.EXO.6.2", "CISA.MS.EXO.7.1", - "CISA.MS.EXO.8.1", - "CISA.MS.EXO.8.2", "CISA.MS.EXO.8.3", - "CISA.MS.EXO.8.4", "CISA.MS.EXO.9.1", "CISA.MS.EXO.9.2", "CISA.MS.EXO.9.3", "CISA.MS.EXO.9.4", "CISA.MS.EXO.9.5", + "CISA.MS.SECURITYSUITE.3.1", + "CISA.MS.SECURITYSUITE.3.2", + "CISA.MS.SECURITYSUITE.3.3", + "CISA.MS.SECURITYSUITE.3.4", + "CISA.MS.SECURITYSUITE.3.5", "CISA.MS.SHAREPOINT.1.1", "CISA.MS.SHAREPOINT.1.2", "CISA.MS.SHAREPOINT.1.3", @@ -3441,7 +3451,7 @@ "AD" ] }, - "SelectedCount": 538, + "SelectedCount": 540, "SelectedFamilies": [ "MT.1024", "MT.1059", @@ -3717,15 +3727,17 @@ "CISA.MS.EXO.6.1", "CISA.MS.EXO.6.2", "CISA.MS.EXO.7.1", - "CISA.MS.EXO.8.1", - "CISA.MS.EXO.8.2", "CISA.MS.EXO.8.3", - "CISA.MS.EXO.8.4", "CISA.MS.EXO.9.1", "CISA.MS.EXO.9.2", "CISA.MS.EXO.9.3", "CISA.MS.EXO.9.4", "CISA.MS.EXO.9.5", + "CISA.MS.SECURITYSUITE.3.1", + "CISA.MS.SECURITYSUITE.3.2", + "CISA.MS.SECURITYSUITE.3.3", + "CISA.MS.SECURITYSUITE.3.4", + "CISA.MS.SECURITYSUITE.3.5", "CISA.MS.SHAREPOINT.1.1", "CISA.MS.SHAREPOINT.1.2", "CISA.MS.SHAREPOINT.1.3", @@ -4006,7 +4018,7 @@ "AD" ] }, - "SelectedCount": 595, + "SelectedCount": 597, "SelectedFamilies": [ "MT.1024", "MT.1033", @@ -4286,15 +4298,17 @@ "CISA.MS.EXO.6.1", "CISA.MS.EXO.6.2", "CISA.MS.EXO.7.1", - "CISA.MS.EXO.8.1", - "CISA.MS.EXO.8.2", "CISA.MS.EXO.8.3", - "CISA.MS.EXO.8.4", "CISA.MS.EXO.9.1", "CISA.MS.EXO.9.2", "CISA.MS.EXO.9.3", "CISA.MS.EXO.9.4", "CISA.MS.EXO.9.5", + "CISA.MS.SECURITYSUITE.3.1", + "CISA.MS.SECURITYSUITE.3.2", + "CISA.MS.SECURITYSUITE.3.3", + "CISA.MS.SECURITYSUITE.3.4", + "CISA.MS.SECURITYSUITE.3.5", "CISA.MS.SHAREPOINT.1.1", "CISA.MS.SHAREPOINT.1.2", "CISA.MS.SHAREPOINT.1.3", diff --git a/powershell/tests/functions/Test-MtCisaSecuritySuitePurview.Tests.ps1 b/powershell/tests/functions/Test-MtCisaSecuritySuitePurview.Tests.ps1 new file mode 100644 index 0000000000..73f5cbc4b6 --- /dev/null +++ b/powershell/tests/functions/Test-MtCisaSecuritySuitePurview.Tests.ps1 @@ -0,0 +1,180 @@ +BeforeAll { + $testRoot = Resolve-Path (Join-Path $PSScriptRoot '../../..') + function Get-TestSensitiveDlpResponse { + $advancedRule = @( + '50842eb7-edc8-4019-85dd-5a5c1f2bb085', + 'a44669fe-0d48-453d-a9b1-2cc83f2cba77', + 'e55e2a32-f92d-4985-a35d-a0b269eb687b' + ) -join ' ' + + @{ + DlpCompliancePolicy = @( + [pscustomobject]@{ + Name = 'Sensitive information'; Identity = 'Sensitive information'; Enabled = $true + Mode = 'Enable' + Workload = @('Exchange', 'OneDriveForBusiness', 'SharePoint', 'Teams', 'EndpointDevices') + ExchangeLocation = @([pscustomobject]@{ DisplayName = 'All' }) + OneDriveLocation = @([pscustomobject]@{ DisplayName = 'All' }) + SharePointLocation = @([pscustomobject]@{ DisplayName = 'All' }) + TeamsLocation = @([pscustomobject]@{ DisplayName = 'All' }) + EndpointDlpLocation = @([pscustomobject]@{ DisplayName = 'All' }) + } + ) + DlpComplianceRule = @( + [pscustomobject]@{ + Name = 'Protect sensitive information'; ParentPolicyName = 'Sensitive information' + Disabled = $false; IsAdvancedRule = $true; Mode = 'Enforce'; AdvancedRule = $advancedRule + ContentContainsSensitiveInformation = @() + BlockAccess = $true; BlockAccessScope = 'All'; NotifyUser = @('user@contoso.com') + } + ) + } + } + + . (Join-Path $testRoot 'powershell/internal/checks/cisa/purview/Get-MtCisaSensitiveDlpRule.ps1') + . (Join-Path $testRoot 'powershell/public/report/Get-MtSafeMarkdown.ps1') + . (Join-Path $testRoot 'tests/cisa/purview/Test.CISA.MS.SECURITYSUITE.3.1.ps1') + . (Join-Path $testRoot 'tests/cisa/purview/Test.CISA.MS.SECURITYSUITE.3.2.ps1') + . (Join-Path $testRoot 'tests/cisa/purview/Test.CISA.MS.SECURITYSUITE.3.3.ps1') + . (Join-Path $testRoot 'tests/cisa/purview/Test.CISA.MS.SECURITYSUITE.3.4.ps1') + . (Join-Path $testRoot 'tests/cisa/purview/Test.CISA.MS.SECURITYSUITE.3.5.ps1') +} + +Describe 'CISA Security Suite Purview checks' { + BeforeEach { + Mock Add-MtTestResultDetail {} + } + It 'checks that sensitive-information DLP policies cover all five workloads' { + $script:exoResponses = Get-TestSensitiveDlpResponse + Mock Get-MtExo { $script:exoResponses[$Request] } + + Test-MtCisaDlpLocationCoverage | Should -BeTrue + + $script:exoResponses.DlpCompliancePolicy[0].TeamsLocation = @() + Test-MtCisaDlpLocationCoverage | Should -BeFalse + } + + It 'recognizes basic DLP sensitive-information types and requires an enabled parent policy' { + $script:exoResponses = Get-TestSensitiveDlpResponse + $script:exoResponses.DlpComplianceRule[0].IsAdvancedRule = $false + $script:exoResponses.DlpComplianceRule[0].ContentContainsSensitiveInformation = @( + [pscustomobject]@{ Name = 'Credit Card Number' } + [pscustomobject]@{ Name = 'U.S. Social Security Number (SSN)' } + [pscustomobject]@{ Name = 'U.S. Individual Taxpayer Identification Number (ITIN)' } + ) + $script:exoResponses.DlpComplianceRule[0].AdvancedRule = $null + Mock Get-MtExo { $script:exoResponses[$Request] } + + Test-MtCisaDlpSensitiveInformation | Should -BeTrue + Test-MtCisaDlpLocationCoverage | Should -BeTrue + Test-MtCisaDlpBlocksSensitiveInformation | Should -BeTrue + Test-MtCisaDlpUserNotification | Should -BeTrue + + $script:exoResponses.DlpComplianceRule[0].ContentContainsSensitiveInformation = @( + $script:exoResponses.DlpComplianceRule[0].ContentContainsSensitiveInformation | Select-Object -First 2 + ) + Test-MtCisaDlpSensitiveInformation | Should -BeFalse + Test-MtCisaDlpLocationCoverage | Should -BeFalse + Test-MtCisaDlpBlocksSensitiveInformation | Should -BeFalse + Test-MtCisaDlpUserNotification | Should -BeFalse + + $script:exoResponses = Get-TestSensitiveDlpResponse + $script:exoResponses.DlpCompliancePolicy[0].Mode = 'Audit' + Test-MtCisaDlpSensitiveInformation | Should -BeFalse + Test-MtCisaDlpLocationCoverage | Should -BeFalse + } + + It 'requires full-protection DLP rules to block access for everyone' { + $script:exoResponses = Get-TestSensitiveDlpResponse + Mock Get-MtExo { $script:exoResponses[$Request] } + + Test-MtCisaDlpBlocksSensitiveInformation | Should -BeTrue + + $script:exoResponses.DlpComplianceRule[0].BlockAccessScope = 'NotInvolved' + Test-MtCisaDlpBlocksSensitiveInformation | Should -BeFalse + } + + It 'requires full-protection DLP rules to notify at least one user' { + $script:exoResponses = Get-TestSensitiveDlpResponse + Mock Get-MtExo { $script:exoResponses[$Request] } + + Test-MtCisaDlpUserNotification | Should -BeTrue + + $script:exoResponses.DlpComplianceRule[0].NotifyUser = @() + Test-MtCisaDlpUserNotification | Should -BeFalse + } + + It 'renders tenant-provided policy and rule names safely' { + $script:exoResponses = Get-TestSensitiveDlpResponse + $script:exoResponses.DlpCompliancePolicy[0].Name = 'Maester lab DLP | $& $$' + $script:exoResponses.DlpCompliancePolicy[0].Identity = 'FFO.extest.microsoft.com/Configuration/Maester lab DLP' + $script:exoResponses.DlpComplianceRule[0].ParentPolicyName = 'Maester lab DLP | $& $$' + $script:exoResponses.DlpComplianceRule[0].Name = 'Maester lab rule | $& $$' + Mock Get-MtExo { $script:exoResponses[$Request] } + + Test-MtCisaDlpSensitiveInformation | Should -BeTrue + Test-MtCisaDlpLocationCoverage | Should -BeTrue + Test-MtCisaDlpBlocksSensitiveInformation | Should -BeTrue + Test-MtCisaDlpUserNotification | Should -BeTrue + + Should -Invoke Add-MtTestResultDetail -Times 4 -Exactly -ParameterFilter { + $Result.Contains('Maester lab DLP \| $& $$') -and + -not $Result.Contains('FFO.extest.microsoft.com') -and + -not $Result.Contains('%TestResult%') + } + Should -Invoke Add-MtTestResultDetail -Times 3 -Exactly -ParameterFilter { + $Result.Contains('Maester lab rule \| $& $$') + } + } + + It 'shows an explicit row when no full-protection rule exists' { + $script:exoResponses = Get-TestSensitiveDlpResponse + $script:exoResponses.DlpComplianceRule = @() + Mock Get-MtExo { $script:exoResponses[$Request] } + + Test-MtCisaDlpBlocksSensitiveInformation | Should -BeFalse + Test-MtCisaDlpUserNotification | Should -BeFalse + + Should -Invoke Add-MtTestResultDetail -Times 2 -Exactly -ParameterFilter { + $Result.Contains('| No matching rules |') + } + } + + It 'returns an investigation result for the manual endpoint DLP requirement' { + Test-MtCisaDlpEndpointRestriction | Should -BeTrue + + Should -Invoke Add-MtTestResultDetail -Times 1 -Exactly -ParameterFilter { $Investigate } + } + + It 'aggregates types across rules only under enabled parent policies' { + $script:exoResponses = Get-TestSensitiveDlpResponse + $script:exoResponses.DlpComplianceRule = @( + [pscustomobject]@{ + Name = 'Credit card'; ParentPolicyName = 'Sensitive information'; Disabled = $false + IsAdvancedRule = $true; AdvancedRule = '50842eb7-edc8-4019-85dd-5a5c1f2bb085' + } + [pscustomobject]@{ + Name = 'SSN'; ParentPolicyName = 'Sensitive information'; Disabled = $false + IsAdvancedRule = $true; AdvancedRule = 'a44669fe-0d48-453d-a9b1-2cc83f2cba77' + } + [pscustomobject]@{ + Name = 'Unrelated ITIN'; ParentPolicyName = 'Other policy'; Disabled = $false + IsAdvancedRule = $true; AdvancedRule = 'e55e2a32-f92d-4985-a35d-a0b269eb687b' + } + ) + Mock Get-MtExo { $script:exoResponses[$Request] } + + Test-MtCisaDlpSensitiveInformation | Should -BeFalse + + $script:exoResponses.DlpComplianceRule[2].ParentPolicyName = 'Sensitive information' + Test-MtCisaDlpSensitiveInformation | Should -BeTrue + + $script:exoResponses.DlpComplianceRule[1].Disabled = $true + Test-MtCisaDlpSensitiveInformation | Should -BeFalse + + $script:exoResponses.DlpComplianceRule[1].Disabled = $false + + $script:exoResponses.DlpCompliancePolicy[0].Mode = 'Audit' + Test-MtCisaDlpSensitiveInformation | Should -BeFalse + } +} diff --git a/powershell/tests/functions/engine/ArgumentCompletion.Tests.ps1 b/powershell/tests/functions/engine/ArgumentCompletion.Tests.ps1 index 1cf7e33125..5460a5b0ab 100644 --- a/powershell/tests/functions/engine/ArgumentCompletion.Tests.ps1 +++ b/powershell/tests/functions/engine/ArgumentCompletion.Tests.ps1 @@ -103,7 +103,9 @@ Describe 'Tab completion' { } It 'lists only the values that still select a test' { - Get-CompletionText 'Invoke-Maester -Suite CISA -Severity ' | Should -Not -Contain 'Info' + $offered = Get-CompletionText 'Invoke-Maester -Suite CISA -Severity ' + $offered | Should -Contain 'Info' + $offered | Should -Not -Contain 'Critical' } It 'lists the suites of the built-in tests' { diff --git a/powershell/tests/functions/engine/Frameworks.Tests.ps1 b/powershell/tests/functions/engine/Frameworks.Tests.ps1 index 06a6372fd8..95dfcc5023 100644 --- a/powershell/tests/functions/engine/Frameworks.Tests.ps1 +++ b/powershell/tests/functions/engine/Frameworks.Tests.ps1 @@ -336,7 +336,7 @@ Describe 'Benchmark of the tests shipped with Maester' { It 'Gives every test a Benchmark of