-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made hybrid join optional in filter. Fix for #433
- Loading branch information
Showing
2 changed files
with
91 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
85 changes: 85 additions & 0 deletions
85
powershell/tests/functions/Test-MtCaEnforceNonPersistentBrowserSession.Tests.ps1
This file contains 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,85 @@ | ||
|
||
Describe 'Test-MtCaEnforceNonPersistentBrowserSession' { | ||
BeforeAll { | ||
Mock -ModuleName Maester Get-MtLicenseInformation { return "P1" } | ||
|
||
function Get-BaselinePolicy { | ||
return [PSCustomObject]@{ | ||
state = "enabled" | ||
conditions = @{ | ||
users = @{ | ||
includeUsers = "All" | ||
} | ||
applications = @{ | ||
includeApplications = "All" | ||
} | ||
devices = @{ | ||
deviceFilter = @{ | ||
mode = "include" | ||
rule = 'device.trustType -ne "ServerAD" -or device.isCompliant -ne True' | ||
} | ||
} | ||
} | ||
sessionControls = @{ | ||
persistentBrowser = @{ | ||
isEnabled = $true | ||
mode = "never" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
Context "CA: Enforce non persistent browser session" { | ||
|
||
It 'Policy without non persistent browser session should fail' { | ||
$policy = Get-BaselinePolicy | ||
$policy.sessionControls.persistentBrowser.isEnabled = $false | ||
|
||
Mock -ModuleName Maester Get-MtConditionalAccessPolicy { return $policy } | ||
|
||
Test-MtCaEnforceNonPersistentBrowserSession | Should -BeFalse | ||
} | ||
|
||
It 'Include: Non Hybrid or Non-compliant device filter should Pass' { | ||
$policy = Get-BaselinePolicy | ||
$policy.conditions.devices.deviceFilter.mode = "include" | ||
$policy.conditions.devices.deviceFilter.rule = 'device.trustType -ne "ServerAD" -or device.isCompliant -ne True' | ||
Mock -ModuleName Maester Get-MtConditionalAccessPolicy { return $policy } | ||
|
||
Test-MtCaEnforceNonPersistentBrowserSession | Should -BeTrue | ||
} | ||
|
||
It 'Include: Non Compliant device filter (no-hybrid) should Pass' { | ||
# Should work with CA policies that only check for compliant devices | ||
# See https://github.com/maester365/maester/issues/433 | ||
$policy = Get-BaselinePolicy | ||
$policy.conditions.devices.deviceFilter.mode = "include" | ||
$policy.conditions.devices.deviceFilter.rule = 'device.isCompliant -ne True' | ||
Mock -ModuleName Maester Get-MtConditionalAccessPolicy { return $policy } | ||
|
||
Test-MtCaEnforceNonPersistentBrowserSession | Should -BeTrue | ||
} | ||
|
||
It 'Exclude: Hybrid or compliant device filter should Pass' { | ||
$policy = Get-BaselinePolicy | ||
$policy.conditions.devices.deviceFilter.mode = "exclude" | ||
$policy.conditions.devices.deviceFilter.rule = 'device.trustType -eq "ServerAD" -or device.isCompliant -eq True' | ||
Mock -ModuleName Maester Get-MtConditionalAccessPolicy { return $policy } | ||
|
||
Test-MtCaEnforceNonPersistentBrowserSession | Should -BeTrue | ||
} | ||
|
||
It 'Exclude: Compliant device filter (no-hybrid) should Pass' { | ||
# Should work with CA policies that only check for compliant devices | ||
# See https://github.com/maester365/maester/issues/433 | ||
$policy = Get-BaselinePolicy | ||
$policy.conditions.devices.deviceFilter.mode = "exclude" | ||
$policy.conditions.devices.deviceFilter.rule = 'device.isCompliant -eq True' | ||
Mock -ModuleName Maester Get-MtConditionalAccessPolicy { return $policy } | ||
|
||
Test-MtCaEnforceNonPersistentBrowserSession | Should -BeTrue | ||
} | ||
} | ||
} | ||
|