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/Maester.psm1 b/powershell/Maester.psm1 index f5b0d45188..8995f3a98e 100644 --- a/powershell/Maester.psm1 +++ b/powershell/Maester.psm1 @@ -32,6 +32,10 @@ $__MtSession = @{ SpoCache = @{} # Cache for SharePoint Online tenant settings retrieved via PnP FabricCache = @{} # Fabric admin API data cached for the current test run GitHubCache = @{} # Per-session REST response cache; cleared each Invoke-Maester run + TeamsCache = @{} # Teams admin API data cached for the current test run + TeamsAuthCache = @{} # Teams unified settings MSAL client; retained until disconnect + TeamsUseDeviceCode = $false # Whether Connect-Maester requested device-code authentication + TeamsEnvironmentName = $null # Explicit Teams PowerShell environment, when provided ADCache = @{} # Active Directory data cache ADConnection = $null # Active Directory connection state ADCredential = $null # Active Directory credential retained only for the connected session 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..90cbf1781d --- /dev/null +++ b/powershell/internal/checks/cisa/exchange/Get-MtCisaEffectiveAntiMalwarePolicy.ps1 @@ -0,0 +1,77 @@ +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 + (& $isEmpty $_.SentTo) -and + (& $isEmpty $_.SentToMemberOf) -and + (& $isEmpty $_.RecipientDomainIs) + } | 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/internal/checks/cisa/teams/TeamsChecks.ps1 b/powershell/internal/checks/cisa/teams/TeamsChecks.ps1 new file mode 100644 index 0000000000..a4c71576e2 --- /dev/null +++ b/powershell/internal/checks/cisa/teams/TeamsChecks.ps1 @@ -0,0 +1,153 @@ +function Get-MtCisaTeamsMeetingPolicies { + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'The Teams cmdlet returns a collection of meeting policies.')] + param( + [switch]$GlobalOnly + ) + + $policies = if ($GlobalOnly) { + @(Get-CsTeamsMeetingPolicy -Identity Global -ErrorAction Stop) + } else { + @(Get-CsTeamsMeetingPolicy -ErrorAction Stop) + } + + if ($policies.Count -eq 0) { + throw 'Teams returned no meeting policies.' + } + if ($GlobalOnly -and ($policies.Count -ne 1 -or $policies[0].Identity -ne 'Global')) { + throw 'Teams did not return exactly one Global meeting policy.' + } + + return $policies +} + +function Test-MtCisaTeamsMeetingPolicyBoolean { + [CmdletBinding()] + param( + [Parameter(Mandatory)] + [string]$SettingName, + [Parameter(Mandatory)] + [bool]$ExpectedValue, + [Parameter(Mandatory)] + [string]$PolicyDescription + ) + + $policies = Get-MtCisaTeamsMeetingPolicies + $results = foreach ($policy in $policies) { + $setting = $policy.PSObject.Properties[$SettingName] + if ($null -eq $setting -or $setting.Value -isnot [bool]) { + throw "Teams meeting policy '$($policy.Identity)' did not return a Boolean value for $SettingName." + } + + [pscustomobject]@{ + Policy = $policy.Identity + Value = $setting.Value + Pass = $setting.Value -eq $ExpectedValue + } + } + + $passed = @($results | Where-Object { -not $_.Pass }).Count -eq 0 + $markdown = if ($passed) { + "Well done. $PolicyDescription is configured for every meeting policy.`n`n" + } else { + "$PolicyDescription is not configured for every meeting policy.`n`n" + } + $markdown += "| Policy | $SettingName | Result |`n| --- | --- | --- |`n" + foreach ($row in $results) { + $markdown += "| $($row.Policy) | $($row.Value) | $(if ($row.Pass) { 'Pass' } else { 'Fail' }) |`n" + } + Add-MtTestResultDetail -Result $markdown.TrimEnd() + return $passed +} + +function Get-MtCisaTeamsGlobalMeetingPolicy { + [CmdletBinding()] + param() + + $policies = Get-MtCisaTeamsMeetingPolicies -GlobalOnly + return $policies[0] +} + +function Get-MtCisaTeamsFederationConfiguration { + [CmdletBinding()] + param() + + $configurations = @(Get-CsTenantFederationConfiguration -ErrorAction Stop) + if ($configurations.Count -ne 1) { + throw 'Teams did not return exactly one tenant federation configuration.' + } + return $configurations[0] +} + +function Test-MtCisaTeamsIsUSGovernment { + [CmdletBinding()] + param() + + $context = Get-MgContext -ErrorAction Stop + if (-not $context) { + throw 'A Microsoft Graph context is required to determine the Teams environment.' + } + return ($context.Environment -in @('USGov', 'USGovDoD') -or + $__MtSession.TeamsEnvironmentName -in @('TeamsGCCH', 'TeamsDOD')) +} + +function Test-MtCisaTeamsAppControl { + [CmdletBinding()] + param( + [Parameter(Mandatory)] + [ValidateSet('DefaultApp', 'GlobalApp', 'PrivateApp')] + [string]$SettingName, + [Parameter(Mandatory)] + [string]$AppType + ) + + $settings = @(Get-MtTeamsUnifiedTenantSettings) + $setting = $settings | Where-Object { $_.SettingName -eq $SettingName } | Select-Object -First 1 + $policyProperty = switch ($SettingName) { + 'DefaultApp' { 'DefaultCatalogAppsType' } + 'GlobalApp' { 'GlobalCatalogAppsType' } + 'PrivateApp' { 'PrivateCatalogAppsType' } + } + + $rows = @() + if ($setting) { + $value = [string]$setting.SettingValue + $passed = $value -eq 'None' + $rows += [pscustomobject]@{ + Policy = 'Org-wide setting' + Value = $value + Pass = $passed + } + } else { + $policies = @(Get-CsTeamsAppPermissionPolicy -ErrorAction Stop) + if ($policies.Count -eq 0) { + throw 'Teams returned no app permission policies.' + } + + $rows = foreach ($policy in $policies) { + $type = $policy.PSObject.Properties[$policyProperty] + if ($null -eq $type -or $type.Value -notin @('AllowedAppList', 'BlockedAppList')) { + throw "Teams app permission policy '$($policy.Identity)' did not return a supported value for $policyProperty." + } + + [pscustomobject]@{ + Policy = $policy.Identity + Value = $type.Value + Pass = $type.Value -eq 'AllowedAppList' + } + } + $passed = @($rows | Where-Object { -not $_.Pass }).Count -eq 0 + } + + $markdown = if ($passed) { + "Well done. $AppType apps are restricted to the approved set.`n`n" + } else { + "$AppType apps are not restricted to the approved set.`n`n" + } + $markdown += "| Policy or setting | Value | Result |`n| --- | --- | --- |`n" + foreach ($row in $rows) { + $markdown += "| $($row.Policy) | $($row.Value) | $(if ($row.Pass) { 'Pass' } else { 'Fail' }) |`n" + } + Add-MtTestResultDetail -Result $markdown.TrimEnd() + return $passed +} diff --git a/powershell/internal/services/teams/Get-MtTeamsUnifiedTenantSettings.ps1 b/powershell/internal/services/teams/Get-MtTeamsUnifiedTenantSettings.ps1 new file mode 100644 index 0000000000..19ae99a930 --- /dev/null +++ b/powershell/internal/services/teams/Get-MtTeamsUnifiedTenantSettings.ps1 @@ -0,0 +1,133 @@ +function Get-MtTeamsUnifiedTenantSettings { + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'The Teams API returns a collection of settings.')] + param() + + $context = Get-MgContext -ErrorAction Stop + if (-not $context) { + throw 'A Microsoft Graph context is required to retrieve Teams unified app settings.' + } + + $tenantId = [string]$context.TenantId + if ([string]::IsNullOrWhiteSpace($tenantId)) { + throw 'The Microsoft Graph context does not include a tenant ID.' + } + + if (($context.Environment -and $context.Environment -ne 'Global') -or + $__MtSession.TeamsEnvironmentName -in @('TeamsChina', 'TeamsGCCH', 'TeamsDOD')) { + return $null + } + if ($context.AuthType -ne 'Delegated') { + return $null + } + + $cacheKey = "UnifiedAppSettings:$tenantId" + if ($__MtSession.TeamsCache.ContainsKey($cacheKey)) { + return $__MtSession.TeamsCache[$cacheKey] + } + + $accessToken = Get-MtTeamsUnifiedSettingsAccessToken -Context $context + $response = Invoke-RestMethod ` + -Uri 'https://substrate.office.com/AdminAppCatalog/ps/v2/admin/unifiedApp/settings' ` + -Method Get ` + -Headers @{ Authorization = "Bearer $accessToken" } ` + -ErrorAction Stop + + if ($null -eq $response) { + throw 'The Teams unified app settings API returned an empty response.' + } + + $settings = if ($response.PSObject.Properties['value']) { + @($response.value) + } else { + @($response) + } + + foreach ($setting in $settings) { + if ($null -eq $setting -or + $null -eq $setting.PSObject.Properties['SettingName'] -or + $null -eq $setting.PSObject.Properties['SettingValue']) { + throw 'The Teams unified app settings API returned a setting without SettingName or SettingValue.' + } + } + + $__MtSession.TeamsCache[$cacheKey] = $settings + return $settings +} + +function Get-MtTeamsUnifiedSettingsAccessToken { + [CmdletBinding()] + param( + [Parameter(Mandatory)] + [object]$Context + ) + + $tenantId = [string]$Context.TenantId + $clientId = '12128f48-ec9e-42f0-b203-ea49fb6af367' + $scope = @('08ff1ce2-4973-4b08-86a3-ebed13badc7f/.default') + $authority = "https://login.microsoftonline.com/$tenantId" + $cacheKey = "$tenantId|$($Context.Environment)" + + if (-not ('Microsoft.Identity.Client.PublicClientApplicationBuilder' -as [type])) { + $authenticationModule = Get-Module Microsoft.Graph.Authentication | Sort-Object Version -Descending | Select-Object -First 1 + if (-not $authenticationModule) { + throw 'Microsoft.Graph.Authentication must be loaded before acquiring a Teams unified settings token.' + } + + $dependencyFolder = if ($PSVersionTable.PSEdition -eq 'Core') { 'Core' } else { 'Desktop' } + $msalPath = Join-Path $authenticationModule.ModuleBase "Dependencies\$dependencyFolder\Microsoft.Identity.Client.dll" + if (-not (Test-Path -LiteralPath $msalPath)) { + throw "Microsoft.Identity.Client.dll was not found at '$msalPath'." + } + $null = Add-Type -Path $msalPath -ErrorAction Stop + } + + if (-not $__MtSession.TeamsAuthCache.ContainsKey('Clients')) { + $__MtSession.TeamsAuthCache['Clients'] = @{} + } + + $clients = $__MtSession.TeamsAuthCache['Clients'] + if (-not $clients.ContainsKey($cacheKey)) { + $clients[$cacheKey] = [Microsoft.Identity.Client.PublicClientApplicationBuilder]::Create($clientId). + WithAuthority($authority). + WithRedirectUri('http://localhost'). + Build() + } + $application = $clients[$cacheKey] + + $accounts = @($application.GetAccountsAsync().GetAwaiter().GetResult()) + $account = $null + if ($Context.Account) { + $account = $accounts | Where-Object { $_.Username -eq [string]$Context.Account } | Select-Object -First 1 + } + + $result = $null + if ($account) { + try { + $result = $application.AcquireTokenSilent($scope, $account).ExecuteAsync().GetAwaiter().GetResult() + } catch [Microsoft.Identity.Client.MsalUiRequiredException] { + Write-Verbose 'Silent token acquisition requires user interaction.' + } + } + + if (-not $result -and $__MtSession.TeamsUseDeviceCode) { + $deviceCodeCallback = [System.Func[Microsoft.Identity.Client.DeviceCodeResult, System.Threading.Tasks.Task]] { + param($deviceCode) + Write-Information $deviceCode.Message -InformationAction Continue + [System.Threading.Tasks.Task]::CompletedTask + } + $result = $application.AcquireTokenWithDeviceCode($scope, $deviceCodeCallback).ExecuteAsync().GetAwaiter().GetResult() + } elseif (-not $result) { + $interactiveRequest = $application.AcquireTokenInteractive($scope).WithUseEmbeddedWebView($false) + if ($Context.Account) { + $interactiveRequest = $interactiveRequest.WithLoginHint([string]$Context.Account) + } + $result = $interactiveRequest.ExecuteAsync().GetAwaiter().GetResult() + } + + if (-not $result -or [string]::IsNullOrWhiteSpace($result.AccessToken)) { + throw 'Microsoft identity platform returned no access token for Teams unified app settings.' + } + + return $result.AccessToken +} diff --git a/powershell/internal/session/Clear-ModuleVariable.ps1 b/powershell/internal/session/Clear-ModuleVariable.ps1 index 2817a52795..9b220a878a 100644 --- a/powershell/internal/session/Clear-ModuleVariable.ps1 +++ b/powershell/internal/session/Clear-ModuleVariable.ps1 @@ -33,6 +33,7 @@ $__MtSession.GitHubCache = @{} $__MtSession.SpoCache = @{} $__MtSession.FabricCache = @{} + $__MtSession.TeamsCache = @{} $__MtSession.Console = $null $__MtSession.ReportAttachments = $null # $__MtSession.Connections = @() # Do not clear connections as they are used to track the connection state. This module variable should only be set by Connect-Maester and Disconnect-Maester. diff --git a/powershell/public/connect/Connect-Maester.ps1 b/powershell/public/connect/Connect-Maester.ps1 index caaf7c4efc..0295cbe177 100644 --- a/powershell/public/connect/Connect-Maester.ps1 +++ b/powershell/public/connect/Connect-Maester.ps1 @@ -554,6 +554,8 @@ 'MicrosoftTeams' { if ($Service -contains 'Teams' -or $Service -contains 'All') { + $__MtSession.TeamsUseDeviceCode = $UseDeviceCode.IsPresent + $__MtSession.TeamsEnvironmentName = $TeamsEnvironmentName Write-Verbose 'Connecting to Microsoft Teams' try { $teamsParams = @{ ErrorAction = 'Stop' } diff --git a/powershell/public/connect/Disconnect-Maester.ps1 b/powershell/public/connect/Disconnect-Maester.ps1 index 3e183aa42c..e8d5405b66 100644 --- a/powershell/public/connect/Disconnect-Maester.ps1 +++ b/powershell/public/connect/Disconnect-Maester.ps1 @@ -71,6 +71,11 @@ } if ($MyInvocation.InvocationName -notmatch '(^|\\)Disconnect-MtGraph$') { + $__MtSession.TeamsCache = @{} + $__MtSession.TeamsAuthCache = @{} + $__MtSession.TeamsUseDeviceCode = $false + $__MtSession.TeamsEnvironmentName = $null + # The service list can be replaced by another Connect-Maester call. Clean up a loaded # ADOPS session too, without importing an optional module just to disconnect it. try { 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/CisaTeamsChecks.Tests.ps1 b/powershell/tests/functions/CisaTeamsChecks.Tests.ps1 new file mode 100644 index 0000000000..287eb3becf --- /dev/null +++ b/powershell/tests/functions/CisaTeamsChecks.Tests.ps1 @@ -0,0 +1,164 @@ +BeforeAll { + Import-Module "$PSScriptRoot/../../Maester.psd1" -Force + + $script:createdTeamsStubs = @() + $teamsStubs = @{ + 'Get-CsTeamsMeetingPolicy' = { + [CmdletBinding()] + param([string]$Identity) + $null = $PSBoundParameters + } + 'Get-CsTeamsAppPermissionPolicy' = { + [CmdletBinding()] + param([string]$Identity) + $null = $PSBoundParameters + } + 'Get-CsTenantFederationConfiguration' = { + [CmdletBinding()] + param() + } + 'Get-CsTeamsMeetingBroadcastPolicy' = { + [CmdletBinding()] + param([string]$Identity) + $null = $PSBoundParameters + } + 'Get-CsTeamsClientConfiguration' = { + [CmdletBinding()] + param([string]$Identity) + $null = $PSBoundParameters + } + } + foreach ($name in $teamsStubs.Keys) { + if (-not (Get-Command $name -ErrorAction SilentlyContinue)) { + Set-Item -Path "Function:global:$name" -Value $teamsStubs[$name] + $script:createdTeamsStubs += $name + } + } +} + +AfterAll { + foreach ($name in $script:createdTeamsStubs) { + Remove-Item -Path "Function:global:$name" -ErrorAction SilentlyContinue + } +} + +Describe 'CISA Teams checks' { + BeforeEach { + InModuleScope Maester { + $__MtSession.TeamsCache = @{} + } + Mock Add-MtTestResultDetail -ModuleName Maester {} + } + + It 'Checks every meeting policy for a Boolean setting' { + Mock Get-CsTeamsMeetingPolicy -ModuleName Maester { + @( + [pscustomobject]@{ Identity = 'Global'; AllowAnonymousUsersToStartMeeting = $false } + [pscustomobject]@{ Identity = 'Custom'; AllowAnonymousUsersToStartMeeting = $false } + ) + } + + InModuleScope Maester { + Test-MtCisaTeamsMeetingPolicyBoolean -SettingName AllowAnonymousUsersToStartMeeting -ExpectedValue $false -PolicyDescription 'Anonymous meeting start' | Should -BeTrue + } + Should -Invoke Get-CsTeamsMeetingPolicy -ModuleName Maester -Times 1 -Exactly + } + + It 'Fails a meeting policy when the setting differs from the baseline' { + Mock Get-CsTeamsMeetingPolicy -ModuleName Maester { + @( + [pscustomobject]@{ Identity = 'Global'; AllowAnonymousUsersToStartMeeting = $false } + [pscustomobject]@{ Identity = 'Custom'; AllowAnonymousUsersToStartMeeting = $true } + ) + } + + InModuleScope Maester { + Test-MtCisaTeamsMeetingPolicyBoolean -SettingName AllowAnonymousUsersToStartMeeting -ExpectedValue $false -PolicyDescription 'Anonymous meeting start' | Should -BeFalse + } + } + + It 'Errors when a meeting policy does not return the checked setting' { + Mock Get-CsTeamsMeetingPolicy -ModuleName Maester { + [pscustomobject]@{ Identity = 'Global' } + } + + { InModuleScope Maester { Test-MtCisaTeamsMeetingPolicyBoolean -SettingName AllowAnonymousUsersToStartMeeting -ExpectedValue $false -PolicyDescription 'Anonymous meeting start' } } | Should -Throw '*did not return a Boolean value*' + } + + It 'Passes external federation when disabled' { + Mock Get-MtCisaTeamsFederationConfiguration -ModuleName Maester { + [pscustomobject]@{ AllowFederatedUsers = $false } + } + + InModuleScope Maester { + Test-MtCisaTeamsExternalAccessScope | Should -BeTrue + } + } + + It 'Fails external federation when all known domains are allowed' { + Mock Get-MtCisaTeamsFederationConfiguration -ModuleName Maester { + $domains = [pscustomobject]@{} + $domains.PSObject.TypeNames.Insert(0, 'AllowAllKnownDomains') + [pscustomobject]@{ + AllowFederatedUsers = $true + AllowedDomains = $domains + } + } + + InModuleScope Maester { + Test-MtCisaTeamsExternalAccessScope | Should -BeFalse + } + } + + It 'Passes external federation when only configured domains are allowed' { + Mock Get-MtCisaTeamsFederationConfiguration -ModuleName Maester { + [pscustomobject]@{ + AllowFederatedUsers = $true + AllowedDomains = [pscustomobject]@{ AllowedDomain = @('contoso.com') } + } + } + + InModuleScope Maester { + Test-MtCisaTeamsExternalAccessScope | Should -BeTrue + } + } + + It 'Uses an available unified org-wide app setting instead of legacy policies' { + Mock Get-MtTeamsUnifiedTenantSettings -ModuleName Maester { + @([pscustomobject]@{ SettingName = 'GlobalApp'; SettingValue = 'None' }) + } + Mock Get-CsTeamsAppPermissionPolicy -ModuleName Maester { throw 'Legacy policies should not be queried.' } + + InModuleScope Maester { + Test-MtCisaTeamsAppControl -SettingName GlobalApp -AppType Third-party | Should -BeTrue + } + Should -Invoke Get-CsTeamsAppPermissionPolicy -ModuleName Maester -Times 0 -Exactly + } + + It 'Fails an available unified org-wide app setting that is not None' { + Mock Get-MtTeamsUnifiedTenantSettings -ModuleName Maester { + @([pscustomobject]@{ SettingName = 'PrivateApp'; SettingValue = 'All' }) + } + Mock Get-CsTeamsAppPermissionPolicy -ModuleName Maester { throw 'Legacy policies should not be queried.' } + + InModuleScope Maester { + Test-MtCisaTeamsAppControl -SettingName PrivateApp -AppType Custom | Should -BeFalse + } + Should -Invoke Get-CsTeamsAppPermissionPolicy -ModuleName Maester -Times 0 -Exactly + } + + It 'Falls back to all legacy app permission policies when the unified setting is unavailable' { + Mock Get-MtTeamsUnifiedTenantSettings -ModuleName Maester { $null } + Mock Get-CsTeamsAppPermissionPolicy -ModuleName Maester { + @( + [pscustomobject]@{ Identity = 'Global'; DefaultCatalogAppsType = 'AllowedAppList' } + [pscustomobject]@{ Identity = 'Custom'; DefaultCatalogAppsType = 'BlockedAppList' } + ) + } + + InModuleScope Maester { + Test-MtCisaTeamsAppControl -SettingName DefaultApp -AppType Microsoft | Should -BeFalse + } + Should -Invoke Get-CsTeamsAppPermissionPolicy -ModuleName Maester -Times 1 -Exactly + } +} diff --git a/powershell/tests/functions/Clear-ModuleVariable.Tests.ps1 b/powershell/tests/functions/Clear-ModuleVariable.Tests.ps1 index 23afa4bb0b..cd0e63a8b0 100644 --- a/powershell/tests/functions/Clear-ModuleVariable.Tests.ps1 +++ b/powershell/tests/functions/Clear-ModuleVariable.Tests.ps1 @@ -1,4 +1,4 @@ -BeforeAll { +BeforeAll { Import-Module "$PSScriptRoot/../../Maester.psd1" -Force } @@ -9,6 +9,7 @@ Describe 'Clear-ModuleVariable — GitHub session lifecycle' { $__MtSession.GitHubAuthHeader = @{ Authorization = 'Bearer testtoken' } $__MtSession.GitHubCache = @{ somekey = 'cached-value' } } + } AfterEach { @@ -49,3 +50,17 @@ Describe 'Clear-ModuleVariable — GitHub session lifecycle' { } } } + +Describe 'Clear-ModuleVariable - Teams API cache lifecycle' { + It 'Clears per-run Teams settings but preserves the connected MSAL client' { + InModuleScope Maester { + $client = [pscustomobject]@{ Cached = $true } + $__MtSession.TeamsCache = @{ 'UnifiedAppSettings:tenant' = @('setting') } + $__MtSession.TeamsAuthCache = @{ Clients = @{ tenant = $client } } + Clear-ModuleVariable + + $__MtSession.TeamsCache.Count | Should -Be 0 + $__MtSession.TeamsAuthCache.Clients.tenant.Cached | Should -BeTrue + } + } +} diff --git a/powershell/tests/functions/Connect-Maester.Tests.ps1 b/powershell/tests/functions/Connect-Maester.Tests.ps1 index abf3780338..9193f74032 100644 --- a/powershell/tests/functions/Connect-Maester.Tests.ps1 +++ b/powershell/tests/functions/Connect-Maester.Tests.ps1 @@ -1,4 +1,4 @@ -BeforeAll { +BeforeAll { Import-Module "$PSScriptRoot/../../Maester.psd1" -Force # Keep -Service All tests isolated from optional service modules that may not be installed. @@ -303,6 +303,10 @@ Describe 'Connect-Maester connection summary' { Should -Invoke Connect-MicrosoftTeams -ModuleName Maester -Times 1 -Exactly -ParameterFilter { $UseDeviceAuthentication -and $TeamsEnvironmentName -eq 'TeamsGCCH' } + InModuleScope Maester { + $__MtSession.TeamsUseDeviceCode | Should -BeTrue + $__MtSession.TeamsEnvironmentName | Should -Be 'TeamsGCCH' + } } Context 'When an Az context from another tenant already exists' { diff --git a/powershell/tests/functions/Disconnect-Maester.Tests.ps1 b/powershell/tests/functions/Disconnect-Maester.Tests.ps1 index b3eeca9561..635725a78b 100644 --- a/powershell/tests/functions/Disconnect-Maester.Tests.ps1 +++ b/powershell/tests/functions/Disconnect-Maester.Tests.ps1 @@ -1,4 +1,4 @@ -BeforeAll { +BeforeAll { Import-Module "$PSScriptRoot/../../Maester.psd1" -Force } @@ -177,6 +177,7 @@ Describe 'Disconnect-Maester - Active Directory session lifecycle' { Connected = $true DomainController = 'dc01.contoso.com' } + $__MtSession.ADCredential = [PSCredential]::new('CONTOSO\Maester', ([System.Security.SecureString]::new())) $__MtSession.ADCache = @{ DomainState = [PSCustomObject]@{ Domain = 'contoso.com' } } } @@ -216,6 +217,29 @@ Describe 'Disconnect-Maester - Active Directory session lifecycle' { } } +Describe 'Disconnect-Maester - Teams unified settings authentication lifecycle' { + BeforeEach { + Mock Get-Module -ModuleName Maester { $null } -ParameterFilter { $Name -eq 'ADOPS' } + InModuleScope Maester { + $__MtSession.Connections = @() + $__MtSession.TeamsCache = @{ 'UnifiedAppSettings:tenant' = @('stale') } + $__MtSession.TeamsAuthCache = @{ Clients = @{ tenant = 'cached-client' } } + $__MtSession.TeamsUseDeviceCode = $true + $__MtSession.TeamsEnvironmentName = 'TeamsGCCH' + } + } + + It 'Clears the Teams authentication client and device-code preference' { + Disconnect-Maester + InModuleScope Maester { + $__MtSession.TeamsCache.Count | Should -Be 0 + $__MtSession.TeamsAuthCache.Count | Should -Be 0 + $__MtSession.TeamsUseDeviceCode | Should -BeFalse + $__MtSession.TeamsEnvironmentName | Should -BeNullOrEmpty + } + } +} + Describe 'Disconnect-Maester - service disconnects' { BeforeAll { # The Exchange Online and Teams modules are optional; stand in for their commands when they are not installed. diff --git a/powershell/tests/functions/TeamsUnifiedSettings.Tests.ps1 b/powershell/tests/functions/TeamsUnifiedSettings.Tests.ps1 new file mode 100644 index 0000000000..3574152230 --- /dev/null +++ b/powershell/tests/functions/TeamsUnifiedSettings.Tests.ps1 @@ -0,0 +1,110 @@ +BeforeAll { + Import-Module "$PSScriptRoot/../../Maester.psd1" -Force +} + +Describe 'Get-MtTeamsUnifiedTenantSettings' { + BeforeEach { + InModuleScope Maester { + $__MtSession.TeamsCache = @{} + $__MtSession.TeamsAuthCache = @{} + $__MtSession.TeamsEnvironmentName = $null + } + Mock Get-MgContext -ModuleName Maester { + [pscustomobject]@{ + TenantId = '11111111-1111-1111-1111-111111111111' + Environment = 'Global' + AuthType = 'Delegated' + Account = 'admin@contoso.com' + } + } + Mock Get-MtTeamsUnifiedSettingsAccessToken -ModuleName Maester { + 'test-token' + } + Mock Invoke-RestMethod -ModuleName Maester { + @([pscustomobject]@{ SettingName = 'DefaultApp'; SettingValue = 'None' }) + } + } + + It 'Retrieves settings with a delegated token and caches them for the current run' { + $first = InModuleScope Maester { @(Get-MtTeamsUnifiedTenantSettings) } + $second = InModuleScope Maester { @(Get-MtTeamsUnifiedTenantSettings) } + + $first | Should -HaveCount 1 + $first[0].SettingName | Should -Be 'DefaultApp' + $second[0].SettingValue | Should -Be 'None' + Should -Invoke Get-MtTeamsUnifiedSettingsAccessToken -ModuleName Maester -Times 1 -Exactly + Should -Invoke Invoke-RestMethod -ModuleName Maester -Times 1 -Exactly -ParameterFilter { + $Uri -eq 'https://substrate.office.com/AdminAppCatalog/ps/v2/admin/unifiedApp/settings' -and + $Method -eq 'Get' -and + $Headers.Authorization -eq 'Bearer test-token' + } + } + + It 'Uses legacy policies in US Government environments' { + Mock Get-MgContext -ModuleName Maester { + [pscustomobject]@{ + TenantId = '11111111-1111-1111-1111-111111111111' + Environment = 'USGov' + AuthType = 'Delegated' + } + } + + InModuleScope Maester { Get-MtTeamsUnifiedTenantSettings } | Should -BeNullOrEmpty + Should -Invoke Invoke-RestMethod -ModuleName Maester -Times 0 -Exactly + } + + It 'Uses legacy policies in US Government DoD environments' { + Mock Get-MgContext -ModuleName Maester { + [pscustomobject]@{ + TenantId = '11111111-1111-1111-1111-111111111111' + Environment = 'USGovDoD' + AuthType = 'Delegated' + } + } + + InModuleScope Maester { Get-MtTeamsUnifiedTenantSettings } | Should -BeNullOrEmpty + Should -Invoke Invoke-RestMethod -ModuleName Maester -Times 0 -Exactly + } + + It 'Uses legacy policies when Teams is connected to GCC High' { + InModuleScope Maester { + $__MtSession.TeamsEnvironmentName = 'TeamsGCCH' + } + + InModuleScope Maester { Get-MtTeamsUnifiedTenantSettings } | Should -BeNullOrEmpty + Should -Invoke Invoke-RestMethod -ModuleName Maester -Times 0 -Exactly + } + + It 'Uses legacy policies for app-only authentication' { + Mock Get-MgContext -ModuleName Maester { + [pscustomobject]@{ + TenantId = '11111111-1111-1111-1111-111111111111' + Environment = 'Global' + AuthType = 'AppOnly' + } + } + + InModuleScope Maester { Get-MtTeamsUnifiedTenantSettings } | Should -BeNullOrEmpty + Should -Invoke Invoke-RestMethod -ModuleName Maester -Times 0 -Exactly + } + + It 'Throws when the unified settings API returns a malformed setting' { + Mock Invoke-RestMethod -ModuleName Maester { + @([pscustomobject]@{ SettingName = 'DefaultApp' }) + } + + { InModuleScope Maester { Get-MtTeamsUnifiedTenantSettings } } | Should -Throw '*without SettingName or SettingValue*' + } + + It 'Surfaces API request failures instead of silently falling back' { + Mock Invoke-RestMethod -ModuleName Maester { throw 'request failed' } + + { InModuleScope Maester { Get-MtTeamsUnifiedTenantSettings } } | Should -Throw '*request failed*' + } + + It 'Throws when no Graph context is available' { + Mock Get-MgContext -ModuleName Maester { $null } + + { InModuleScope Maester { Get-MtTeamsUnifiedTenantSettings } } | Should -Throw '*Graph context is required*' + } +} diff --git a/powershell/tests/functions/Test-MtCisaSecuritySuiteMalware.Tests.ps1 b/powershell/tests/functions/Test-MtCisaSecuritySuiteMalware.Tests.ps1 new file mode 100644 index 0000000000..693bba9129 --- /dev/null +++ b/powershell/tests/functions/Test-MtCisaSecuritySuiteMalware.Tests.ps1 @@ -0,0 +1,152 @@ +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.AcceptedDomain = @() + Test-MtCisaBlockExecutable | Should -BeFalse + Test-MtCisaMalwareZap | Should -BeFalse + $script:exoResponses.AcceptedDomain = @([pscustomobject]@{ DomainName = 'contoso.com' }) + + $script:exoResponses.MalwareFilterRule[0].State = 'Disabled' + $allRecipientsPolicy.EnableFileFilter = $true + $allRecipientsPolicy.FileTypes = @('exe', 'cmd', 'vbe') + $allRecipientsPolicy.ZapEnabled = $true + 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 '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 + } + + 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..7f125a3936 100644 --- a/powershell/tests/functions/engine/Frameworks.Tests.ps1 +++ b/powershell/tests/functions/engine/Frameworks.Tests.ps1 @@ -1,4 +1,4 @@ -# Benchmarks and framework files (docs/proposals/maester-3.0-test-attributes.md, section 6): the Frameworks a +# Benchmarks and framework files (docs/proposals/maester-3.0-test-attributes.md, section 6): the Frameworks a # suite.json declares, the framework files beside it, the Control that maps a test to a requirement, Benchmark and # Control on a test, on its rows and in the catalog, what the catalog build rejects, and what a run does with a # custom suite whose framework file is wrong. @@ -336,7 +336,7 @@ Describe 'Benchmark of the tests shipped with Maester' { It 'Gives every test a Benchmark of