Skip to content
Merged
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
15 changes: 9 additions & 6 deletions .github/workflows/quality-gates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
# tests Windows, PowerShell 7. PSScriptAnalyzer at Error and Warning over the module, the
# kit and the tests, the 115-character line limit, then the whole Pester suite (the
# module's unit and integration suites and the validation kit's unit suite) with an
# 80% coverage gate over Public/ and Private/. Nothing here
# reaches a tenant: every Graph call in the suites goes through the mocked
# Invoke-IslGraphRequest seam, and the suites that need an elevated session, a lab
# account or a Graph connection skip themselves.
# 80% coverage gate over Public/ and Private/. Nothing here reaches a tenant: every
# Graph call in the suites goes through the mocked Invoke-IslGraphRequest seam, and
# the suites that need a lab account or a Graph connection skip themselves. The
# hosted Windows runner is elevated, so the SYSTEM-context tests run: they register
# scheduled tasks named IntuneScriptLab-* as NT AUTHORITY\SYSTEM on the runner, run
# a script through each and remove them.
#
# Every Pester run goes through Tests/Invoke-Tests.ps1, the script a developer runs as well. It
# shuffles the order, so a test that only passes because of what ran before it fails here
Expand Down Expand Up @@ -185,8 +187,9 @@ jobs:
"Pester $((Get-Module Pester).Version) on PowerShell $($PSVersionTable.PSVersion)" | Write-Host

# The integration suite as well: it launches the 5.1 hosts the harness uses on a device.
# The hosted runner's token is not elevated (IsInRole Administrator is false), so the
# SYSTEM-context tests skip here as they do under pwsh; they run on the lab devices
# The hosted runner is elevated, so the SYSTEM-context tests run here as they do under
# pwsh: they register and remove IntuneScriptLab-* scheduled tasks as SYSTEM on the runner.
# The user-context suite needs a lab account and skips itself.
- name: Pester under Windows PowerShell 5.1
shell: powershell
run: |
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ entries are carried over from the manifest's release notes.
process that is already gone on its error stream, and 5.1 made a terminating error of that
line. The process tree is now ended without that stream reaching PowerShell as errors, and a
warning is written when a process could not be ended.
- Four tests were skipped on every run: the three of the SYSTEM-context integration suite, which
are the only ones that launch a script through a scheduled task as SYSTEM, and the file-version
test of `Test-IntuneWin32Rule`. Their skip condition read a variable that was set only after
Pester had evaluated the condition. It is decided during discovery now, so the SYSTEM-context
suite runs in an elevated session and is skipped in any other.

## [0.34.0] - 2026-10-15

Expand Down
11 changes: 8 additions & 3 deletions Tests/Integration/SystemContext.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@

#pester:no-parallel

BeforeDiscovery {
# Pester evaluates -Skip during discovery, before any BeforeAll runs. Set there, this was still
# unset when the conditions read it, and the tests were skipped in an elevated session too
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$script:IsAdmin = ([Security.Principal.WindowsPrincipal]$identity).IsInRole(
[Security.Principal.WindowsBuiltInRole]::Administrator)
}

BeforeAll {
$script:ModuleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
Import-Module (Join-Path $script:ModuleRoot 'IntuneScriptLab.psd1') -Force
. (Join-Path $script:ModuleRoot 'Tests\TestHelpers\TestHelpers.ps1')
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$script:IsAdmin = ([Security.Principal.WindowsPrincipal]$identity).IsInRole(
[Security.Principal.WindowsBuiltInRole]::Administrator)
}

AfterAll {
Expand Down
7 changes: 7 additions & 0 deletions Tests/Unit/Public/Test-IntuneWin32Rule.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
afterwards; the 32-bit registry view is read from a Windows value that differs between views.
#>

BeforeDiscovery {
# Pester evaluates -Skip during discovery, before any BeforeAll runs, so the condition of the
# file-version test is decided here. BeforeAll looks again, because a variable set during
# discovery does not reach the run
$script:HasVersioned = Test-Path -LiteralPath (Join-Path $env:WINDIR 'System32\notepad.exe')
}

BeforeAll {
$script:ModuleRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $PSScriptRoot))
Import-Module (Join-Path $script:ModuleRoot 'IntuneScriptLab.psd1') -Force
Expand Down