Repository navigation
fix(MT.1087): no pass when the hunting query returned nothing at all #2702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
merill
merged 3 commits into
maester365:main
from
earbona23:fix/mt1087-false-pass-on-unreadable-source
Nov 8, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
powershell/tests/functions/Test-MtXspmPublicRemotelyExploitableHighExposureDevices.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| Describe 'MT.1087 public exposed devices with a remotely exploitable CVE' { | ||
| BeforeAll { | ||
| Import-Module $PSScriptRoot/../../Maester.psd1 -Force | ||
| . "$PSScriptRoot/../helpers/Use-MtModuleFunction.ps1" | ||
| # The check is a native test, so the function is not exported. | ||
| Use-MtModuleFunction -Name Test-MtXspmPublicRemotelyExploitableHighExposureDevices | ||
| } | ||
|
|
||
| BeforeEach { | ||
| $script:TestResult = $null | ||
| $script:SkippedBecause = $null | ||
|
|
||
| Mock -ModuleName Maester Get-MtLicenseInformation { return $true } | ||
| Mock -ModuleName Maester Add-MtTestResultDetail { | ||
| param($Result, $SkippedBecause) | ||
|
|
||
| $script:TestResult = $Result | ||
| $script:SkippedBecause = $SkippedBecause | ||
| } | ||
| } | ||
|
|
||
| It 'skips instead of passing when Defender has no vulnerability data for the tenant' { | ||
| # Invoke-MtGraphSecurityQuery returns nothing both when no device matches and when the query | ||
| # could not run, so an empty result alone used to be the pass. Zero exposed devices out of | ||
| # zero assessed devices is not a pass. | ||
| Mock -ModuleName Maester Invoke-MtGraphSecurityQuery { | ||
| if ($Query -match 'summarize AssessedDeviceCount') { | ||
| return @([pscustomobject]@{ AssessedDeviceCount = 0 }) | ||
| } | ||
| return @() | ||
| } | ||
|
|
||
| $null -eq (Test-MtXspmPublicRemotelyExploitableHighExposureDevices) | Should -BeTrue | ||
| $script:SkippedBecause | Should -Be 'NotApplicable' | ||
| } | ||
|
|
||
| It 'passes a clean fleet, because the denominator comes from the inventory' { | ||
| # The mock honours the semantics of each table instead of matching on the summarize clause: | ||
| # a fleet that is assessed but has nothing vulnerable has rows in the inventory and none in | ||
| # DeviceTvmSoftwareVulnerabilities. Reading the denominator from the vulnerabilities table | ||
| # returned zero here and skipped the tenant that most deserves to pass, so this case fails | ||
| # against the previous query. | ||
| Mock -ModuleName Maester Invoke-MtGraphSecurityQuery { | ||
| # The denominator query is identified by its summarize clause first, because the main | ||
| # exposure query also names DeviceTvmSoftwareVulnerabilities. Only then does the table | ||
| # decide the answer: inventory has the assessed fleet, the vulnerabilities table has | ||
| # nothing because nothing is vulnerable. | ||
| if ($Query -match 'summarize AssessedDeviceCount') { | ||
| if ($Query -match 'DeviceTvmSoftwareInventory') { return @([pscustomobject]@{ AssessedDeviceCount = 120 }) } | ||
| return @([pscustomobject]@{ AssessedDeviceCount = 0 }) | ||
| } | ||
| return @() | ||
| } | ||
|
|
||
| Test-MtXspmPublicRemotelyExploitableHighExposureDevices | Should -BeTrue | ||
| $script:TestResult | Should -Match 'Well done' | ||
| $script:SkippedBecause | Should -BeNullOrEmpty | ||
| } | ||
|
|
||
| It 'passes when the fleet is assessed and no device is exposed' { | ||
| Mock -ModuleName Maester Invoke-MtGraphSecurityQuery { | ||
| if ($Query -match 'summarize AssessedDeviceCount') { | ||
| return @([pscustomobject]@{ AssessedDeviceCount = 120 }) | ||
| } | ||
| return @() | ||
| } | ||
|
|
||
| Test-MtXspmPublicRemotelyExploitableHighExposureDevices | Should -BeTrue | ||
| $script:TestResult | Should -Match 'Well done' | ||
| $script:SkippedBecause | Should -BeNullOrEmpty | ||
| } | ||
|
|
||
| It 'renders no placeholder on the pass path' { | ||
| # The markdown accumulator used to be assigned only on the failure path while the -replace | ||
| # consumed it either way. | ||
| Mock -ModuleName Maester Invoke-MtGraphSecurityQuery { | ||
| if ($Query -match 'summarize AssessedDeviceCount') { | ||
| return @([pscustomobject]@{ AssessedDeviceCount = 5 }) | ||
| } | ||
| return @() | ||
| } | ||
|
|
||
| $null = Test-MtXspmPublicRemotelyExploitableHighExposureDevices | ||
| $script:TestResult | Should -Not -Match '%TestResult%' | ||
| } | ||
|
|
||
| It 'fails and lists the devices when any is exposed' { | ||
| Mock -ModuleName Maester Invoke-MtGraphSecurityQuery { | ||
| if ($Query -match 'summarize AssessedDeviceCount') { | ||
| return @([pscustomobject]@{ AssessedDeviceCount = 120 }) | ||
| } | ||
| return @([pscustomobject]@{ | ||
| DeviceName = 'web-01' | ||
| MaxEpssScore = 0.72 | ||
| MaxCvssScore = 9.8 | ||
| CveList = @('CVE-2026-0001', 'CVE-2026-0002') | ||
| PublicOpenPortList = @(443, 8080) | ||
| }) | ||
| } | ||
|
|
||
| Test-MtXspmPublicRemotelyExploitableHighExposureDevices | Should -BeFalse | ||
| $script:TestResult | Should -Match 'web-01' | ||
| $script:TestResult | Should -Match 'CVE-2026-0001, CVE-2026-0002' | ||
| $script:TestResult | Should -Not -Match '%TestResult%' | ||
| } | ||
|
|
||
| It 'does not ask for the denominator when devices were already found' { | ||
| # The second query is only the tie-breaker for an empty result; a populated result must not | ||
| # pay for it. | ||
| Mock -ModuleName Maester Invoke-MtGraphSecurityQuery { | ||
| @([pscustomobject]@{ DeviceName = 'web-01'; CveList = @('CVE-2026-0003'); PublicOpenPortList = @(443) }) | ||
| } | ||
|
|
||
| $null = Test-MtXspmPublicRemotelyExploitableHighExposureDevices | ||
| Should -Invoke -ModuleName Maester Invoke-MtGraphSecurityQuery -Times 1 -Exactly | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.