diff --git a/build/golden/Export-MtLegacyIdTable.ps1 b/build/golden/Export-MtLegacyIdTable.ps1 index e5a8d8ea9e..d0aec05d8a 100644 --- a/build/golden/Export-MtLegacyIdTable.ps1 +++ b/build/golden/Export-MtLegacyIdTable.ps1 @@ -19,9 +19,8 @@ function - the single check function called in the It body is called by exactly one current test retired - nothing matched - The output is deterministic: GeneratedFrom is the last commit that touched the scanned test files, - and current IDs are read from that commit's tree, so rerunning on a later commit that does not touch - tests/ produces identical output. + GeneratedFrom is the last commit that touched the scanned Pester test files. Current native test IDs, + titles and function names are read from the working tree so legacy checks can map to their native replacements. .EXAMPLE ./build/golden/Export-MtLegacyIdTable.ps1 @@ -55,6 +54,21 @@ $ManualOverrides = [ordered]@{ # Pre-colon names of the split checks; the current titles say 'Global Administrator' and both call one function. 'MT.1050 Apps with high-risk permissions having a direct path to Global Admin' = 'MT.1050' 'MT.1051 Apps with high-risk permissions having an indirect path to Global Admin' = 'MT.1051' + # CISA moved the email malware checks to the Security Suite baseline. + 'CISA.MS.EXO.09.5' = 'CISA.MS.SECURITYSUITE.1.1' + 'CISA.MS.EXO.9.5' = 'CISA.MS.SECURITYSUITE.1.1' + 'CISA.MS.EXO.10.3' = 'CISA.MS.SECURITYSUITE.1.2' + 'CISA.MS.EXO.9.1' = 'CISA.MS.SECURITYSUITE.1.1' + 'CISA.MS.EXO.9.3' = 'CISA.MS.SECURITYSUITE.1.1' + 'CISA.MS.EXO.10.1' = 'CISA.MS.SECURITYSUITE.1.3' + 'CISA.MS.EXO.10.2' = 'CISA.MS.SECURITYSUITE.1.3' + 'MS.EXO.09.5' = 'CISA.MS.SECURITYSUITE.1.1' + 'MS.EXO.9.5' = 'CISA.MS.SECURITYSUITE.1.1' + 'MS.EXO.10.3' = 'CISA.MS.SECURITYSUITE.1.2' + 'MS.EXO.9.1' = 'CISA.MS.SECURITYSUITE.1.1' + 'MS.EXO.9.3' = 'CISA.MS.SECURITYSUITE.1.1' + 'MS.EXO.10.1' = 'CISA.MS.SECURITYSUITE.1.3' + 'MS.EXO.10.2' = 'CISA.MS.SECURITYSUITE.1.3' # Mock-based unit tests that briefly lived under tests/; they were never security checks. 'MFA for All users should pass even if not targeting guests' = 'retired' 'MFA for All users that excludes any guest type should fail' = 'retired' @@ -263,6 +277,42 @@ foreach ($line in $treeLines) { } Write-Verbose "Current static IDs: $($currentIds.Count); family prefixes: $($familyPrefixes -join ', ')" +# Native tests are current checks after migration from the Pester format. +$nativeTestFiles = Get-ChildItem -Path (Join-Path $RepoRoot 'tests') -Recurse -File -Filter 'Test.*.ps1' | + Where-Object { $_.FullName -notmatch '[\\/]Custom[\\/]' } +foreach ($file in $nativeTestFiles) { + $tokens = $null + $parseErrors = $null + $ast = [System.Management.Automation.Language.Parser]::ParseFile($file.FullName, [ref]$tokens, [ref]$parseErrors) + if ($parseErrors.Count -gt 0) { + throw "Cannot parse native test '$($file.FullName)': $($parseErrors[0].Message)" + } + + $function = $ast.FindAll({ + param($node) + $node -is [System.Management.Automation.Language.FunctionDefinitionAst] -and + $node.Body.ParamBlock -and + ($node.Body.ParamBlock.Attributes | Where-Object { $_.TypeName.Name -in 'MaesterTest', 'MaesterTestAttribute' }) + }, $true) | Select-Object -First 1 + if (-not $function) { + throw "Native test '$($file.FullName)' has no MaesterTest attribute." + } + + $attribute = $function.Body.ParamBlock.Attributes | Where-Object { $_.TypeName.Name -in 'MaesterTest', 'MaesterTestAttribute' } | Select-Object -First 1 + $id = $file.BaseName.Substring('Test.'.Length) + $title = $attribute.NamedArguments | Where-Object { $_.ArgumentName -eq 'Title' } | Select-Object -First 1 + if (-not $title -or $title.Argument -isnot [System.Management.Automation.Language.StringConstantExpressionAst]) { + throw "Native test '$($file.FullName)' has no static title." + } + + $currentIds[$id] = [pscustomobject]@{ + Id = $id + Title = Get-NormalizedTitle $title.Argument.Value + Functions = @($function.Name) + Path = $file.FullName.Substring($RepoRoot.Length + 1).Replace('\', '/') + } +} + $titleIndex = @{} $functionIndex = @{} foreach ($c in $currentIds.Values) { diff --git a/build/golden/Export-MtLegacyTagTable.ps1 b/build/golden/Export-MtLegacyTagTable.ps1 index 33da8e4eff..7e0dbbf406 100644 --- a/build/golden/Export-MtLegacyTagTable.ps1 +++ b/build/golden/Export-MtLegacyTagTable.ps1 @@ -51,7 +51,13 @@ $fixtures = Join-Path $RepoRoot 'powershell/tests/fixtures/golden' # 2.x IDs that have another ID in 3.0. $RenamedIds = @{ - 'MT1060' = 'MT.1060' # The drift family: four Its per folder in 2.x, one native family in 3.0. + 'MT1060' = 'MT.1060' # The drift family: four Its per folder in 2.x, one native family in 3.0. + 'CISA.MS.EXO.9.1' = 'CISA.MS.SECURITYSUITE.1.1' + 'CISA.MS.EXO.9.3' = 'CISA.MS.SECURITYSUITE.1.1' + 'CISA.MS.EXO.9.5' = 'CISA.MS.SECURITYSUITE.1.1' + 'CISA.MS.EXO.10.1' = 'CISA.MS.SECURITYSUITE.1.3' + 'CISA.MS.EXO.10.2' = 'CISA.MS.SECURITYSUITE.1.3' + 'CISA.MS.EXO.10.3' = 'CISA.MS.SECURITYSUITE.1.2' } # The typed selector that takes the place of a tag. Only tags with an obvious one are listed. diff --git a/powershell/assets/Maester.LegacyIds.json b/powershell/assets/Maester.LegacyIds.json index d0681e44a6..615edfae1e 100644 --- a/powershell/assets/Maester.LegacyIds.json +++ b/powershell/assets/Maester.LegacyIds.json @@ -1,6 +1,6 @@ { "SchemaVersion": "1.0", - "GeneratedFrom": "fc6a9078bcdd59b5b2f788682fdcd2be27e15b9c", + "GeneratedFrom": "eb13e7a116e4063bec204e901e4847ae67c1f6f6", "Entries": [ { "LegacyId": "1.1.1 (L1) Ensure Administrative accounts are cloud-only", @@ -29,7 +29,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 +37,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 +53,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 +69,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 +77,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 +85,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 +957,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 +965,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 +981,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 +989,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" @@ -1116,20 +1116,68 @@ }, { "LegacyId": "CISA.MS.EXO.09.3", - "CurrentId": "CISA.MS.EXO.9.3", - "Rule": "title", + "CurrentId": "retired", + "Rule": "retired", "FirstSeenCommit": "d176a815b8cfef203cfe0672af5bc092385f05b9", "LastSeenCommit": "5810a0dc37538fe0c4884f55938f23f5c7d1d6cc", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaBlockFileType.Tests.ps1" }, { "LegacyId": "CISA.MS.EXO.09.5", - "CurrentId": "CISA.MS.EXO.9.5", - "Rule": "title", + "CurrentId": "CISA.MS.SECURITYSUITE.1.1", + "Rule": "manual", "FirstSeenCommit": "d176a815b8cfef203cfe0672af5bc092385f05b9", "LastSeenCommit": "5810a0dc37538fe0c4884f55938f23f5c7d1d6cc", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaBlockExecutable.Tests.ps1" }, + { + "LegacyId": "CISA.MS.EXO.10.1", + "CurrentId": "CISA.MS.SECURITYSUITE.1.3", + "Rule": "manual", + "FirstSeenCommit": "d176a815b8cfef203cfe0672af5bc092385f05b9", + "LastSeenCommit": "eb38f4357cdf3576600aeca7d8da3138f77a37ca", + "LastSeenFile": "tests/cisa/exchange/Test-MtCisaMalwareScan.Tests.ps1" + }, + { + "LegacyId": "CISA.MS.EXO.10.2", + "CurrentId": "CISA.MS.SECURITYSUITE.1.3", + "Rule": "manual", + "FirstSeenCommit": "d176a815b8cfef203cfe0672af5bc092385f05b9", + "LastSeenCommit": "eb38f4357cdf3576600aeca7d8da3138f77a37ca", + "LastSeenFile": "tests/cisa/exchange/Test-MtCisaMalwareAction.Tests.ps1" + }, + { + "LegacyId": "CISA.MS.EXO.10.3", + "CurrentId": "CISA.MS.SECURITYSUITE.1.2", + "Rule": "manual", + "FirstSeenCommit": "d176a815b8cfef203cfe0672af5bc092385f05b9", + "LastSeenCommit": "eb38f4357cdf3576600aeca7d8da3138f77a37ca", + "LastSeenFile": "tests/cisa/exchange/Test-MtCisaMalwareZap.Tests.ps1" + }, + { + "LegacyId": "CISA.MS.EXO.9.1", + "CurrentId": "CISA.MS.SECURITYSUITE.1.1", + "Rule": "manual", + "FirstSeenCommit": "d176a815b8cfef203cfe0672af5bc092385f05b9", + "LastSeenCommit": "eb38f4357cdf3576600aeca7d8da3138f77a37ca", + "LastSeenFile": "tests/cisa/exchange/Test-MtCisaAttachmentFilter.Tests.ps1" + }, + { + "LegacyId": "CISA.MS.EXO.9.3", + "CurrentId": "CISA.MS.SECURITYSUITE.1.1", + "Rule": "manual", + "FirstSeenCommit": "b2513b049671c82eede6415f708bb3560e6a8d06", + "LastSeenCommit": "eb38f4357cdf3576600aeca7d8da3138f77a37ca", + "LastSeenFile": "tests/cisa/exchange/Test-MtCisaBlockFileType.Tests.ps1" + }, + { + "LegacyId": "CISA.MS.EXO.9.5", + "CurrentId": "CISA.MS.SECURITYSUITE.1.1", + "Rule": "manual", + "FirstSeenCommit": "b2513b049671c82eede6415f708bb3560e6a8d06", + "LastSeenCommit": "eb38f4357cdf3576600aeca7d8da3138f77a37ca", + "LastSeenFile": "tests/cisa/exchange/Test-MtCisaBlockExecutable.Tests.ps1" + }, { "LegacyId": "Configure which users are allowed to present in Teams meetings", "CurrentId": "retired", @@ -1140,8 +1188,8 @@ }, { "LegacyId": "Ensure MailTips are enabled for end users", - "CurrentId": "MT.1039", - "Rule": "title", + "CurrentId": "retired", + "Rule": "retired", "FirstSeenCommit": "7cd563adfc02cdecb49b1b5e755f5c541bdd4beb", "LastSeenCommit": "7cd563adfc02cdecb49b1b5e755f5c541bdd4beb", "LastSeenFile": "tests/Maester/Exchange/Test-ExchangeSetting.Tests.ps1" @@ -1188,8 +1236,8 @@ }, { "LegacyId": "Ensure modern authentication for Exchange Online is enabled", - "CurrentId": "MT.1044", - "Rule": "title", + "CurrentId": "retired", + "Rule": "retired", "FirstSeenCommit": "7cd563adfc02cdecb49b1b5e755f5c541bdd4beb", "LastSeenCommit": "7cd563adfc02cdecb49b1b5e755f5c541bdd4beb", "LastSeenFile": "tests/Maester/Exchange/Test-ExchangeSetting.Tests.ps1" @@ -1204,8 +1252,8 @@ }, { "LegacyId": "Ensure users installing Outlook add-ins is not allowed", - "CurrentId": "MT.1041", - "Rule": "title", + "CurrentId": "retired", + "Rule": "retired", "FirstSeenCommit": "7cd563adfc02cdecb49b1b5e755f5c541bdd4beb", "LastSeenCommit": "7cd563adfc02cdecb49b1b5e755f5c541bdd4beb", "LastSeenFile": "tests/Maester/Exchange/Test-ExchangeSetting.Tests.ps1" @@ -1796,8 +1844,8 @@ }, { "LegacyId": "MS.EXO.09.1", - "CurrentId": "CISA.MS.EXO.9.1", - "Rule": "title", + "CurrentId": "retired", + "Rule": "retired", "FirstSeenCommit": "062c1e6a1e0566789256aaea1e37b73dcdb11aed", "LastSeenCommit": "062c1e6a1e0566789256aaea1e37b73dcdb11aed", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaAttachmentFilter.Tests.ps1" @@ -1812,8 +1860,8 @@ }, { "LegacyId": "MS.EXO.09.3", - "CurrentId": "CISA.MS.EXO.9.3", - "Rule": "title", + "CurrentId": "retired", + "Rule": "retired", "FirstSeenCommit": "062c1e6a1e0566789256aaea1e37b73dcdb11aed", "LastSeenCommit": "062c1e6a1e0566789256aaea1e37b73dcdb11aed", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaBlockFileType.Tests.ps1" @@ -1828,8 +1876,8 @@ }, { "LegacyId": "MS.EXO.09.5", - "CurrentId": "CISA.MS.EXO.9.5", - "Rule": "title", + "CurrentId": "CISA.MS.SECURITYSUITE.1.1", + "Rule": "manual", "FirstSeenCommit": "062c1e6a1e0566789256aaea1e37b73dcdb11aed", "LastSeenCommit": "062c1e6a1e0566789256aaea1e37b73dcdb11aed", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaBlockExecutable.Tests.ps1" @@ -1844,24 +1892,24 @@ }, { "LegacyId": "MS.EXO.10.1", - "CurrentId": "CISA.MS.EXO.10.1", - "Rule": "prefix", + "CurrentId": "CISA.MS.SECURITYSUITE.1.3", + "Rule": "manual", "FirstSeenCommit": "1e22bb9c04dc04785d4a813e270b5359d71c6338", "LastSeenCommit": "1e22bb9c04dc04785d4a813e270b5359d71c6338", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaMalwareScan.Tests.ps1" }, { "LegacyId": "MS.EXO.10.2", - "CurrentId": "CISA.MS.EXO.10.2", - "Rule": "prefix", + "CurrentId": "CISA.MS.SECURITYSUITE.1.3", + "Rule": "manual", "FirstSeenCommit": "1e22bb9c04dc04785d4a813e270b5359d71c6338", "LastSeenCommit": "1e22bb9c04dc04785d4a813e270b5359d71c6338", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaMalwareAction.Tests.ps1" }, { "LegacyId": "MS.EXO.10.3", - "CurrentId": "CISA.MS.EXO.10.3", - "Rule": "prefix", + "CurrentId": "CISA.MS.SECURITYSUITE.1.2", + "Rule": "manual", "FirstSeenCommit": "1e22bb9c04dc04785d4a813e270b5359d71c6338", "LastSeenCommit": "1e22bb9c04dc04785d4a813e270b5359d71c6338", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaMalwareZap.Tests.ps1" @@ -2124,8 +2172,8 @@ }, { "LegacyId": "MS.EXO.9.1", - "CurrentId": "CISA.MS.EXO.9.1", - "Rule": "prefix", + "CurrentId": "CISA.MS.SECURITYSUITE.1.1", + "Rule": "manual", "FirstSeenCommit": "9b5657a0506757ef2c2be95b93c115a921491522", "LastSeenCommit": "1e22bb9c04dc04785d4a813e270b5359d71c6338", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaAttachmentFilter.Tests.ps1" @@ -2140,8 +2188,8 @@ }, { "LegacyId": "MS.EXO.9.3", - "CurrentId": "CISA.MS.EXO.9.3", - "Rule": "prefix", + "CurrentId": "CISA.MS.SECURITYSUITE.1.1", + "Rule": "manual", "FirstSeenCommit": "9b5657a0506757ef2c2be95b93c115a921491522", "LastSeenCommit": "e6db16c50cb93a790370609162c683a5d1338928", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaBlockFileType.Tests.ps1" @@ -2156,8 +2204,8 @@ }, { "LegacyId": "MS.EXO.9.5", - "CurrentId": "CISA.MS.EXO.9.5", - "Rule": "prefix", + "CurrentId": "CISA.MS.SECURITYSUITE.1.1", + "Rule": "manual", "FirstSeenCommit": "9b5657a0506757ef2c2be95b93c115a921491522", "LastSeenCommit": "e6db16c50cb93a790370609162c683a5d1338928", "LastSeenFile": "tests/cisa/exchange/Test-MtCisaBlockExecutable.Tests.ps1" diff --git a/powershell/assets/Maester.LegacyTags.json b/powershell/assets/Maester.LegacyTags.json index 2ba8db3c4b..fdacaac06f 100644 --- a/powershell/assets/Maester.LegacyTags.json +++ b/powershell/assets/Maester.LegacyTags.json @@ -1161,9 +1161,6 @@ "CISA.MS.AAD.8.2", "CISA.MS.AAD.8.3", "CISA.MS.EXO.1.1", - "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", @@ -1196,11 +1193,11 @@ "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.1.1", + "CISA.MS.SECURITYSUITE.1.2", + "CISA.MS.SECURITYSUITE.1.3", "CISA.MS.SHAREPOINT.1.1", "CISA.MS.SHAREPOINT.1.2", "CISA.MS.SHAREPOINT.1.3", @@ -1211,6 +1208,42 @@ "CISA.MS.SHAREPOINT.3.3" ] }, + { + "Tag": "CISA.MS.EXO.10.1", + "Tests": [ + "CISA.MS.SECURITYSUITE.1.3" + ] + }, + { + "Tag": "CISA.MS.EXO.10.2", + "Tests": [ + "CISA.MS.SECURITYSUITE.1.3" + ] + }, + { + "Tag": "CISA.MS.EXO.10.3", + "Tests": [ + "CISA.MS.SECURITYSUITE.1.2" + ] + }, + { + "Tag": "CISA.MS.EXO.9.1", + "Tests": [ + "CISA.MS.SECURITYSUITE.1.1" + ] + }, + { + "Tag": "CISA.MS.EXO.9.3", + "Tests": [ + "CISA.MS.SECURITYSUITE.1.1" + ] + }, + { + "Tag": "CISA.MS.EXO.9.5", + "Tests": [ + "CISA.MS.SECURITYSUITE.1.1" + ] + }, { "Tag": "CopilotStudio", "Replacement": "-Product copilot-studio", @@ -2152,9 +2185,6 @@ "Tag": "MS.EXO", "Tests": [ "CISA.MS.EXO.1.1", - "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", @@ -2187,11 +2217,11 @@ "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.1.1", + "CISA.MS.SECURITYSUITE.1.2", + "CISA.MS.SECURITYSUITE.1.3" ] }, { @@ -2203,19 +2233,19 @@ { "Tag": "MS.EXO.10.1", "Tests": [ - "CISA.MS.EXO.10.1" + "CISA.MS.SECURITYSUITE.1.3" ] }, { "Tag": "MS.EXO.10.2", "Tests": [ - "CISA.MS.EXO.10.2" + "CISA.MS.SECURITYSUITE.1.3" ] }, { "Tag": "MS.EXO.10.3", "Tests": [ - "CISA.MS.EXO.10.3" + "CISA.MS.SECURITYSUITE.1.2" ] }, { @@ -2413,7 +2443,7 @@ { "Tag": "MS.EXO.9.1", "Tests": [ - "CISA.MS.EXO.9.1" + "CISA.MS.SECURITYSUITE.1.1" ] }, { @@ -2425,7 +2455,7 @@ { "Tag": "MS.EXO.9.3", "Tests": [ - "CISA.MS.EXO.9.3" + "CISA.MS.SECURITYSUITE.1.1" ] }, { @@ -2437,7 +2467,7 @@ { "Tag": "MS.EXO.9.5", "Tests": [ - "CISA.MS.EXO.9.5" + "CISA.MS.SECURITYSUITE.1.1" ] }, { diff --git a/powershell/internal/checks/cisa/exchange/Get-MtCisaEffectiveAntiMalwarePolicy.ps1 b/powershell/internal/checks/cisa/exchange/Get-MtCisaEffectiveAntiMalwarePolicy.ps1 new file mode 100644 index 0000000000..05fe8dd019 --- /dev/null +++ b/powershell/internal/checks/cisa/exchange/Get-MtCisaEffectiveAntiMalwarePolicy.ps1 @@ -0,0 +1,75 @@ +function Get-MtCisaEffectiveAntiMalwarePolicy { + [CmdletBinding()] + [OutputType([object])] + param() + + $policies = @(Get-MtExo -Request MalwareFilterPolicy) + $malwareRules = @(Get-MtExo -Request MalwareFilterRule) + $presetRules = @(Get-MtExo -Request EOPProtectionPolicyRule) + $tenantDomains = @( + Get-MtExo -Request AcceptedDomain | + ForEach-Object { + $domain = if ($_.DomainName) { $_.DomainName } else { $_.Name } + ([string]$domain).Trim().ToLowerInvariant() + } | + Where-Object { -not [string]::IsNullOrWhiteSpace($_) } + ) + + $isEmpty = { + param($Value) + $null -eq $Value -or + ($Value -is [string] -and [string]::IsNullOrWhiteSpace($Value)) -or + @($Value).Count -eq 0 + } + + $ruleCoversAllRecipients = { + param($Rule) + foreach ($field in @('SentTo', 'SentToMemberOf', 'ExceptIfSentTo', 'ExceptIfSentToMemberOf', 'ExceptIfRecipientDomainIs')) { + if (-not (& $isEmpty $Rule.$field)) { + return $false + } + } + + if (& $isEmpty $Rule.RecipientDomainIs) { + return $true + } + + $recipientDomains = @($Rule.RecipientDomainIs | ForEach-Object { ([string]$_).Trim().ToLowerInvariant() }) + $tenantDomains.Count -gt 0 -and @($tenantDomains | Where-Object { $_ -notin $recipientDomains }).Count -eq 0 + } + + foreach ($preset in @('Strict', 'Standard')) { + $pattern = "(?i)$preset Preset Security Policy" + $presetRule = $presetRules | Where-Object { + $_.State -eq 'Enabled' -and + $_.Identity -match $pattern -and + (& $ruleCoversAllRecipients $_) + } | Select-Object -First 1 + + if ($presetRule) { + $policy = $policies | Where-Object { $_.Identity -match $pattern } | Select-Object -First 1 + if ($policy) { + return $policy + } + } + } + + $enabledRules = @($malwareRules | Where-Object { $_.State -eq 'Enabled' }) + if ($enabledRules.Count -gt 0) { + $highestPriority = ($enabledRules | Measure-Object -Property Priority -Minimum).Minimum + $highestPriorityRules = @($enabledRules | Where-Object { $_.Priority -eq $highestPriority }) + $effectiveRule = $highestPriorityRules | Where-Object { & $ruleCoversAllRecipients $_ } | Select-Object -First 1 + + if ($effectiveRule) { + return $policies | Where-Object { + $_.Identity -eq $effectiveRule.MalwareFilterPolicy + } | Select-Object -First 1 + } + } + + $defaultPolicy = $policies | Where-Object { + $_.Identity -eq 'Default' -or $_.IsDefault -eq $true + } | Select-Object -First 1 + + return $defaultPolicy +} diff --git a/powershell/tests/fixtures/golden/config-layouts/root-custom-tenant/expected.json b/powershell/tests/fixtures/golden/config-layouts/root-custom-tenant/expected.json index 766612336a..6153eeb219 100644 --- a/powershell/tests/fixtures/golden/config-layouts/root-custom-tenant/expected.json +++ b/powershell/tests/fixtures/golden/config-layouts/root-custom-tenant/expected.json @@ -15,7 +15,7 @@ "TenantId": null, "ConfigFile": "powershell/tests/fixtures/golden/config-layouts/root-custom-tenant/maester-config.json", "ConfigSource": "maester-config.json", - "CustomOverlay": "powershell/tests/fixtures/golden/config-layouts/root-custom-tenant/Custom/maester-config.json", + "CustomOverlay": "powershell/tests/fixtures/golden/config-layouts/root-custom-tenant/custom/maester-config.json", "UsedShippedFile": false, "GlobalSettings": { "EmergencyAccessAccounts": [ @@ -37,7 +37,7 @@ "TenantId": "11111111-2222-3333-4444-555555555555", "ConfigFile": "powershell/tests/fixtures/golden/config-layouts/root-custom-tenant/maester-config.11111111-2222-3333-4444-555555555555.json", "ConfigSource": "maester-config.11111111-2222-3333-4444-555555555555.json", - "CustomOverlay": "powershell/tests/fixtures/golden/config-layouts/root-custom-tenant/Custom/maester-config.json", + "CustomOverlay": "powershell/tests/fixtures/golden/config-layouts/root-custom-tenant/custom/maester-config.json", "UsedShippedFile": false, "GlobalSettings": { "EmergencyAccessAccounts": [ diff --git a/powershell/tests/fixtures/golden/selection.json b/powershell/tests/fixtures/golden/selection.json index ae970e7cfd..8f87117296 100644 --- a/powershell/tests/fixtures/golden/selection.json +++ b/powershell/tests/fixtures/golden/selection.json @@ -21,7 +21,7 @@ "AD" ] }, - "SelectedCount": 582, + "SelectedCount": 580, "SelectedFamilies": [ "MT.1024", "MT.1059", @@ -266,9 +266,6 @@ "CISA.MS.AAD.8.2", "CISA.MS.AAD.8.3", "CISA.MS.EXO.1.1", - "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", @@ -301,11 +298,12 @@ "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.1.1", + "CISA.MS.SECURITYSUITE.1.2", + "CISA.MS.SECURITYSUITE.1.3", + "CISA.MS.SECURITYSUITE.1.4", "CISA.MS.SHAREPOINT.1.1", "CISA.MS.SHAREPOINT.1.2", "CISA.MS.SHAREPOINT.1.3", @@ -771,7 +769,7 @@ "AD" ] }, - "SelectedCount": 538, + "SelectedCount": 536, "SelectedFamilies": [ "MT.1024", "MT.1059", @@ -1016,9 +1014,6 @@ "CISA.MS.AAD.8.2", "CISA.MS.AAD.8.3", "CISA.MS.EXO.1.1", - "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", @@ -1051,11 +1046,12 @@ "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.1.1", + "CISA.MS.SECURITYSUITE.1.2", + "CISA.MS.SECURITYSUITE.1.3", + "CISA.MS.SECURITYSUITE.1.4", "CISA.MS.SHAREPOINT.1.1", "CISA.MS.SHAREPOINT.1.2", "CISA.MS.SHAREPOINT.1.3", @@ -1330,7 +1326,7 @@ "AD" ] }, - "SelectedCount": 598, + "SelectedCount": 596, "SelectedFamilies": [ "MT.1024", "MT.1033", @@ -1578,9 +1574,6 @@ "CISA.MS.AAD.8.2", "CISA.MS.AAD.8.3", "CISA.MS.EXO.1.1", - "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", @@ -1613,11 +1606,12 @@ "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.1.1", + "CISA.MS.SECURITYSUITE.1.2", + "CISA.MS.SECURITYSUITE.1.3", + "CISA.MS.SECURITYSUITE.1.4", "CISA.MS.SHAREPOINT.1.1", "CISA.MS.SHAREPOINT.1.2", "CISA.MS.SHAREPOINT.1.3", @@ -1951,7 +1945,7 @@ "AD" ] }, - "SelectedCount": 609, + "SelectedCount": 607, "SelectedFamilies": [ "MT.1024", "MT.1059", @@ -2197,9 +2191,6 @@ "CISA.MS.AAD.8.2", "CISA.MS.AAD.8.3", "CISA.MS.EXO.1.1", - "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", @@ -2232,11 +2223,12 @@ "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.1.1", + "CISA.MS.SECURITYSUITE.1.2", + "CISA.MS.SECURITYSUITE.1.3", + "CISA.MS.SECURITYSUITE.1.4", "CISA.MS.SHAREPOINT.1.1", "CISA.MS.SHAREPOINT.1.2", "CISA.MS.SHAREPOINT.1.3", @@ -2581,7 +2573,7 @@ "AD" ] }, - "SelectedCount": 639, + "SelectedCount": 637, "SelectedFamilies": [ "MT.1024", "MT.1033", @@ -2830,9 +2822,6 @@ "CISA.MS.AAD.8.2", "CISA.MS.AAD.8.3", "CISA.MS.EXO.1.1", - "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", @@ -2865,11 +2854,12 @@ "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.1.1", + "CISA.MS.SECURITYSUITE.1.2", + "CISA.MS.SECURITYSUITE.1.3", + "CISA.MS.SECURITYSUITE.1.4", "CISA.MS.SHAREPOINT.1.1", "CISA.MS.SHAREPOINT.1.2", "CISA.MS.SHAREPOINT.1.3", @@ -3441,7 +3431,7 @@ "AD" ] }, - "SelectedCount": 538, + "SelectedCount": 536, "SelectedFamilies": [ "MT.1024", "MT.1059", @@ -3686,9 +3676,6 @@ "CISA.MS.AAD.8.2", "CISA.MS.AAD.8.3", "CISA.MS.EXO.1.1", - "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", @@ -3721,11 +3708,12 @@ "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.1.1", + "CISA.MS.SECURITYSUITE.1.2", + "CISA.MS.SECURITYSUITE.1.3", + "CISA.MS.SECURITYSUITE.1.4", "CISA.MS.SHAREPOINT.1.1", "CISA.MS.SHAREPOINT.1.2", "CISA.MS.SHAREPOINT.1.3", @@ -4006,7 +3994,7 @@ "AD" ] }, - "SelectedCount": 595, + "SelectedCount": 593, "SelectedFamilies": [ "MT.1024", "MT.1033", @@ -4255,9 +4243,6 @@ "CISA.MS.AAD.8.2", "CISA.MS.AAD.8.3", "CISA.MS.EXO.1.1", - "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", @@ -4290,11 +4275,12 @@ "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.1.1", + "CISA.MS.SECURITYSUITE.1.2", + "CISA.MS.SECURITYSUITE.1.3", + "CISA.MS.SECURITYSUITE.1.4", "CISA.MS.SHAREPOINT.1.1", "CISA.MS.SHAREPOINT.1.2", "CISA.MS.SHAREPOINT.1.3", diff --git a/powershell/tests/functions/Test-MtCisaSecuritySuiteMalware.Tests.ps1 b/powershell/tests/functions/Test-MtCisaSecuritySuiteMalware.Tests.ps1 new file mode 100644 index 0000000000..8e6897cf12 --- /dev/null +++ b/powershell/tests/functions/Test-MtCisaSecuritySuiteMalware.Tests.ps1 @@ -0,0 +1,191 @@ +BeforeAll { + $testRoot = Resolve-Path (Join-Path $PSScriptRoot '..\..\..') + . (Join-Path $testRoot 'powershell\internal\checks\cisa\exchange\Get-MtCisaEffectiveAntiMalwarePolicy.ps1') + . (Join-Path $testRoot 'tests\cisa\exchange\Test.CISA.MS.SECURITYSUITE.1.1.ps1') + . (Join-Path $testRoot 'tests\cisa\exchange\Test.CISA.MS.SECURITYSUITE.1.2.ps1') + . (Join-Path $testRoot 'tests\orca\Test.ORCA.158.ps1') + . (Join-Path $testRoot 'tests\cisa\defender\Test.CISA.MS.SECURITYSUITE.1.3.ps1') + . (Join-Path $testRoot 'tests\cisa\defender\Test.CISA.MS.SECURITYSUITE.1.4.ps1') +} +Describe 'CISA Security Suite malware and Safe Attachments checks' { + BeforeEach { + Mock Add-MtTestResultDetail {} + } + + It 'checks malware controls on the effective anti-malware policy for all recipients' { + $script:exoResponses = @{ + MalwareFilterPolicy = @( + [pscustomobject]@{ + Identity = 'Strict Preset Security Policy'; RecommendedPolicyType = 'Strict'; IsDefault = $false + EnableFileFilter = $true; FileTypes = @('exe', 'cmd', 'vbe'); ZapEnabled = $true + }, + [pscustomobject]@{ + Identity = 'Scoped'; RecommendedPolicyType = 'Custom'; IsDefault = $false + EnableFileFilter = $true; FileTypes = @('exe', 'cmd', 'vbe'); ZapEnabled = $true + }, + [pscustomobject]@{ + Identity = 'Default'; RecommendedPolicyType = 'Custom'; IsDefault = $true + EnableFileFilter = $false; FileTypes = @(); ZapEnabled = $false + } + ) + MalwareFilterRule = @() + EOPProtectionPolicyRule = @( + [pscustomobject]@{ + Identity = 'Strict Preset Security Policy'; State = 'Enabled' + SentTo = @(); SentToMemberOf = @(); RecipientDomainIs = @() + } + ) + AcceptedDomain = @([pscustomobject]@{ DomainName = 'contoso.com' }) + } + Mock Get-MtExo { $script:exoResponses[$Request] } + + Test-MtCisaBlockExecutable | Should -BeTrue + Test-MtCisaMalwareZap | Should -BeTrue + + $script:exoResponses.MalwareFilterPolicy[0].FileTypes = @('exe', 'cmd') + $script:exoResponses.MalwareFilterPolicy[0].ZapEnabled = $false + Test-MtCisaBlockExecutable | Should -BeFalse + Test-MtCisaMalwareZap | Should -BeFalse + + $script:exoResponses.EOPProtectionPolicyRule[0].State = 'Disabled' + $script:exoResponses.MalwareFilterPolicy[0].FileTypes = @('exe', 'cmd', 'vbe') + $script:exoResponses.MalwareFilterPolicy[0].ZapEnabled = $true + $script:exoResponses.MalwareFilterRule = @( + [pscustomobject]@{ + Identity = 'Scoped'; MalwareFilterPolicy = 'Scoped'; State = 'Enabled'; Priority = 1 + SentTo = @('user@contoso.com'); SentToMemberOf = @(); ExceptIfSentTo = @() + ExceptIfSentToMemberOf = @(); ExceptIfRecipientDomainIs = @(); RecipientDomainIs = @() + }, + [pscustomobject]@{ + Identity = 'All recipients'; MalwareFilterPolicy = 'All recipients'; State = 'Enabled'; Priority = 2 + SentTo = @(); SentToMemberOf = @(); ExceptIfSentTo = @() + ExceptIfSentToMemberOf = @(); ExceptIfRecipientDomainIs = @(); RecipientDomainIs = @('contoso.com') + } + ) + $script:exoResponses.MalwareFilterPolicy += [pscustomobject]@{ + Identity = 'All recipients'; RecommendedPolicyType = 'Custom'; IsDefault = $false + EnableFileFilter = $false; FileTypes = @('exe', 'cmd'); ZapEnabled = $false + } + $allRecipientsPolicy = $script:exoResponses.MalwareFilterPolicy | Where-Object { $_.Identity -eq 'All recipients' } + + Test-MtCisaBlockExecutable | Should -BeFalse + Test-MtCisaMalwareZap | Should -BeFalse + + $script:exoResponses.MalwareFilterRule[0].State = 'Disabled' + $allRecipientsPolicy.EnableFileFilter = $true + $allRecipientsPolicy.FileTypes = @('exe', 'cmd', 'vbe') + $allRecipientsPolicy.ZapEnabled = $true + $script:exoResponses.AcceptedDomain = @() + Test-MtCisaBlockExecutable | Should -BeFalse + Test-MtCisaMalwareZap | Should -BeFalse + $script:exoResponses.AcceptedDomain = @([pscustomobject]@{ DomainName = 'contoso.com' }) + + Test-MtCisaBlockExecutable | Should -BeTrue + Test-MtCisaMalwareZap | Should -BeTrue + } + + It 'prefers the Strict preset and falls back to the Standard preset' { + $script:exoResponses = @{ + MalwareFilterPolicy = @( + [pscustomobject]@{ Identity = 'Strict Preset Security Policy' }, + [pscustomobject]@{ Identity = 'Standard Preset Security Policy' }, + [pscustomobject]@{ Identity = 'Default'; IsDefault = $true } + ) + MalwareFilterRule = @() + EOPProtectionPolicyRule = @( + [pscustomobject]@{ + Identity = 'Strict Preset Security Policy'; State = 'Enabled' + SentTo = @(); SentToMemberOf = @(); RecipientDomainIs = @() + }, + [pscustomobject]@{ + Identity = 'Standard Preset Security Policy'; State = 'Enabled' + SentTo = @(); SentToMemberOf = @(); RecipientDomainIs = @() + } + ) + AcceptedDomain = @([pscustomobject]@{ DomainName = 'contoso.com' }) + } + Mock Get-MtExo { $script:exoResponses[$Request] } + + (Get-MtCisaEffectiveAntiMalwarePolicy).Identity | Should -Be 'Strict Preset Security Policy' + + $script:exoResponses.EOPProtectionPolicyRule[0].State = 'Disabled' + (Get-MtCisaEffectiveAntiMalwarePolicy).Identity | Should -Be 'Standard Preset Security Policy' + } + + It 'selects preset policies only when their rules cover every tenant recipient' { + $script:exoResponses = @{ + MalwareFilterPolicy = @( + [pscustomobject]@{ Identity = 'Strict Preset Security Policy'; IsDefault = $false }, + [pscustomobject]@{ Identity = 'Standard Preset Security Policy'; IsDefault = $false }, + [pscustomobject]@{ Identity = 'Default'; IsDefault = $true } + ) + MalwareFilterRule = @() + EOPProtectionPolicyRule = @( + [pscustomobject]@{ + Identity = 'Strict Preset Security Policy'; State = 'Enabled' + SentTo = @(); SentToMemberOf = @(); ExceptIfSentTo = @('user@contoso.com') + ExceptIfSentToMemberOf = @(); ExceptIfRecipientDomainIs = @(); RecipientDomainIs = @() + }, + [pscustomobject]@{ + Identity = 'Standard Preset Security Policy'; State = 'Enabled' + SentTo = @(); SentToMemberOf = @(); ExceptIfSentTo = @() + ExceptIfSentToMemberOf = @(); ExceptIfRecipientDomainIs = @() + RecipientDomainIs = @('contoso.com', 'fabrikam.com') + } + ) + AcceptedDomain = @( + [pscustomobject]@{ DomainName = 'contoso.com' } + [pscustomobject]@{ DomainName = 'fabrikam.com' } + ) + } + Mock Get-MtExo { $script:exoResponses[$Request] } + + (Get-MtCisaEffectiveAntiMalwarePolicy).Identity | Should -Be 'Standard Preset Security Policy' + + $script:exoResponses.EOPProtectionPolicyRule[1].RecipientDomainIs = @('contoso.com') + (Get-MtCisaEffectiveAntiMalwarePolicy).Identity | Should -Be 'Default' + } + + It 'checks the global SharePoint, OneDrive, and Teams Safe Attachments setting' { + Mock Test-ORCA158 { $true } + Test-MtCisaSafeAttachmentsForSharePoint | Should -BeTrue + Should -Invoke Test-ORCA158 -Times 1 -Exactly + + Mock Test-ORCA158 { $false } + Test-MtCisaSafeAttachmentsForSharePoint | Should -BeFalse + + Mock Test-ORCA158 { $null } + $result = Test-MtCisaSafeAttachmentsForSharePoint + $result | Should -BeNullOrEmpty + Should -Invoke Test-ORCA158 -Times 3 -Exactly + } + + It 'uses the highest-priority enabled Safe Attachments rule before checking its recipient scope' { + $script:exoResponses = @{ + SafeAttachmentPolicy = @( + [pscustomobject]@{ Identity = 'All domains'; Name = 'All domains'; Action = 'DynamicDelivery' } + ) + ATPProtectionPolicyRule = @() + SafeAttachmentRule = @( + [pscustomobject]@{ + State = 'Enabled'; Priority = 1; SafeAttachmentPolicy = 'Targeted' + SentTo = @('user@contoso.com'); SentToMemberOf = @(); ExceptIfSentTo = @(); ExceptIfSentToMemberOf = @() + ExceptIfRecipientDomainIs = @(); RecipientDomainIs = @() + }, + [pscustomobject]@{ + State = 'Enabled'; Priority = 2; SafeAttachmentPolicy = 'All domains' + SentTo = @(); SentToMemberOf = @(); ExceptIfSentTo = @(); ExceptIfSentToMemberOf = @() + ExceptIfRecipientDomainIs = @(); RecipientDomainIs = @('contoso.com') + } + ) + ATPBuiltInProtectionRule = @() + AcceptedDomain = @([pscustomobject]@{ Name = 'contoso.com' }) + } + Mock Get-MtExo { $script:exoResponses[$Request] } + + Test-MtCisaSafeAttachment | Should -BeFalse + + $script:exoResponses.SafeAttachmentRule[0].State = 'Disabled' + Test-MtCisaSafeAttachment | Should -BeTrue + } +} diff --git a/powershell/tests/functions/engine/Frameworks.Tests.ps1 b/powershell/tests/functions/engine/Frameworks.Tests.ps1 index 06a6372fd8..a70043fe8b 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