|
| 1 | +Describe "Test-Assessment-41060" { |
| 2 | + BeforeAll { |
| 3 | + $here = $PSScriptRoot |
| 4 | + $srcRoot = Join-Path $here "../../src/powershell" |
| 5 | + |
| 6 | + # Mock external module dependencies that may not be loaded in the test host |
| 7 | + if (-not (Get-Command Write-PSFMessage -ErrorAction SilentlyContinue)) { |
| 8 | + function Write-PSFMessage { |
| 9 | + } |
| 10 | + } |
| 11 | + if (-not (Get-Command Write-ZtProgress -ErrorAction SilentlyContinue)) { |
| 12 | + function Write-ZtProgress { |
| 13 | + } |
| 14 | + } |
| 15 | + if (-not (Get-Command Invoke-ZtGraphRequest -ErrorAction SilentlyContinue)) { |
| 16 | + function Invoke-ZtGraphRequest { |
| 17 | + param($RelativeUri, $Filter, $ApiVersion, $Top, [switch]$DisablePaging) |
| 18 | + } |
| 19 | + } |
| 20 | + if (-not (Get-Command Add-ZtTestResultDetail -ErrorAction SilentlyContinue)) { |
| 21 | + function Add-ZtTestResultDetail { |
| 22 | + } |
| 23 | + } |
| 24 | + if (-not (Get-Command Get-SafeMarkdown -ErrorAction SilentlyContinue)) { |
| 25 | + function Get-SafeMarkdown { |
| 26 | + param($Text) return $Text |
| 27 | + } |
| 28 | + } |
| 29 | + if (-not (Get-Command Get-FormattedDate -ErrorAction SilentlyContinue)) { |
| 30 | + function Get-FormattedDate { |
| 31 | + param($DateString) return $DateString |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + # Load the class |
| 36 | + $classPath = Join-Path $srcRoot "classes/ZtTest.ps1" |
| 37 | + if (-not ("ZtTest" -as [type])) { |
| 38 | + . $classPath |
| 39 | + } |
| 40 | + |
| 41 | + # Load the SUT |
| 42 | + $sut = Join-Path $srcRoot "tests/Test-Assessment.41060.ps1" |
| 43 | + . $sut |
| 44 | + |
| 45 | + # Setup output file |
| 46 | + $script:outputFile = Join-Path $here "../TestResults/Report-Test-Assessment.41060.md" |
| 47 | + $outputDir = Split-Path $script:outputFile |
| 48 | + if (-not (Test-Path $outputDir)) { |
| 49 | + New-Item -ItemType Directory -Path $outputDir | Out-Null |
| 50 | + } |
| 51 | + "# Test Results for 41060`n" | Set-Content $script:outputFile |
| 52 | + } |
| 53 | + |
| 54 | + BeforeEach { |
| 55 | + Mock Write-PSFMessage {} |
| 56 | + Mock Write-ZtProgress {} |
| 57 | + Mock Get-SafeMarkdown { param($Text) return $Text } |
| 58 | + Mock Get-FormattedDate { param($DateString) return $DateString } |
| 59 | + } |
| 60 | + |
| 61 | + Context "When all pinned cloud-protection controls are fully scored" { |
| 62 | + It "Should pass" { |
| 63 | + # Q1a: the three pinned MDATP Secure Score control profiles, each with a maxScore. |
| 64 | + # Q1b: the latest Secure Score snapshot whose controlScores meet or exceed each maxScore. |
| 65 | + # The mock branches on $RelativeUri to mirror the two Graph calls the test makes. |
| 66 | + Mock Invoke-ZtGraphRequest { |
| 67 | + if ($RelativeUri -eq 'security/secureScoreControlProfiles') { |
| 68 | + return @( |
| 69 | + [PSCustomObject]@{ |
| 70 | + id = 'scid_2016' |
| 71 | + title = 'Turn on cloud-delivered protection in Microsoft Defender Antivirus' |
| 72 | + maxScore = 10 |
| 73 | + lastModifiedDateTime = '2026-06-26T00:00:00Z' |
| 74 | + controlStateUpdates = @() |
| 75 | + }, |
| 76 | + [PSCustomObject]@{ |
| 77 | + id = 'scid_5094' |
| 78 | + title = 'Set cloud-delivered protection to advanced' |
| 79 | + maxScore = 8 |
| 80 | + lastModifiedDateTime = '2026-06-26T00:00:00Z' |
| 81 | + controlStateUpdates = @() |
| 82 | + }, |
| 83 | + [PSCustomObject]@{ |
| 84 | + id = 'scid_6094' |
| 85 | + title = 'Enable cloud protection sample submission' |
| 86 | + maxScore = 9 |
| 87 | + lastModifiedDateTime = '2026-06-26T00:00:00Z' |
| 88 | + controlStateUpdates = @() |
| 89 | + } |
| 90 | + ) |
| 91 | + } |
| 92 | + elseif ($RelativeUri -eq 'security/secureScores') { |
| 93 | + # Shaped like GET /v1.0/security/secureScores?$top=1 (response wrapper with .value). |
| 94 | + return [PSCustomObject]@{ |
| 95 | + '@odata.context' = 'https://graph.microsoft.com/v1.0/$metadata#security/secureScores' |
| 96 | + value = @( |
| 97 | + [PSCustomObject]@{ |
| 98 | + id = '536279f6-15cc-45f2-be2d-61e352b51eef_2026-06-26' |
| 99 | + azureTenantId = '536279f6-15cc-45f2-be2d-61e352b51eef' |
| 100 | + createdDateTime = '2026-06-26T00:00:00Z' |
| 101 | + currentScore = 1032.09 |
| 102 | + maxScore = 1717 |
| 103 | + controlScores = @( |
| 104 | + [PSCustomObject]@{ |
| 105 | + controlCategory = 'Device' |
| 106 | + controlName = 'scid_2016' |
| 107 | + score = 10 |
| 108 | + scoreInPercentage = 100 |
| 109 | + }, |
| 110 | + [PSCustomObject]@{ |
| 111 | + controlCategory = 'Device' |
| 112 | + controlName = 'scid_5094' |
| 113 | + score = 8 |
| 114 | + scoreInPercentage = 100 |
| 115 | + }, |
| 116 | + [PSCustomObject]@{ |
| 117 | + controlCategory = 'Device' |
| 118 | + controlName = 'scid_6094' |
| 119 | + score = 9 |
| 120 | + scoreInPercentage = 100 |
| 121 | + } |
| 122 | + ) |
| 123 | + } |
| 124 | + ) |
| 125 | + } |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + $script:capturedStatus = $null |
| 130 | + $script:capturedResult = $null |
| 131 | + Mock Add-ZtTestResultDetail { |
| 132 | + param($TestId, $Title, $Status, $Result, $CustomStatus) |
| 133 | + $script:capturedStatus = $Status |
| 134 | + $script:capturedResult = $Result |
| 135 | + "## Scenario: All pinned controls fully scored`n`n$Result`n" | Add-Content $script:outputFile |
| 136 | + } |
| 137 | + |
| 138 | + Test-Assessment-41060 |
| 139 | + |
| 140 | + Should -Invoke Add-ZtTestResultDetail -Times 1 -Exactly -ParameterFilter { |
| 141 | + $Status -eq $true |
| 142 | + } |
| 143 | + $script:capturedResult | Should -Match 'Cloud-delivered protection is enabled' |
| 144 | + $script:capturedResult | Should -Match 'scid_2016' |
| 145 | + $script:capturedResult | Should -Match 'scid_5094' |
| 146 | + $script:capturedResult | Should -Match 'scid_6094' |
| 147 | + $script:capturedResult | Should -Match '✅ Pass' |
| 148 | + $script:capturedResult | Should -Not -Match '❌ Fail' |
| 149 | + } |
| 150 | + } |
| 151 | +} |
0 commit comments