Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BeforeAll {
BeforeAll {
Import-Module "$PSScriptRoot/../../Maester.psd1" -Force

$script:savedGhToken = $env:GH_TOKEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
Mock -ModuleName Maester Get-MtConditionalAccessPolicy { return $policy }
Mock -ModuleName Maester Get-MtSetting { return $null }

InModuleScope Maester -Parameters @{ C = $config } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeTrue
InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeTrue
}

It 'Should pass when a group is excluded from all policies (auto-detected)' {
Expand All @@ -223,7 +223,7 @@
Mock -ModuleName Maester Get-MtConditionalAccessPolicy { return $policy }
Mock -ModuleName Maester Get-MtSetting { return $null }

InModuleScope Maester -Parameters @{ C = $config } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeTrue
InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeTrue
}
}

Expand Down Expand Up @@ -469,7 +469,7 @@

# Returns $false because Agent Identity policies don't apply to users and are filtered out
# When all policies are filtered out, there are no policies to check, so no emergency access is detected
InModuleScope Maester -Parameters @{ C = $config } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeFalse
InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeFalse
}

It 'Should return false (no emergency access detected) when only a Service Principal policy exists (which should be ignored)' {
Expand All @@ -480,7 +480,7 @@

# Returns $false because Service Principal policies don't apply to users and are filtered out
# When all policies are filtered out, there are no policies to check, so no emergency access is detected
InModuleScope Maester -Parameters @{ C = $config } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeFalse
InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeFalse
}

It 'Should only check user-targeted policies when both Agent Identity and user policies exist' {
Expand All @@ -493,7 +493,7 @@
Mock -ModuleName Maester Get-MtSetting { return $null }

# Should pass because the Agent Identity policy is ignored and the user policy has exclusions
InModuleScope Maester -Parameters @{ C = $config } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeTrue
InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeTrue
}
}
}
36 changes: 18 additions & 18 deletions powershell/tests/pester.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -140,34 +140,34 @@ if ($testFiles.Count -eq 0) {
#region Combined single-run mode (required for coherent coverage data)
# When coverage is enabled, all test files are passed to a single Invoke-Pester call so Pester can
# produce one consolidated JaCoCo report.
$config = New-PesterConfiguration
$config.TestResult.Enabled = $true
$pesterConfig = New-PesterConfiguration
$pesterConfig.TestResult.Enabled = $true
$coverageOutputPath = Join-Path $resultRoot "CodeCoverage.xml"
$config.CodeCoverage.Enabled = $true
$config.CodeCoverage.OutputFormat = 'JaCoCo'
$config.CodeCoverage.OutputPath = $coverageOutputPath
$pesterConfig.CodeCoverage.Enabled = $true
$pesterConfig.CodeCoverage.OutputFormat = 'JaCoCo'
$pesterConfig.CodeCoverage.OutputPath = $coverageOutputPath
# Scope coverage to module source directories only (exclude tests/).
$config.CodeCoverage.Path = @(
$pesterConfig.CodeCoverage.Path = @(
(Resolve-Path "$PSScriptRoot\..\public").Path,
(Resolve-Path "$PSScriptRoot\..\internal").Path
)
$config.CodeCoverage.RecursePaths = $true
$pesterConfig.CodeCoverage.RecursePaths = $true
# Profiler-based coverage. With breakpoints on every line of the module the coverage run took ten
# times as long as the other runs, as the tests run the engine end to end many times.
$config.CodeCoverage.UseBreakpoints = $false
$pesterConfig.CodeCoverage.UseBreakpoints = $false
Write-PSFMessage -Level Important -Message "Code coverage enabled. Output: $coverageOutputPath"

Write-PSFMessage -Level Important -Message "Running $($testFiles.Count) test files in combined coverage run"
$config.TestResult.OutputPath = Join-Path $resultRoot "TEST-Coverage.xml"
$config.TestResult.OutputFormat = "JUnitXml"
$config.Run.Path = [string[]]$testFiles.FullName
$config.Run.PassThru = $true
$config.Output.Verbosity = $Output
$result = Invoke-Pester -Configuration $config

$totalRun += $result.TotalCount
$totalFailed += $result.FailedCount + $result.FailedContainersCount
foreach ($test in $result.Tests) {
$pesterConfig.TestResult.OutputPath = Join-Path $resultRoot "TEST-Coverage.xml"
$pesterConfig.TestResult.OutputFormat = "JUnitXml"
$pesterConfig.Run.Path = [string[]]$testFiles.FullName
$pesterConfig.Run.PassThru = $true
$pesterConfig.Output.Verbosity = $Output
$pesterRun = Invoke-Pester -Configuration $pesterConfig

$totalRun += $pesterRun.TotalCount
$totalFailed += $pesterRun.FailedCount + $pesterRun.FailedContainersCount
foreach ($test in $pesterRun.Tests) {
if ($test.Result -notin 'Passed', 'Skipped') {
$null = $testresults.Add([pscustomobject]@{
Block = $test.Block.ExpandedName
Expand Down
Loading