diff --git a/build/golden/Export-MtLegacyIdTable.ps1 b/build/golden/Export-MtLegacyIdTable.ps1 index e5a8d8ea9e..8e88bb850d 100644 --- a/build/golden/Export-MtLegacyIdTable.ps1 +++ b/build/golden/Export-MtLegacyIdTable.ps1 @@ -3,9 +3,9 @@ Generates the Maester previous-ID table (Maester.LegacyIds.json) from the git history of tests/. .DESCRIPTION - Walks every commit that touched a *.Tests.ps1 file under tests/ (tests/Custom excluded), parses the - It names of every changed file version with the PowerShell AST (regex fallback for files that do - not parse) and records every static test ID that ever shipped. + Walks every commit that touched a *.Tests.ps1 or Test.*.ps1 file under tests/ (tests/Custom excluded), + parses the It names of every changed Pester file version with the PowerShell AST (regex fallback for + files that do not parse) and records every static test ID that ever shipped. The ID of an It name is the text before the first colon when that text has no spaces (for example 'MT.1001' or 'MS.AAD.7.1'). Early wrappers had no ID; for those the whole It name is @@ -19,9 +19,12 @@ 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. + Previously verified mappings from the generated-from commit are retained while their targets remain + current, unless a manual override applies. This preserves aliases when native titles or functions change. + + The output is deterministic: GeneratedFrom is the last commit that touched either test format, and + current Pester and native IDs are read from that commit's tree, so rerunning on a later commit that + does not touch tests/ produces identical output. .EXAMPLE ./build/golden/Export-MtLegacyIdTable.ps1 @@ -55,6 +58,14 @@ $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.MS.EXO.11.1' = 'CISA.MS.SECURITYSUITE.2.1' + 'CISA.MS.EXO.11.2' = 'CISA.MS.SECURITYSUITE.2.4' + 'CISA.MS.EXO.16.1' = 'CISA.MS.SECURITYSUITE.4.1' + 'CISA.MS.EXO.16.2' = 'CISA.MS.SECURITYSUITE.4.2' + 'MS.EXO.11.1' = 'CISA.MS.SECURITYSUITE.2.1' + 'MS.EXO.11.2' = 'CISA.MS.SECURITYSUITE.2.4' + 'MS.EXO.16.1' = 'CISA.MS.SECURITYSUITE.4.1' + 'MS.EXO.16.2' = 'CISA.MS.SECURITYSUITE.4.2' # 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' @@ -80,7 +91,11 @@ $PrefixRenames = @( # Commands that are not check functions. $IgnoredFunctions = @('Test-Path', 'Test-Json', 'Test-Connection', 'Test-NetConnection', 'Test-MtConnection', 'Test-MtContext') -$testPathSpec = @(':(glob,icase)tests/**/*.tests.ps1', ':(exclude,glob,icase)tests/Custom/**') +$testPathSpec = @( + ':(glob,icase)tests/**/*.tests.ps1' + ':(glob,icase)tests/**/Test.*.ps1' + ':(exclude,glob,icase)tests/Custom/**' +) function Invoke-Git { # Arguments are passed through $args so git switches such as -p are not bound as PowerShell parameters. @@ -197,8 +212,8 @@ foreach ($line in $logLines) { if ($line -match '^commit ([0-9a-f]{40})$') { $current = [pscustomobject]@{ Sha = $Matches[1]; Files = [System.Collections.Generic.List[object]]::new() } $commits.Add($current) - } elseif ($line -match '^:\d+ \d+ [0-9a-f]+ ([0-9a-f]{40}) ([AMT])\t(.+)$') { - $current.Files.Add([pscustomobject]@{ Blob = $Matches[1]; Path = $Matches[3] }) + } elseif ($line -match '^:\d+ \d+ [0-9a-f]{40} ([0-9a-f]{40}) ([AMTD])\t(.+)$') { + $current.Files.Add([pscustomobject]@{ Blob = $Matches[1]; Status = $Matches[2]; Path = $Matches[3] }) } } $commits = @($commits | Where-Object { $_.Files.Count -gt 0 }) @@ -221,6 +236,7 @@ $history = [System.Collections.Generic.Dictionary[string, object]]::new([System. $historicalFamilies = [System.Collections.Generic.SortedSet[string]]::new([System.StringComparer]::Ordinal) foreach ($commit in $commits) { foreach ($file in $commit.Files) { + if ($file.Status -eq 'D' -or $file.Path -notmatch '(?i)\.tests\.ps1$') { continue } foreach ($it in (Get-BlobItInfo -Blob $file.Blob)) { $split = Get-StaticSplit -Name $it.Name if (-not $split) { @@ -247,21 +263,67 @@ foreach ($commit in $commits) { #region Current IDs (from the tree of $generatedFrom) $currentIds = [System.Collections.Generic.Dictionary[string, object]]::new([System.StringComparer]::OrdinalIgnoreCase) $familyPrefixes = [System.Collections.Generic.SortedSet[string]]::new([System.StringComparer]::Ordinal) +$nativeIds = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase) +$nativeRecords = [System.Collections.Generic.List[object]]::new() $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 } + if ($line -notmatch '^\d+ blob ([0-9a-f]{40})\t(tests/.+)$') { continue } + $blob = $Matches[1] $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 + if ($path -like 'tests/Custom/*') { continue } + + if ($path -match '(?i)\.tests\.ps1$') { + foreach ($it in (Get-BlobItInfo -Blob $blob)) { + $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 } + + if ($path -notmatch '(?i)(?:^|/)Test\.(?.+)\.ps1$') { continue } + $nativeId = $Matches.id + $null = $nativeIds.Add($nativeId) + $content = (Invoke-Git cat-file -p $blob) -join "`n" + $tokens = $null + $parseErrors = $null + $ast = [System.Management.Automation.Language.Parser]::ParseInput($content, [ref] $tokens, [ref] $parseErrors) + if ($parseErrors.Count -gt 0) { continue } + $nativeFunction = $ast.EndBlock.Statements | + Where-Object { + $_ -is [System.Management.Automation.Language.FunctionDefinitionAst] -and + $_.Body.ParamBlock -and + ($_.Body.ParamBlock.Attributes | Where-Object { $_.TypeName.Name -in 'MaesterTest', 'MaesterTestAttribute' }) + } | + Select-Object -First 1 + if (-not $nativeFunction) { continue } + + $attribute = $nativeFunction.Body.ParamBlock.Attributes | + Where-Object { $_.TypeName.Name -in 'MaesterTest', 'MaesterTestAttribute' } | + Select-Object -First 1 + if ($attribute.NamedArguments.ArgumentName -contains 'InstanceSource') { $null = $familyPrefixes.Add("$nativeId.") } + $titleArgument = $attribute.NamedArguments | Where-Object { $_.ArgumentName -eq 'Title' } | Select-Object -First 1 + $title = '' + if ($titleArgument.Argument -is [System.Management.Automation.Language.StringConstantExpressionAst]) { + $title = Get-NormalizedTitle -Title $titleArgument.Argument.Value + } + $nativeRecords.Add([pscustomobject]@{ Id = $nativeId; Title = $title; Function = $nativeFunction.Name }) } -Write-Verbose "Current static IDs: $($currentIds.Count); family prefixes: $($familyPrefixes -join ', ')" +foreach ($historicalPrefix in $historicalFamilies) { + if ($familyPrefixes.Contains($historicalPrefix)) { continue } + foreach ($rename in $PrefixRenames) { + if (-not $historicalPrefix.StartsWith($rename.Old, [System.StringComparison]::OrdinalIgnoreCase)) { continue } + $renamedPrefix = $rename.New + $historicalPrefix.Substring($rename.Old.Length) + if ($familyPrefixes.Contains($renamedPrefix)) { + $null = $familyPrefixes.Add($historicalPrefix) + break + } + } +} +Write-Verbose "Current static IDs: $($currentIds.Count); native IDs: $($nativeIds.Count); family prefixes: $($familyPrefixes -join ', ')" $titleIndex = @{} $functionIndex = @{} @@ -274,13 +336,32 @@ foreach ($c in $currentIds.Values) { $null = $functionIndex[$f].Add($c.Id) } } +foreach ($native in $nativeRecords) { + if ($native.Title) { + if (-not $titleIndex.ContainsKey($native.Title)) { $titleIndex[$native.Title] = [System.Collections.Generic.SortedSet[string]]::new([System.StringComparer]::Ordinal) } + $null = $titleIndex[$native.Title].Add($native.Id) + } + if ($native.Function) { + if (-not $functionIndex.ContainsKey($native.Function)) { $functionIndex[$native.Function] = [System.Collections.Generic.SortedSet[string]]::new([System.StringComparer]::Ordinal) } + $null = $functionIndex[$native.Function].Add($native.Id) + } +} #endregion Current IDs +# Keep verified aliases stable when native titles change or introduce additional matching candidates. +$previousTable = ((Invoke-Git show "$($generatedFrom):powershell/assets/Maester.LegacyIds.json") -join "`n") | ConvertFrom-Json +$verifiedMappings = @{} +foreach ($entry in $previousTable.Entries) { + if ($currentIds.ContainsKey($entry.CurrentId) -or $nativeIds.Contains($entry.CurrentId)) { + $verifiedMappings[$entry.LegacyId] = $entry + } +} + #region Map $entries = [System.Collections.Generic.List[object]]::new() $review = [System.Collections.Generic.List[string]]::new() foreach ($record in $history.Values) { - if ($currentIds.ContainsKey($record.Id)) { continue } + if ($currentIds.ContainsKey($record.Id) -or $nativeIds.Contains($record.Id)) { continue } if ($record.Id -in $GenericIds) { continue } $titleCandidates = [System.Collections.Generic.SortedSet[string]]::new() @@ -294,14 +375,25 @@ foreach ($record in $history.Values) { foreach ($rename in $PrefixRenames) { if ($record.Id.StartsWith($rename.Old, [System.StringComparison]::OrdinalIgnoreCase)) { $target = $rename.New + $record.Id.Substring($rename.Old.Length) - if ($currentIds.ContainsKey($target)) { $prefixTarget = $currentIds[$target].Id; break } + if ($currentIds.ContainsKey($target)) { + $prefixTarget = $currentIds[$target].Id + break + } elseif ($nativeIds.Contains($target)) { + $prefixTarget = $target + break + } } } $currentId = 'retired'; $rule = 'retired' if ($ManualOverrides.Contains($record.Id)) { $currentId = $ManualOverrides[$record.Id]; $rule = 'manual' - } elseif ($prefixTarget) { + } + elseif ($verifiedMappings.ContainsKey($record.Id)) { + $currentId = $verifiedMappings[$record.Id].CurrentId + $rule = $verifiedMappings[$record.Id].Rule + } + elseif ($prefixTarget) { $currentId = $prefixTarget; $rule = 'prefix' } elseif ($titleCandidates.Count -eq 1) { $currentId = @($titleCandidates)[0]; $rule = 'title' @@ -323,7 +415,7 @@ foreach ($record in $history.Values) { $review.Add("AMBIGUOUS $($record.Id): function -> $($functionCandidates -join '|')") } - if ($currentId -ne 'retired' -and -not $currentIds.ContainsKey($currentId)) { + if ($currentId -ne 'retired' -and -not ($currentIds.ContainsKey($currentId) -or $nativeIds.Contains($currentId))) { throw "Mapping for '$($record.Id)' targets '$currentId', which is not a current ID." } $entries.Add([ordered]@{ diff --git a/build/golden/Export-MtLegacyTagTable.ps1 b/build/golden/Export-MtLegacyTagTable.ps1 index 33da8e4eff..771ce2a605 100644 --- a/build/golden/Export-MtLegacyTagTable.ps1 +++ b/build/golden/Export-MtLegacyTagTable.ps1 @@ -52,6 +52,10 @@ $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.11.1' = 'CISA.MS.SECURITYSUITE.2.1' + 'CISA.MS.EXO.11.2' = 'CISA.MS.SECURITYSUITE.2.4' + 'CISA.MS.EXO.16.1' = 'CISA.MS.SECURITYSUITE.4.1' + 'CISA.MS.EXO.16.2' = 'CISA.MS.SECURITYSUITE.4.2' } # The typed selector that takes the place of a tag. Only tags with an obvious one are listed. diff --git a/powershell/assets/Maester.LegacyIds.json b/powershell/assets/Maester.LegacyIds.json index d0681e44a6..85e7ba1889 100644 --- a/powershell/assets/Maester.LegacyIds.json +++ b/powershell/assets/Maester.LegacyIds.json @@ -1,6 +1,6 @@ { "SchemaVersion": "1.0", - "GeneratedFrom": "fc6a9078bcdd59b5b2f788682fdcd2be27e15b9c", + "GeneratedFrom": "a64e82a9516fb0f556ec4abb17dcb05cb536878a", "Entries": [ { "LegacyId": "1.1.1 (L1) Ensure Administrative accounts are cloud-only", @@ -1130,6 +1130,38 @@ "LastSeenCommit": "5810a0dc37538fe0c4884f55938f23f5c7d1d6cc", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaBlockExecutable.Tests.ps1" }, + { + "LegacyId": "CISA.MS.EXO.11.1", + "CurrentId": "CISA.MS.SECURITYSUITE.2.1", + "Rule": "manual", + "FirstSeenCommit": "d176a815b8cfef203cfe0672af5bc092385f05b9", + "LastSeenCommit": "eb38f4357cdf3576600aeca7d8da3138f77a37ca", + "LastSeenFile": "tests/cisa/exchange/Test-MtCisaImpersonation.Tests.ps1" + }, + { + "LegacyId": "CISA.MS.EXO.11.2", + "CurrentId": "CISA.MS.SECURITYSUITE.2.4", + "Rule": "manual", + "FirstSeenCommit": "d176a815b8cfef203cfe0672af5bc092385f05b9", + "LastSeenCommit": "eb38f4357cdf3576600aeca7d8da3138f77a37ca", + "LastSeenFile": "tests/cisa/exchange/Test-MtCisaImpersonationTip.Tests.ps1" + }, + { + "LegacyId": "CISA.MS.EXO.16.1", + "CurrentId": "CISA.MS.SECURITYSUITE.4.1", + "Rule": "manual", + "FirstSeenCommit": "d176a815b8cfef203cfe0672af5bc092385f05b9", + "LastSeenCommit": "eb38f4357cdf3576600aeca7d8da3138f77a37ca", + "LastSeenFile": "tests/cisa/exchange/Test-MtCisaExoAlert.Tests.ps1" + }, + { + "LegacyId": "CISA.MS.EXO.16.2", + "CurrentId": "CISA.MS.SECURITYSUITE.4.2", + "Rule": "manual", + "FirstSeenCommit": "d176a815b8cfef203cfe0672af5bc092385f05b9", + "LastSeenCommit": "eb38f4357cdf3576600aeca7d8da3138f77a37ca", + "LastSeenFile": "tests/cisa/exchange/Test-MtCisaExoAlertSiem.Tests.ps1" + }, { "LegacyId": "Configure which users are allowed to present in Teams meetings", "CurrentId": "retired", @@ -1868,16 +1900,16 @@ }, { "LegacyId": "MS.EXO.11.1", - "CurrentId": "CISA.MS.EXO.11.1", - "Rule": "prefix", + "CurrentId": "CISA.MS.SECURITYSUITE.2.1", + "Rule": "manual", "FirstSeenCommit": "73e139b26d340765f4cfc202847ea009479da2ac", "LastSeenCommit": "73e139b26d340765f4cfc202847ea009479da2ac", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaImpersonation.Tests.ps1" }, { "LegacyId": "MS.EXO.11.2", - "CurrentId": "CISA.MS.EXO.11.2", - "Rule": "prefix", + "CurrentId": "CISA.MS.SECURITYSUITE.2.4", + "Rule": "manual", "FirstSeenCommit": "73e139b26d340765f4cfc202847ea009479da2ac", "LastSeenCommit": "73e139b26d340765f4cfc202847ea009479da2ac", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaImpersonationTip.Tests.ps1" @@ -1972,16 +2004,16 @@ }, { "LegacyId": "MS.EXO.16.1", - "CurrentId": "CISA.MS.EXO.16.1", - "Rule": "prefix", + "CurrentId": "CISA.MS.SECURITYSUITE.4.1", + "Rule": "manual", "FirstSeenCommit": "4af5fc2c7df1f755e933cba0042069793d47121a", "LastSeenCommit": "4af5fc2c7df1f755e933cba0042069793d47121a", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaExoAlert.Tests.ps1" }, { "LegacyId": "MS.EXO.16.2", - "CurrentId": "CISA.MS.EXO.16.2", - "Rule": "prefix", + "CurrentId": "CISA.MS.SECURITYSUITE.4.2", + "Rule": "manual", "FirstSeenCommit": "4af5fc2c7df1f755e933cba0042069793d47121a", "LastSeenCommit": "4af5fc2c7df1f755e933cba0042069793d47121a", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaExoAlertSiem.Tests.ps1" @@ -3128,6 +3160,7 @@ "MT.1033.", "MT.1034.", "MT.1059.", + "MT.1060.", "MT1060." ] } diff --git a/powershell/assets/Maester.LegacyTags.json b/powershell/assets/Maester.LegacyTags.json index 2ba8db3c4b..794f38c773 100644 --- a/powershell/assets/Maester.LegacyTags.json +++ b/powershell/assets/Maester.LegacyTags.json @@ -1164,8 +1164,6 @@ "CISA.MS.EXO.10.1", "CISA.MS.EXO.10.2", "CISA.MS.EXO.10.3", - "CISA.MS.EXO.11.1", - "CISA.MS.EXO.11.2", "CISA.MS.EXO.11.3", "CISA.MS.EXO.12.1", "CISA.MS.EXO.12.2", @@ -1177,8 +1175,6 @@ "CISA.MS.EXO.15.1", "CISA.MS.EXO.15.2", "CISA.MS.EXO.15.3", - "CISA.MS.EXO.16.1", - "CISA.MS.EXO.16.2", "CISA.MS.EXO.17.1", "CISA.MS.EXO.17.2", "CISA.MS.EXO.17.3", @@ -1201,6 +1197,10 @@ "CISA.MS.EXO.9.3", "CISA.MS.EXO.9.4", "CISA.MS.EXO.9.5", + "CISA.MS.SECURITYSUITE.2.1", + "CISA.MS.SECURITYSUITE.2.4", + "CISA.MS.SECURITYSUITE.4.1", + "CISA.MS.SECURITYSUITE.4.2", "CISA.MS.SHAREPOINT.1.1", "CISA.MS.SHAREPOINT.1.2", "CISA.MS.SHAREPOINT.1.3", @@ -1211,6 +1211,30 @@ "CISA.MS.SHAREPOINT.3.3" ] }, + { + "Tag": "CISA.MS.EXO.11.1", + "Tests": [ + "CISA.MS.SECURITYSUITE.2.1" + ] + }, + { + "Tag": "CISA.MS.EXO.11.2", + "Tests": [ + "CISA.MS.SECURITYSUITE.2.4" + ] + }, + { + "Tag": "CISA.MS.EXO.16.1", + "Tests": [ + "CISA.MS.SECURITYSUITE.4.1" + ] + }, + { + "Tag": "CISA.MS.EXO.16.2", + "Tests": [ + "CISA.MS.SECURITYSUITE.4.2" + ] + }, { "Tag": "CopilotStudio", "Replacement": "-Product copilot-studio", @@ -2155,8 +2179,6 @@ "CISA.MS.EXO.10.1", "CISA.MS.EXO.10.2", "CISA.MS.EXO.10.3", - "CISA.MS.EXO.11.1", - "CISA.MS.EXO.11.2", "CISA.MS.EXO.11.3", "CISA.MS.EXO.12.1", "CISA.MS.EXO.12.2", @@ -2168,8 +2190,6 @@ "CISA.MS.EXO.15.1", "CISA.MS.EXO.15.2", "CISA.MS.EXO.15.3", - "CISA.MS.EXO.16.1", - "CISA.MS.EXO.16.2", "CISA.MS.EXO.17.1", "CISA.MS.EXO.17.2", "CISA.MS.EXO.17.3", @@ -2191,7 +2211,11 @@ "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.2.1", + "CISA.MS.SECURITYSUITE.2.4", + "CISA.MS.SECURITYSUITE.4.1", + "CISA.MS.SECURITYSUITE.4.2" ] }, { @@ -2221,13 +2245,13 @@ { "Tag": "MS.EXO.11.1", "Tests": [ - "CISA.MS.EXO.11.1" + "CISA.MS.SECURITYSUITE.2.1" ] }, { "Tag": "MS.EXO.11.2", "Tests": [ - "CISA.MS.EXO.11.2" + "CISA.MS.SECURITYSUITE.2.4" ] }, { @@ -2299,13 +2323,13 @@ { "Tag": "MS.EXO.16.1", "Tests": [ - "CISA.MS.EXO.16.1" + "CISA.MS.SECURITYSUITE.4.1" ] }, { "Tag": "MS.EXO.16.2", "Tests": [ - "CISA.MS.EXO.16.2" + "CISA.MS.SECURITYSUITE.4.2" ] }, { diff --git a/powershell/internal/checks/cisa/exchange/Get-MtCisaEffectiveAntiPhishPolicy.ps1 b/powershell/internal/checks/cisa/exchange/Get-MtCisaEffectiveAntiPhishPolicy.ps1 new file mode 100644 index 0000000000..b09d0f7d64 --- /dev/null +++ b/powershell/internal/checks/cisa/exchange/Get-MtCisaEffectiveAntiPhishPolicy.ps1 @@ -0,0 +1,96 @@ +function Get-MtCisaEffectiveAntiPhishPolicy { + <# + .SYNOPSIS + Gets enabled anti-phishing policies that effectively cover all tenant recipients. + + .DESCRIPTION + Returns policies whose recipient rules cover every accepted domain without recipient exclusions. + Impersonation checks also require the matching Defender preset rule to cover all recipients. + + .PARAMETER RequireDefenderProtection + Requires tenant-wide Defender protection in addition to EOP coverage for preset policies. + #> + [CmdletBinding()] + [OutputType([object[]])] + param( + [switch] $RequireDefenderProtection + ) + + $policies = @(Get-MtExo -Request AntiPhishPolicy) + $antiPhishRules = @(Get-MtExo -Request AntiPhishRule) + $presetRules = @(Get-MtExo -Request EOPProtectionPolicyRule) + $defenderPresetRules = if ($RequireDefenderProtection) { + @(Get-MtExo -Request ATPProtectionPolicyRule) + } + $tenantDomains = @( + Get-MtExo -Request AcceptedDomain | + ForEach-Object { + $domain = if ($_.DomainName) { $_.DomainName } else { $_.Name } + ([string]$domain).Trim().ToLowerInvariant() + } | + Where-Object { -not [string]::IsNullOrWhiteSpace($_) } + ) + if ($tenantDomains.Count -eq 0) { return @() } + + $isEmpty = { + param($Value) + $null -eq $Value -or + ($Value -is [string] -and [string]::IsNullOrWhiteSpace($Value)) -or + @($Value).Count -eq 0 + } + + $coversAllTenantDomains = { + param($Rule) + foreach ($field in @('SentTo', 'SentToMemberOf', 'ExceptIfSentTo', 'ExceptIfSentToMemberOf', 'ExceptIfRecipientDomainIs')) { + if (-not (& $isEmpty $Rule.$field)) { + return $false + } + } + + if (& $isEmpty $Rule.RecipientDomainIs) { + return $tenantDomains.Count -gt 0 + } + + $recipientDomains = @($Rule.RecipientDomainIs | ForEach-Object { ([string]$_).Trim().ToLowerInvariant() }) + $tenantDomains.Count -gt 0 -and @($tenantDomains | Where-Object { $_ -notin $recipientDomains }).Count -eq 0 + } + + $effectivePolicies = foreach ($policy in $policies | Where-Object { $_.Enabled -eq $true }) { + $coversAllRecipients = $policy.IsDefault -eq $true + + if (-not $coversAllRecipients -and $policy.Identity -match '(?i)(Standard|Strict) Preset Security Policy') { + $coversAllRecipients = @( + $presetRules | Where-Object { + $_.State -eq 'Enabled' -and + $_.Identity -match [regex]::Escape($policy.RecommendedPolicyType) -and + (& $coversAllTenantDomains $_) + } + ).Count -gt 0 + if ($coversAllRecipients -and $RequireDefenderProtection) { + $coversAllRecipients = @( + $defenderPresetRules | Where-Object { + $_.State -eq 'Enabled' -and + $_.Identity -match [regex]::Escape($policy.RecommendedPolicyType) -and + (& $coversAllTenantDomains $_) + } + ).Count -gt 0 + } + } + elseif (-not $coversAllRecipients) { + $policyRules = @( + $antiPhishRules | Where-Object { + $_.State -eq 'Enabled' -and + ($_.AntiPhishPolicy -eq $policy.Name -or $_.AntiPhishPolicy -eq $policy.Identity) -and + (& $coversAllTenantDomains $_) + } + ) + $coversAllRecipients = $tenantDomains.Count -gt 0 -and $policyRules.Count -gt 0 + } + + if ($coversAllRecipients) { + $policy + } + } + + return @($effectivePolicies) +} diff --git a/powershell/tests/fixtures/golden/selection.json b/powershell/tests/fixtures/golden/selection.json index ae970e7cfd..1e416ff7f9 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", @@ -269,8 +269,6 @@ "CISA.MS.EXO.10.1", "CISA.MS.EXO.10.2", "CISA.MS.EXO.10.3", - "CISA.MS.EXO.11.1", - "CISA.MS.EXO.11.2", "CISA.MS.EXO.11.3", "CISA.MS.EXO.12.1", "CISA.MS.EXO.12.2", @@ -282,8 +280,6 @@ "CISA.MS.EXO.15.1", "CISA.MS.EXO.15.2", "CISA.MS.EXO.15.3", - "CISA.MS.EXO.16.1", - "CISA.MS.EXO.16.2", "CISA.MS.EXO.17.1", "CISA.MS.EXO.17.2", "CISA.MS.EXO.17.3", @@ -306,6 +302,12 @@ "CISA.MS.EXO.9.3", "CISA.MS.EXO.9.4", "CISA.MS.EXO.9.5", + "CISA.MS.SECURITYSUITE.2.1", + "CISA.MS.SECURITYSUITE.2.2", + "CISA.MS.SECURITYSUITE.2.3", + "CISA.MS.SECURITYSUITE.2.4", + "CISA.MS.SECURITYSUITE.4.1", + "CISA.MS.SECURITYSUITE.4.2", "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", @@ -1019,8 +1021,6 @@ "CISA.MS.EXO.10.1", "CISA.MS.EXO.10.2", "CISA.MS.EXO.10.3", - "CISA.MS.EXO.11.1", - "CISA.MS.EXO.11.2", "CISA.MS.EXO.11.3", "CISA.MS.EXO.12.1", "CISA.MS.EXO.12.2", @@ -1032,8 +1032,6 @@ "CISA.MS.EXO.15.1", "CISA.MS.EXO.15.2", "CISA.MS.EXO.15.3", - "CISA.MS.EXO.16.1", - "CISA.MS.EXO.16.2", "CISA.MS.EXO.17.1", "CISA.MS.EXO.17.2", "CISA.MS.EXO.17.3", @@ -1056,6 +1054,12 @@ "CISA.MS.EXO.9.3", "CISA.MS.EXO.9.4", "CISA.MS.EXO.9.5", + "CISA.MS.SECURITYSUITE.2.1", + "CISA.MS.SECURITYSUITE.2.2", + "CISA.MS.SECURITYSUITE.2.3", + "CISA.MS.SECURITYSUITE.2.4", + "CISA.MS.SECURITYSUITE.4.1", + "CISA.MS.SECURITYSUITE.4.2", "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", @@ -1581,8 +1585,6 @@ "CISA.MS.EXO.10.1", "CISA.MS.EXO.10.2", "CISA.MS.EXO.10.3", - "CISA.MS.EXO.11.1", - "CISA.MS.EXO.11.2", "CISA.MS.EXO.11.3", "CISA.MS.EXO.12.1", "CISA.MS.EXO.12.2", @@ -1594,8 +1596,6 @@ "CISA.MS.EXO.15.1", "CISA.MS.EXO.15.2", "CISA.MS.EXO.15.3", - "CISA.MS.EXO.16.1", - "CISA.MS.EXO.16.2", "CISA.MS.EXO.17.1", "CISA.MS.EXO.17.2", "CISA.MS.EXO.17.3", @@ -1618,6 +1618,12 @@ "CISA.MS.EXO.9.3", "CISA.MS.EXO.9.4", "CISA.MS.EXO.9.5", + "CISA.MS.SECURITYSUITE.2.1", + "CISA.MS.SECURITYSUITE.2.2", + "CISA.MS.SECURITYSUITE.2.3", + "CISA.MS.SECURITYSUITE.2.4", + "CISA.MS.SECURITYSUITE.4.1", + "CISA.MS.SECURITYSUITE.4.2", "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", @@ -2200,8 +2206,6 @@ "CISA.MS.EXO.10.1", "CISA.MS.EXO.10.2", "CISA.MS.EXO.10.3", - "CISA.MS.EXO.11.1", - "CISA.MS.EXO.11.2", "CISA.MS.EXO.11.3", "CISA.MS.EXO.12.1", "CISA.MS.EXO.12.2", @@ -2213,8 +2217,6 @@ "CISA.MS.EXO.15.1", "CISA.MS.EXO.15.2", "CISA.MS.EXO.15.3", - "CISA.MS.EXO.16.1", - "CISA.MS.EXO.16.2", "CISA.MS.EXO.17.1", "CISA.MS.EXO.17.2", "CISA.MS.EXO.17.3", @@ -2237,6 +2239,12 @@ "CISA.MS.EXO.9.3", "CISA.MS.EXO.9.4", "CISA.MS.EXO.9.5", + "CISA.MS.SECURITYSUITE.2.1", + "CISA.MS.SECURITYSUITE.2.2", + "CISA.MS.SECURITYSUITE.2.3", + "CISA.MS.SECURITYSUITE.2.4", + "CISA.MS.SECURITYSUITE.4.1", + "CISA.MS.SECURITYSUITE.4.2", "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", @@ -2833,8 +2841,6 @@ "CISA.MS.EXO.10.1", "CISA.MS.EXO.10.2", "CISA.MS.EXO.10.3", - "CISA.MS.EXO.11.1", - "CISA.MS.EXO.11.2", "CISA.MS.EXO.11.3", "CISA.MS.EXO.12.1", "CISA.MS.EXO.12.2", @@ -2846,8 +2852,6 @@ "CISA.MS.EXO.15.1", "CISA.MS.EXO.15.2", "CISA.MS.EXO.15.3", - "CISA.MS.EXO.16.1", - "CISA.MS.EXO.16.2", "CISA.MS.EXO.17.1", "CISA.MS.EXO.17.2", "CISA.MS.EXO.17.3", @@ -2870,6 +2874,12 @@ "CISA.MS.EXO.9.3", "CISA.MS.EXO.9.4", "CISA.MS.EXO.9.5", + "CISA.MS.SECURITYSUITE.2.1", + "CISA.MS.SECURITYSUITE.2.2", + "CISA.MS.SECURITYSUITE.2.3", + "CISA.MS.SECURITYSUITE.2.4", + "CISA.MS.SECURITYSUITE.4.1", + "CISA.MS.SECURITYSUITE.4.2", "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", @@ -3689,8 +3699,6 @@ "CISA.MS.EXO.10.1", "CISA.MS.EXO.10.2", "CISA.MS.EXO.10.3", - "CISA.MS.EXO.11.1", - "CISA.MS.EXO.11.2", "CISA.MS.EXO.11.3", "CISA.MS.EXO.12.1", "CISA.MS.EXO.12.2", @@ -3702,8 +3710,6 @@ "CISA.MS.EXO.15.1", "CISA.MS.EXO.15.2", "CISA.MS.EXO.15.3", - "CISA.MS.EXO.16.1", - "CISA.MS.EXO.16.2", "CISA.MS.EXO.17.1", "CISA.MS.EXO.17.2", "CISA.MS.EXO.17.3", @@ -3726,6 +3732,12 @@ "CISA.MS.EXO.9.3", "CISA.MS.EXO.9.4", "CISA.MS.EXO.9.5", + "CISA.MS.SECURITYSUITE.2.1", + "CISA.MS.SECURITYSUITE.2.2", + "CISA.MS.SECURITYSUITE.2.3", + "CISA.MS.SECURITYSUITE.2.4", + "CISA.MS.SECURITYSUITE.4.1", + "CISA.MS.SECURITYSUITE.4.2", "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", @@ -4258,8 +4270,6 @@ "CISA.MS.EXO.10.1", "CISA.MS.EXO.10.2", "CISA.MS.EXO.10.3", - "CISA.MS.EXO.11.1", - "CISA.MS.EXO.11.2", "CISA.MS.EXO.11.3", "CISA.MS.EXO.12.1", "CISA.MS.EXO.12.2", @@ -4271,8 +4281,6 @@ "CISA.MS.EXO.15.1", "CISA.MS.EXO.15.2", "CISA.MS.EXO.15.3", - "CISA.MS.EXO.16.1", - "CISA.MS.EXO.16.2", "CISA.MS.EXO.17.1", "CISA.MS.EXO.17.2", "CISA.MS.EXO.17.3", @@ -4295,6 +4303,12 @@ "CISA.MS.EXO.9.3", "CISA.MS.EXO.9.4", "CISA.MS.EXO.9.5", + "CISA.MS.SECURITYSUITE.2.1", + "CISA.MS.SECURITYSUITE.2.2", + "CISA.MS.SECURITYSUITE.2.3", + "CISA.MS.SECURITYSUITE.2.4", + "CISA.MS.SECURITYSUITE.4.1", + "CISA.MS.SECURITYSUITE.4.2", "CISA.MS.SHAREPOINT.1.1", "CISA.MS.SHAREPOINT.1.2", "CISA.MS.SHAREPOINT.1.3", diff --git a/powershell/tests/functions/Test-MtCisaSecuritySuiteImpersonation.Tests.ps1 b/powershell/tests/functions/Test-MtCisaSecuritySuiteImpersonation.Tests.ps1 new file mode 100644 index 0000000000..9961e664ca --- /dev/null +++ b/powershell/tests/functions/Test-MtCisaSecuritySuiteImpersonation.Tests.ps1 @@ -0,0 +1,265 @@ +BeforeAll { + $testRoot = Resolve-Path (Join-Path $PSScriptRoot '..\..\..') + . (Join-Path $testRoot 'tests\cisa\exchange\Test.CISA.MS.SECURITYSUITE.2.1.ps1') + . (Join-Path $testRoot 'powershell\internal\checks\cisa\exchange\Get-MtCisaEffectiveAntiPhishPolicy.ps1') + . (Join-Path $testRoot 'tests\cisa\exchange\Test.CISA.MS.SECURITYSUITE.2.2.ps1') + . (Join-Path $testRoot 'tests\cisa\exchange\Test.CISA.MS.SECURITYSUITE.2.3.ps1') + . (Join-Path $testRoot 'tests\cisa\exchange\Test.CISA.MS.SECURITYSUITE.2.4.ps1') + . (Join-Path $testRoot 'tests\cisa\exchange\Test.CISA.MS.SECURITYSUITE.4.1.ps1') +} +Describe 'CISA Security Suite impersonation protection checks' { + BeforeEach { + Mock Add-MtTestResultDetail {} + } + + It 'requires every configured sensitive user and an acceptable action' { + $script:policies = @( + [pscustomobject]@{ + Identity = 'Default'; EnableTargetedUserProtection = $true + TargetedUserProtectionAction = 'Quarantine' + TargetedUsersToProtect = @('Sensitive Person;sensitive@example.com', 'ADMIN@example.com') + } + ) + Mock Get-MtCisaEffectiveAntiPhishPolicy { $script:policies } + + Test-MtCisaImpersonation -SensitiveUsers @('sensitive@example.com', 'admin@example.com') | Should -BeTrue + + $script:policies[0].TargetedUsersToProtect = @('sensitive@example.com') + Test-MtCisaImpersonation -SensitiveUsers @('sensitive@example.com', 'admin@example.com') | Should -BeFalse + + $script:policies[0].TargetedUsersToProtect = @('sensitive@example.com', 'admin@example.com') + $script:policies[0].TargetedUserProtectionAction = 'BccMessage' + Test-MtCisaImpersonation -SensitiveUsers @('sensitive@example.com', 'admin@example.com') | Should -BeFalse + + Test-MtCisaImpersonation | Should -BeFalse + } + + It 'checks owned-domain impersonation protection on an effective all-recipient policy' { + $script:exoResponses = @{ + AntiPhishPolicy = @( + [pscustomobject]@{ + Name = 'Default'; Identity = 'Default'; Enabled = $true; IsDefault = $true + EnableOrganizationDomainsProtection = $true; TargetedDomainProtectionAction = 'Quarantine' + } + ) + AntiPhishRule = @() + EOPProtectionPolicyRule = @() + AcceptedDomain = @([pscustomobject]@{ DomainName = 'contoso.com' }) + } + Mock Get-MtExo { $script:exoResponses[$Request] } + + Test-MtCisaOwnedDomainImpersonationProtection | Should -BeTrue + + $script:exoResponses.AntiPhishPolicy[0].TargetedDomainProtectionAction = 'BccMessage' + Test-MtCisaOwnedDomainImpersonationProtection | Should -BeFalse + $script:exoResponses.AntiPhishPolicy[0].TargetedDomainProtectionAction = 'MoveToJmf' + Test-MtCisaOwnedDomainImpersonationProtection | Should -BeTrue + + $script:exoResponses.AntiPhishPolicy[0].TargetedDomainProtectionAction = 'Quarantine' + $script:exoResponses.AntiPhishPolicy[0].EnableOrganizationDomainsProtection = $false + Test-MtCisaOwnedDomainImpersonationProtection | Should -BeFalse + } + + It 'does not treat a scoped custom anti-phish rule as covering all recipients' { + $script:exoResponses = @{ + AntiPhishPolicy = @( + [pscustomobject]@{ + Name = 'Custom'; Identity = 'Custom'; Enabled = $true; IsDefault = $false + RecommendedPolicyType = 'Custom'; EnableOrganizationDomainsProtection = $true + TargetedDomainProtectionAction = 'Quarantine' + } + ) + AntiPhishRule = @( + [pscustomobject]@{ + State = 'Enabled'; AntiPhishPolicy = 'Custom'; SentTo = @('user@contoso.com') + SentToMemberOf = @(); RecipientDomainIs = @(); ExceptIfSentTo = @() + ExceptIfSentToMemberOf = @(); ExceptIfRecipientDomainIs = @() + } + ) + EOPProtectionPolicyRule = @() + AcceptedDomain = @([pscustomobject]@{ DomainName = 'contoso.com' }) + } + Mock Get-MtExo { $script:exoResponses[$Request] } + + Test-MtCisaOwnedDomainImpersonationProtection | Should -BeFalse + } + + It 'requires matching tenant-wide EOP and Defender preset rules for impersonation' { + $script:exoResponses = @{ + AntiPhishPolicy = @( + [pscustomobject]@{ + Name = 'Standard Preset Security Policy'; Identity = 'Standard Preset Security Policy' + Enabled = $true; IsDefault = $false; RecommendedPolicyType = 'Standard' + EnableTargetedUserProtection = $true; TargetedUserProtectionAction = 'Quarantine' + TargetedUsersToProtect = @('sensitive@contoso.com') + EnableOrganizationDomainsProtection = $true; TargetedDomainProtectionAction = 'Quarantine' + EnableTargetedDomainsProtection = $true; TargetedDomainsToProtect = @('partner.example') + } + ) + AntiPhishRule = @() + EOPProtectionPolicyRule = @( + [pscustomobject]@{ + State = 'Enabled'; Identity = 'Standard Preset Security Policy' + SentTo = @(); SentToMemberOf = @(); RecipientDomainIs = @('contoso.com', 'fabrikam.com') + ExceptIfSentTo = @(); ExceptIfSentToMemberOf = @(); ExceptIfRecipientDomainIs = @() + } + ) + ATPProtectionPolicyRule = @( + [pscustomobject]@{ + State = 'Enabled'; Identity = 'Standard Preset Security Policy' + SentTo = @(); SentToMemberOf = @(); RecipientDomainIs = @('contoso.com', 'fabrikam.com') + ExceptIfSentTo = @(); ExceptIfSentToMemberOf = @(); ExceptIfRecipientDomainIs = @() + } + ) + AcceptedDomain = @( + [pscustomobject]@{ DomainName = 'contoso.com' } + [pscustomobject]@{ DomainName = 'fabrikam.com' } + ) + } + Mock Get-MtExo { $script:exoResponses[$Request] } + + @(Get-MtCisaEffectiveAntiPhishPolicy) | Should -HaveCount 1 + Test-MtCisaImpersonation -SensitiveUsers 'sensitive@contoso.com' | Should -BeTrue + Test-MtCisaOwnedDomainImpersonationProtection | Should -BeTrue + Test-MtCisaPartnerDomainImpersonationProtection -PartnerDomains 'partner.example' | Should -BeTrue + + $rule = $script:exoResponses.ATPProtectionPolicyRule[0] + $unsafeScopes = @( + @{ Field = 'State'; Value = 'Disabled' } + @{ Field = 'Identity'; Value = 'Strict Preset Security Policy' } + @{ Field = 'SentTo'; Value = @('user@contoso.com') } + @{ Field = 'SentToMemberOf'; Value = @('Scoped group') } + @{ Field = 'RecipientDomainIs'; Value = @('contoso.com') } + @{ Field = 'ExceptIfSentTo'; Value = @('user@contoso.com') } + @{ Field = 'ExceptIfSentToMemberOf'; Value = @('Excluded group') } + @{ Field = 'ExceptIfRecipientDomainIs'; Value = @('contoso.com') } + ) + foreach ($scope in $unsafeScopes) { + $originalValue = $rule.($scope.Field) + $rule.($scope.Field) = $scope.Value + Test-MtCisaImpersonation -SensitiveUsers 'sensitive@contoso.com' | Should -BeFalse -Because $scope.Field + Test-MtCisaOwnedDomainImpersonationProtection | Should -BeFalse -Because $scope.Field + Test-MtCisaPartnerDomainImpersonationProtection -PartnerDomains 'partner.example' | Should -BeFalse -Because $scope.Field + Test-MtCisaImpersonationTip | Should -BeTrue -Because 'the EOP safety-tip scope is unchanged' + $rule.($scope.Field) = $originalValue + } + + $script:exoResponses.ATPProtectionPolicyRule = @() + @(Get-MtCisaEffectiveAntiPhishPolicy -RequireDefenderProtection) | Should -BeNullOrEmpty + Test-MtCisaImpersonationTip | Should -BeTrue + + $script:exoResponses.EOPProtectionPolicyRule[0].ExceptIfRecipientDomainIs = @('contoso.com') + @(Get-MtCisaEffectiveAntiPhishPolicy) | Should -BeNullOrEmpty + } + + It 'does not accept a default policy when accepted-domain data is missing' { + $script:exoResponses = @{ + AntiPhishPolicy = @( + [pscustomobject]@{ + Name = 'Default'; Identity = 'Default'; Enabled = $true; IsDefault = $true + } + ) + AntiPhishRule = @() + EOPProtectionPolicyRule = @() + AcceptedDomain = @() + } + Mock Get-MtExo { $script:exoResponses[$Request] } + + @(Get-MtCisaEffectiveAntiPhishPolicy) | Should -BeNullOrEmpty + } + + It 'requires configured partner domains and protection for every configured domain' { + $script:exoResponses = @{ + AntiPhishPolicy = @( + [pscustomobject]@{ + Name = 'Default'; Identity = 'Default'; Enabled = $true; IsDefault = $true + EnableTargetedDomainsProtection = $true; TargetedDomainProtectionAction = 'Quarantine' + TargetedDomainsToProtect = @('partner.example') + } + ) + AntiPhishRule = @() + EOPProtectionPolicyRule = @() + AcceptedDomain = @([pscustomobject]@{ DomainName = 'contoso.com' }) + } + Mock Get-MtExo { $script:exoResponses[$Request] } + + Test-MtCisaPartnerDomainImpersonationProtection -PartnerDomains 'partner.example' | Should -BeTrue + $script:exoResponses.AntiPhishPolicy[0].TargetedDomainProtectionAction = 'BccMessage' + Test-MtCisaPartnerDomainImpersonationProtection -PartnerDomains 'partner.example' | Should -BeFalse + $script:exoResponses.AntiPhishPolicy[0].TargetedDomainProtectionAction = 'MoveToJmf' + Test-MtCisaPartnerDomainImpersonationProtection -PartnerDomains 'partner.example' | Should -BeTrue + Test-MtCisaPartnerDomainImpersonationProtection | Should -BeFalse + Test-MtCisaPartnerDomainImpersonationProtection -PartnerDomains @('partner.example', 'supplier.example') | Should -BeFalse + } + + It 'checks all six safety tips on an all-recipient custom policy' { + $script:effectivePolicies = @( + [pscustomobject]@{ + Identity = 'Custom' + EnableFirstContactSafetyTips = $true + EnableSimilarUsersSafetyTips = $true + EnableSimilarDomainsSafetyTips = $true + EnableUnusualCharactersSafetyTips = $true + EnableViaTag = $true + EnableUnauthenticatedSender = $true + } + ) + Mock Get-MtCisaEffectiveAntiPhishPolicy { $script:effectivePolicies } + + Test-MtCisaImpersonationTip | Should -BeTrue + + foreach ($tip in @( + 'EnableFirstContactSafetyTips', + 'EnableSimilarUsersSafetyTips', + 'EnableSimilarDomainsSafetyTips', + 'EnableUnusualCharactersSafetyTips', + 'EnableViaTag', + 'EnableUnauthenticatedSender' + )) { + $script:effectivePolicies[0].$tip = $false + Test-MtCisaImpersonationTip | Should -BeFalse + $script:effectivePolicies[0].$tip = $true + } + } + + It 'accepts an all-recipient preset policy for user safety tips' { + Mock Get-MtCisaEffectiveAntiPhishPolicy { + @([pscustomobject]@{ Identity = 'Standard Preset Security Policy' }) + } + + Test-MtCisaImpersonationTip | Should -BeTrue + } + + It 'requires baseline alerts to be enabled and includes the URL-click alert when present' { + $alertNames = @( + 'Suspicious email sending patterns detected', + 'Suspicious connector activity', + 'Suspicious Email Forwarding Activity', + 'Messages have been delayed', + 'Tenant restricted from sending unprovisioned email', + 'Tenant restricted from sending email' + ) + $script:alerts = @( + foreach ($alertName in $alertNames) { + [pscustomobject]@{ Name = $alertName; Disabled = $false; NotificationEnabled = $false } + } + ) + Mock Get-MtExo { $script:alerts } + + Test-MtCisaExoAlert | Should -BeTrue + + $script:alerts[0].Disabled = $true + Test-MtCisaExoAlert | Should -BeFalse + $script:alerts[0].Disabled = $false + + $script:alerts += [pscustomobject]@{ + Name = 'A potentially malicious URL click was detected' + Disabled = $true + NotificationEnabled = $true + } + Test-MtCisaExoAlert | Should -BeFalse + + $script:alerts[-1].Disabled = $false + Test-MtCisaExoAlert | Should -BeTrue + } +} diff --git a/powershell/tests/functions/engine/Frameworks.Tests.ps1 b/powershell/tests/functions/engine/Frameworks.Tests.ps1 index 06a6372fd8..057cb0921f 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