|
| 1 | +Describe "Test-Assessment-35001" { |
| 2 | + BeforeAll { |
| 3 | + $here = $PSScriptRoot |
| 4 | + $srcRoot = Join-Path $here "../../src/powershell" |
| 5 | + |
| 6 | + # Mock external module dependencies |
| 7 | + if (-not (Get-Command Write-PSFMessage -ErrorAction SilentlyContinue)) { |
| 8 | + function Write-PSFMessage { |
| 9 | + } |
| 10 | + } |
| 11 | + |
| 12 | + # Load the class |
| 13 | + $classPath = Join-Path $srcRoot "classes/ZtTest.ps1" |
| 14 | + if (-not ("ZtTest" -as [type])) { |
| 15 | + . $classPath |
| 16 | + } |
| 17 | + |
| 18 | + # Load the SUT |
| 19 | + $sut = Join-Path $srcRoot "tests/Test-Assessment.35001.ps1" |
| 20 | + . $sut |
| 21 | + |
| 22 | + # Setup output file |
| 23 | + $script:outputFile = Join-Path $here "../TestResults/Report-Test-Assessment.35001.md" |
| 24 | + $outputDir = Split-Path $script:outputFile |
| 25 | + if (-not (Test-Path $outputDir)) { |
| 26 | + New-Item -ItemType Directory -Path $outputDir | Out-Null |
| 27 | + } |
| 28 | + "# Test Results for 35001`n" | Set-Content $script:outputFile |
| 29 | + } |
| 30 | + |
| 31 | + BeforeEach { |
| 32 | + Mock Write-PSFMessage {} |
| 33 | + Mock Write-ZtProgress {} |
| 34 | + Mock Get-SafeMarkdown { param($Text) return $Text } |
| 35 | + } |
| 36 | + |
| 37 | + Context "When no policies exist" { |
| 38 | + It "Should pass" { |
| 39 | + Mock Get-ZtConditionalAccessPolicy { return @() } |
| 40 | + |
| 41 | + Mock Add-ZtTestResultDetail { |
| 42 | + param($TestId, $Title, $Status, $Result) |
| 43 | + "## Scenario: No policies`n`n$Result`n" | Add-Content $script:outputFile |
| 44 | + } |
| 45 | + |
| 46 | + Test-Assessment-35001 |
| 47 | + |
| 48 | + Should -Invoke Add-ZtTestResultDetail -ParameterFilter { |
| 49 | + $Status -eq $true -and $Result -match "Microsoft Rights Management Service \(RMS\) is excluded" |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + Context "When policies exist but RMS is excluded" { |
| 55 | + It "Should pass when 'All' apps included but RMS excluded" { |
| 56 | + Mock Get-ZtConditionalAccessPolicy { |
| 57 | + return @( |
| 58 | + [PSCustomObject]@{ |
| 59 | + id = "policy-1" |
| 60 | + displayName = "Policy 1" |
| 61 | + state = "enabled" |
| 62 | + conditions = [PSCustomObject]@{ |
| 63 | + applications = [PSCustomObject]@{ |
| 64 | + includeApplications = @("All") |
| 65 | + excludeApplications = @("00000012-0000-0000-c000-000000000000") |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + ) |
| 70 | + } |
| 71 | + |
| 72 | + Mock Add-ZtTestResultDetail { |
| 73 | + param($TestId, $Title, $Status, $Result) |
| 74 | + "## Scenario: All apps included, RMS excluded`n`n$Result`n" | Add-Content $script:outputFile |
| 75 | + } |
| 76 | + |
| 77 | + Test-Assessment-35001 |
| 78 | + |
| 79 | + Should -Invoke Add-ZtTestResultDetail -ParameterFilter { |
| 80 | + $Status -eq $true |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + Context "When policies block RMS" { |
| 86 | + It "Should fail when 'All' apps included and RMS NOT excluded" { |
| 87 | + Mock Get-ZtConditionalAccessPolicy { |
| 88 | + return @( |
| 89 | + [PSCustomObject]@{ |
| 90 | + id = "policy-block-all" |
| 91 | + displayName = "Block All Policy" |
| 92 | + state = "enabled" |
| 93 | + conditions = [PSCustomObject]@{ |
| 94 | + applications = [PSCustomObject]@{ |
| 95 | + includeApplications = @("All") |
| 96 | + excludeApplications = @("some-other-app-id") |
| 97 | + } |
| 98 | + } |
| 99 | + grantControls = [PSCustomObject]@{ |
| 100 | + builtInControls = @("mfa") |
| 101 | + } |
| 102 | + sessionControls = [PSCustomObject]@{ |
| 103 | + signInFrequency = [PSCustomObject]@{ |
| 104 | + isEnabled = $true |
| 105 | + value = 4 |
| 106 | + type = "hours" |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + ) |
| 111 | + } |
| 112 | + |
| 113 | + $script:capturedResult = $null |
| 114 | + Mock Add-ZtTestResultDetail { |
| 115 | + param($TestId, $Title, $Status, $Result) |
| 116 | + $script:capturedResult = $Result |
| 117 | + "## Scenario: Block All Policy`n`n$Result`n" | Add-Content $script:outputFile |
| 118 | + } |
| 119 | + |
| 120 | + Test-Assessment-35001 |
| 121 | + |
| 122 | + Should -Invoke Add-ZtTestResultDetail -ParameterFilter { |
| 123 | + $Status -eq $false |
| 124 | + } |
| 125 | + $script:capturedResult | Should -Match "Block All Policy" |
| 126 | + $script:capturedResult | Should -Match "mfa" |
| 127 | + $script:capturedResult | Should -Match "Sign-in Frequency" |
| 128 | + } |
| 129 | + |
| 130 | + It "Should fail when RMS explicitly included and NOT excluded" { |
| 131 | + Mock Get-ZtConditionalAccessPolicy { |
| 132 | + return @( |
| 133 | + [PSCustomObject]@{ |
| 134 | + id = "policy-block-rms" |
| 135 | + displayName = "Block RMS Policy" |
| 136 | + state = "enabled" |
| 137 | + conditions = [PSCustomObject]@{ |
| 138 | + applications = [PSCustomObject]@{ |
| 139 | + includeApplications = @("00000012-0000-0000-c000-000000000000") |
| 140 | + excludeApplications = @() |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | + ) |
| 145 | + } |
| 146 | + |
| 147 | + $script:capturedResult = $null |
| 148 | + Mock Add-ZtTestResultDetail { |
| 149 | + param($TestId, $Title, $Status, $Result) |
| 150 | + $script:capturedResult = $Result |
| 151 | + "## Scenario: Block RMS Policy`n`n$Result`n" | Add-Content $script:outputFile |
| 152 | + } |
| 153 | + |
| 154 | + Test-Assessment-35001 |
| 155 | + |
| 156 | + Should -Invoke Add-ZtTestResultDetail -ParameterFilter { |
| 157 | + $Status -eq $false |
| 158 | + } |
| 159 | + $script:capturedResult | Should -Match "None" |
| 160 | + } |
| 161 | + } |
| 162 | + |
| 163 | + Context "Error Handling" { |
| 164 | + It "Should handle errors gracefully" { |
| 165 | + Mock Get-ZtConditionalAccessPolicy { throw "Graph API Error" } |
| 166 | + |
| 167 | + $script:capturedResult = $null |
| 168 | + Mock Add-ZtTestResultDetail { |
| 169 | + param($TestId, $Title, $Status, $Result) |
| 170 | + $script:capturedResult = $Result |
| 171 | + "## Scenario: Error Handling`n`n$Result`n" | Add-Content $script:outputFile |
| 172 | + } |
| 173 | + |
| 174 | + Test-Assessment-35001 |
| 175 | + |
| 176 | + Should -Invoke Add-ZtTestResultDetail -ParameterFilter { |
| 177 | + $Status -eq $false |
| 178 | + } |
| 179 | + $script:capturedResult | Should -Match "Unable to determine RMS exclusion status" |
| 180 | + } |
| 181 | + } |
| 182 | + |
| 183 | + Context "When policies are disabled" { |
| 184 | + It "Should pass when a blocking policy is disabled" { |
| 185 | + Mock Get-ZtConditionalAccessPolicy { |
| 186 | + return @( |
| 187 | + [PSCustomObject]@{ |
| 188 | + id = "policy-disabled-block" |
| 189 | + displayName = "Disabled Block Policy" |
| 190 | + state = "disabled" |
| 191 | + conditions = [PSCustomObject]@{ |
| 192 | + applications = [PSCustomObject]@{ |
| 193 | + includeApplications = @("00000012-0000-0000-c000-000000000000") |
| 194 | + excludeApplications = @() |
| 195 | + } |
| 196 | + } |
| 197 | + } |
| 198 | + ) |
| 199 | + } |
| 200 | + |
| 201 | + Mock Add-ZtTestResultDetail { |
| 202 | + param($TestId, $Title, $Status, $Result) |
| 203 | + "## Scenario: Disabled Policy`n`n$Result`n" | Add-Content $script:outputFile |
| 204 | + } |
| 205 | + |
| 206 | + Test-Assessment-35001 |
| 207 | + |
| 208 | + Should -Invoke Add-ZtTestResultDetail -ParameterFilter { |
| 209 | + $Status -eq $true |
| 210 | + } |
| 211 | + } |
| 212 | + } |
| 213 | +} |
0 commit comments