From 7aeb99e646f32f52437a5fd2d30a3f943212602e Mon Sep 17 00:00:00 2001 From: Jeffrey Stuhr <110697945+fadwen@users.noreply.github.com> Date: Wed, 25 Nov 2026 15:48:04 -0800 Subject: [PATCH 1/5] test: hold the run-folder grant by its rights, and run the credential test in the x86 host On the hosted runners the grant to the runner's own account showed three entries where the tests counted two, and Windows on ARM has no x64 host, so the credential test stopped before the task. The grant tests now assert the inherit-only Modify, the list and add rights on the folder and no Delete there, and list every entry when one fails. --- Tests/Unit/Module.Credential.Tests.ps1 | 3 +- .../Private/Grant-IslFolderAccess.Tests.ps1 | 74 ++++++++++++++++--- 2 files changed, 66 insertions(+), 11 deletions(-) diff --git a/Tests/Unit/Module.Credential.Tests.ps1 b/Tests/Unit/Module.Credential.Tests.ps1 index 0bde68d..f8f856a 100644 --- a/Tests/Unit/Module.Credential.Tests.ps1 +++ b/Tests/Unit/Module.Credential.Tests.ps1 @@ -49,7 +49,8 @@ BeforeAll { param() $testSplat = @{ - Path = $script:ScriptPath; Architecture = 'x64'; Context = 'User' + # x86: the one host that every Windows has, Windows on ARM included, where there is no x64 + Path = $script:ScriptPath; Architecture = 'x86'; Context = 'User' Credential = $script:Credential; TimeoutSeconds = 30 Verbose = $true; InformationAction = 'Continue'; WarningAction = 'Continue' ErrorAction = 'Continue' diff --git a/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 b/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 index f6b73fd..38b0ce8 100644 --- a/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 +++ b/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 @@ -63,6 +63,68 @@ BeforeAll { Grant-IslFolderAccess -Path $Path -Account $Account } } + + function script:Assert-RunGrant { + <# + .SYNOPSIS + Asserts the grant an account got on a run folder. + + .DESCRIPTION + Reads the entries set on the folder itself for the identity, and asserts that one gives + Modify to what is in the folder only (inherit-only, to files and folders), that one lets + it list the folder and add files and folders, and that none of the entries that apply to + the folder itself lets it delete the folder or what is in it. Each failure lists every + entry of the identity, so that an entry Windows added can be read from the log. + + .PARAMETER Path + The folder. + + .PARAMETER Identity + The identity, as the access list names it. + + .EXAMPLE + Assert-RunGrant -Path $script:Folder -Identity $script:Me.Name + + Asserts the grant of the current user on the test folder. + + .INPUTS + None. + + .OUTPUTS + None. + #> + [CmdletBinding()] + [OutputType([void])] + param( + [Parameter(Mandatory)] + [string]$Path, + + [Parameter(Mandatory)] + [string]$Identity + ) + + $rules = @((Get-Acl -LiteralPath $Path).Access | Where-Object { + -not $_.IsInherited -and "$($_.IdentityReference)" -eq $Identity + }) + $listed = ($rules | ForEach-Object { + $flags = '{0}/{1}' -f $_.InheritanceFlags, $_.PropagationFlags + '{0} {1} {2}' -f $_.FileSystemRights, $flags, $_.AccessControlType + }) -join '; ' + $because = "the entries of $Identity are: $listed" + + $below = @($rules | Where-Object { + "$($_.PropagationFlags)" -eq 'InheritOnly' -and "$($_.FileSystemRights)" -like '*Modify*' + }) + $below.Count | Should-BeGreaterThan 0 -Because $because + $adding = [System.Security.AccessControl.FileSystemRights]'ListDirectory, CreateFiles, CreateDirectories' + $onFolder = @($rules | Where-Object { "$($_.PropagationFlags)" -ne 'InheritOnly' }) + @($onFolder | Where-Object { ($_.FileSystemRights -band $adding) -eq $adding }).Count | + Should-BeGreaterThan 0 -Because $because + $deleting = [System.Security.AccessControl.FileSystemRights]'Delete, DeleteSubdirectoriesAndFiles' + @($onFolder | Where-Object { + "$($_.AccessControlType)" -eq 'Allow' -and [int]($_.FileSystemRights -band $deleting) -ne 0 + }).Count | Should-Be 0 -Because $because + } } Describe 'Grant-IslFolderAccess' -Tag 'Unit', 'Private' { @@ -101,11 +163,7 @@ Describe 'Grant-IslFolderAccess' -Tag 'Unit', 'Private' { It 'grants by the name as given when Windows does not resolve it' { Mock Resolve-IslAccount -ModuleName IntuneScriptLab { } Grant-Access -Path $script:Folder -Account $script:Me.Name - $rule = (Get-Acl -Path $script:Folder).Access | Where-Object { - -not $_.IsInherited -and "$($_.IdentityReference)" -eq $script:Me.Name - } - # One entry for the folder's contents and one for the folder itself - @($rule).Count | Should-Be 2 + Assert-RunGrant -Path $script:Folder -Identity $script:Me.Name } It 'grants on a folder path that ends in a backslash' { @@ -113,11 +171,7 @@ Describe 'Grant-IslFolderAccess' -Tag 'Unit', 'Private' { # of the arguments in it: "The filename, directory name, or volume label syntax is incorrect" Mock Resolve-IslAccount -ModuleName IntuneScriptLab { } Grant-Access -Path "$($script:Folder)\" -Account $script:Me.Name - $rule = (Get-Acl -Path $script:Folder).Access | Where-Object { - -not $_.IsInherited -and "$($_.IdentityReference)" -eq $script:Me.Name - } - # One entry for the folder's contents and one for the folder itself - @($rule).Count | Should-Be 2 + Assert-RunGrant -Path $script:Folder -Identity $script:Me.Name } It 'names the account and the folder when icacls refuses, under error action ' -ForEach @( From 5557e678314d361507a6425755ebaded99626563 Mon Sep 17 00:00:00 2001 From: Jeffrey Stuhr <110697945+fadwen@users.noreply.github.com> Date: Wed, 25 Nov 2026 15:56:39 -0800 Subject: [PATCH 2/5] test: compare only the entries the grant adds On a hosted runner the account that runs the tests already has full control of its own test folder, an entry the old single grant merged into and the two new ones sit beside. The tests record the account's entries before the grant and assert on the ones it added. --- .../Private/Grant-IslFolderAccess.Tests.ps1 | 86 +++++++++++++++---- 1 file changed, 69 insertions(+), 17 deletions(-) diff --git a/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 b/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 index 38b0ce8..fab1a77 100644 --- a/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 +++ b/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 @@ -64,17 +64,66 @@ BeforeAll { } } + function script:Get-GrantEntry { + <# + .SYNOPSIS + Gets an identity's own entries on a folder, each with a text that names it. + + .DESCRIPTION + Returns the entries of the folder's access list that are set on it, not inherited, for + the identity, each with a Text of its rights, inheritance and propagation flags and + type, so that the entries before and after a grant can be compared. + + .PARAMETER Path + The folder. + + .PARAMETER Identity + The identity, as the access list names it. + + .EXAMPLE + $before = @(Get-GrantEntry -Path $script:Folder -Identity $script:Me.Name).Text + + The texts of the current user's entries on the test folder. + + .INPUTS + None. + + .OUTPUTS + System.Security.AccessControl.FileSystemAccessRule, with a Text note property. + #> + [CmdletBinding()] + [OutputType([System.Security.AccessControl.FileSystemAccessRule])] + param( + [Parameter(Mandatory)] + [string]$Path, + + [Parameter(Mandatory)] + [string]$Identity + ) + + foreach ($rule in (Get-Acl -LiteralPath $Path).Access) { + if ($rule.IsInherited -or "$($rule.IdentityReference)" -ne $Identity) { + continue + } + $flags = '{0}/{1}' -f $rule.InheritanceFlags, $rule.PropagationFlags + $text = '{0} {1} {2}' -f $rule.FileSystemRights, $flags, $rule.AccessControlType + $rule | Add-Member -MemberType NoteProperty -Name Text -Value $text -PassThru + } + } + function script:Assert-RunGrant { <# .SYNOPSIS Asserts the grant an account got on a run folder. .DESCRIPTION - Reads the entries set on the folder itself for the identity, and asserts that one gives - Modify to what is in the folder only (inherit-only, to files and folders), that one lets - it list the folder and add files and folders, and that none of the entries that apply to - the folder itself lets it delete the folder or what is in it. Each failure lists every - entry of the identity, so that an entry Windows added can be read from the log. + Reads the entries set on the folder itself for the identity that were not there before + the grant, and asserts that one gives Modify to what is in the folder only + (inherit-only, to files and folders), that one lets it list the folder and add files and + folders, and that none of them lets it delete the folder or what is in it. The test + grants to the account that runs it, which already has full control of its own test + folder on a hosted runner, so the entries from before are left out. Each failure lists + the entries the grant added. .PARAMETER Path The folder. @@ -82,8 +131,11 @@ BeforeAll { .PARAMETER Identity The identity, as the access list names it. + .PARAMETER Before + The identity's entries before the grant, as Get-GrantEntry returned them. + .EXAMPLE - Assert-RunGrant -Path $script:Folder -Identity $script:Me.Name + Assert-RunGrant -Path $script:Folder -Identity $script:Me.Name -Before $before Asserts the grant of the current user on the test folder. @@ -100,17 +152,15 @@ BeforeAll { [string]$Path, [Parameter(Mandatory)] - [string]$Identity + [string]$Identity, + + [Parameter()] + [AllowEmptyCollection()] + [string[]]$Before = @() ) - $rules = @((Get-Acl -LiteralPath $Path).Access | Where-Object { - -not $_.IsInherited -and "$($_.IdentityReference)" -eq $Identity - }) - $listed = ($rules | ForEach-Object { - $flags = '{0}/{1}' -f $_.InheritanceFlags, $_.PropagationFlags - '{0} {1} {2}' -f $_.FileSystemRights, $flags, $_.AccessControlType - }) -join '; ' - $because = "the entries of $Identity are: $listed" + $rules = @(Get-GrantEntry -Path $Path -Identity $Identity | Where-Object { $_.Text -notin $Before }) + $because = "the entries the grant added for $Identity are: $(($rules.Text) -join '; ')" $below = @($rules | Where-Object { "$($_.PropagationFlags)" -eq 'InheritOnly' -and "$($_.FileSystemRights)" -like '*Modify*' @@ -162,16 +212,18 @@ Describe 'Grant-IslFolderAccess' -Tag 'Unit', 'Private' { It 'grants by the name as given when Windows does not resolve it' { Mock Resolve-IslAccount -ModuleName IntuneScriptLab { } + $before = @(Get-GrantEntry -Path $script:Folder -Identity $script:Me.Name | ForEach-Object { $_.Text }) Grant-Access -Path $script:Folder -Account $script:Me.Name - Assert-RunGrant -Path $script:Folder -Identity $script:Me.Name + Assert-RunGrant -Path $script:Folder -Identity $script:Me.Name -Before $before } It 'grants on a folder path that ends in a backslash' { # Before, the backslash escaped the closing quote and icacls was handed a path with the rest # of the arguments in it: "The filename, directory name, or volume label syntax is incorrect" Mock Resolve-IslAccount -ModuleName IntuneScriptLab { } + $before = @(Get-GrantEntry -Path $script:Folder -Identity $script:Me.Name | ForEach-Object { $_.Text }) Grant-Access -Path "$($script:Folder)\" -Account $script:Me.Name - Assert-RunGrant -Path $script:Folder -Identity $script:Me.Name + Assert-RunGrant -Path $script:Folder -Identity $script:Me.Name -Before $before } It 'names the account and the folder when icacls refuses, under error action ' -ForEach @( From 0766b6ccf010db2b4363d93742289c6af6ba9f39 Mon Sep 17 00:00:00 2001 From: Jeffrey Stuhr <110697945+fadwen@users.noreply.github.com> Date: Wed, 25 Nov 2026 16:06:11 -0800 Subject: [PATCH 3/5] test: grant to LOCAL SERVICE, not to the account that runs the tests On a hosted runner the account that runs the tests owns its test folder, and a grant to it there also writes FullControl for it, which the folder did not hold before. A run grants to another account, so the by-name tests grant to NT AUTHORITY\LOCAL SERVICE, which no test folder names. --- .../Unit/Private/Grant-IslFolderAccess.Tests.ps1 | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 b/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 index fab1a77..172ae13 100644 --- a/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 +++ b/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 @@ -15,6 +15,9 @@ BeforeAll { Import-Module (Join-Path $script:ModuleRoot 'IntuneScriptLab.psd1') -Force } $script:Me = [System.Security.Principal.WindowsIdentity]::GetCurrent() + # An account on no folder of the tests, granted by name. Not the account that runs them: on a + # hosted runner it owns its test folder, and a grant to it there also writes FullControl for it + $script:Stranger = 'NT AUTHORITY\LOCAL SERVICE' function Grant-Access { <# @@ -212,18 +215,18 @@ Describe 'Grant-IslFolderAccess' -Tag 'Unit', 'Private' { It 'grants by the name as given when Windows does not resolve it' { Mock Resolve-IslAccount -ModuleName IntuneScriptLab { } - $before = @(Get-GrantEntry -Path $script:Folder -Identity $script:Me.Name | ForEach-Object { $_.Text }) - Grant-Access -Path $script:Folder -Account $script:Me.Name - Assert-RunGrant -Path $script:Folder -Identity $script:Me.Name -Before $before + $before = @(Get-GrantEntry -Path $script:Folder -Identity $script:Stranger | ForEach-Object { $_.Text }) + Grant-Access -Path $script:Folder -Account $script:Stranger + Assert-RunGrant -Path $script:Folder -Identity $script:Stranger -Before $before } It 'grants on a folder path that ends in a backslash' { # Before, the backslash escaped the closing quote and icacls was handed a path with the rest # of the arguments in it: "The filename, directory name, or volume label syntax is incorrect" Mock Resolve-IslAccount -ModuleName IntuneScriptLab { } - $before = @(Get-GrantEntry -Path $script:Folder -Identity $script:Me.Name | ForEach-Object { $_.Text }) - Grant-Access -Path "$($script:Folder)\" -Account $script:Me.Name - Assert-RunGrant -Path $script:Folder -Identity $script:Me.Name -Before $before + $before = @(Get-GrantEntry -Path $script:Folder -Identity $script:Stranger | ForEach-Object { $_.Text }) + Grant-Access -Path "$($script:Folder)\" -Account $script:Stranger + Assert-RunGrant -Path $script:Folder -Identity $script:Stranger -Before $before } It 'names the account and the folder when icacls refuses, under error action ' -ForEach @( From 1c10ed821d8680590a9c1fa0b45927b418d6803a Mon Sep 17 00:00:00 2001 From: Jeffrey Stuhr <110697945+fadwen@users.noreply.github.com> Date: Wed, 25 Nov 2026 16:21:04 -0800 Subject: [PATCH 4/5] test: grant to LOCAL SERVICE by its name in the system's language, and assert the grant's exact shape The English name of LOCAL SERVICE is not what Get-Acl returns on Windows in another language. The name is now translated from S-1-5-19, entries are matched by SID, and one helper asserts the two entries of the grant exactly for both the by-SID and the by-name tests. --- .../Private/Grant-IslFolderAccess.Tests.ps1 | 143 +++++------------- 1 file changed, 39 insertions(+), 104 deletions(-) diff --git a/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 b/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 index 172ae13..c2392d8 100644 --- a/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 +++ b/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 @@ -15,9 +15,12 @@ BeforeAll { Import-Module (Join-Path $script:ModuleRoot 'IntuneScriptLab.psd1') -Force } $script:Me = [System.Security.Principal.WindowsIdentity]::GetCurrent() - # An account on no folder of the tests, granted by name. Not the account that runs them: on a - # hosted runner it owns its test folder, and a grant to it there also writes FullControl for it - $script:Stranger = 'NT AUTHORITY\LOCAL SERVICE' + # LOCAL SERVICE, an account on no folder of the tests, granted by its name in the system's own + # language. Not the account that runs them: on a hosted runner it owns its test folder, and a + # grant to it there also writes FullControl for it + $script:StrangerSid = 'S-1-5-19' + $script:Stranger = [System.Security.Principal.SecurityIdentifier]::new($script:StrangerSid).Translate( + [System.Security.Principal.NTAccount]).Value function Grant-Access { <# @@ -67,80 +70,27 @@ BeforeAll { } } - function script:Get-GrantEntry { - <# - .SYNOPSIS - Gets an identity's own entries on a folder, each with a text that names it. - - .DESCRIPTION - Returns the entries of the folder's access list that are set on it, not inherited, for - the identity, each with a Text of its rights, inheritance and propagation flags and - type, so that the entries before and after a grant can be compared. - - .PARAMETER Path - The folder. - - .PARAMETER Identity - The identity, as the access list names it. - - .EXAMPLE - $before = @(Get-GrantEntry -Path $script:Folder -Identity $script:Me.Name).Text - - The texts of the current user's entries on the test folder. - - .INPUTS - None. - - .OUTPUTS - System.Security.AccessControl.FileSystemAccessRule, with a Text note property. - #> - [CmdletBinding()] - [OutputType([System.Security.AccessControl.FileSystemAccessRule])] - param( - [Parameter(Mandatory)] - [string]$Path, - - [Parameter(Mandatory)] - [string]$Identity - ) - - foreach ($rule in (Get-Acl -LiteralPath $Path).Access) { - if ($rule.IsInherited -or "$($rule.IdentityReference)" -ne $Identity) { - continue - } - $flags = '{0}/{1}' -f $rule.InheritanceFlags, $rule.PropagationFlags - $text = '{0} {1} {2}' -f $rule.FileSystemRights, $flags, $rule.AccessControlType - $rule | Add-Member -MemberType NoteProperty -Name Text -Value $text -PassThru - } - } - function script:Assert-RunGrant { <# .SYNOPSIS - Asserts the grant an account got on a run folder. + Asserts the two entries a run folder's grant gives an account. .DESCRIPTION - Reads the entries set on the folder itself for the identity that were not there before - the grant, and asserts that one gives Modify to what is in the folder only - (inherit-only, to files and folders), that one lets it list the folder and add files and - folders, and that none of them lets it delete the folder or what is in it. The test - grants to the account that runs it, which already has full control of its own test - folder on a hosted runner, so the entries from before are left out. Each failure lists - the entries the grant added. + Reads the entries set on the folder itself for the SID, and asserts that there are two: + Modify for what is in the folder only, inherited by files and folders, and on the folder + itself the rights to list it and add files and folders, without Delete or + DeleteSubdirectoriesAndFiles. Each failure lists the SID's entries. .PARAMETER Path The folder. - .PARAMETER Identity - The identity, as the access list names it. - - .PARAMETER Before - The identity's entries before the grant, as Get-GrantEntry returned them. + .PARAMETER Sid + The SID of the account the folder was granted to. .EXAMPLE - Assert-RunGrant -Path $script:Folder -Identity $script:Me.Name -Before $before + Assert-RunGrant -Path $script:Folder -Sid 'S-1-5-19' - Asserts the grant of the current user on the test folder. + Asserts the grant of LOCAL SERVICE on the test folder. .INPUTS None. @@ -155,28 +105,31 @@ BeforeAll { [string]$Path, [Parameter(Mandatory)] - [string]$Identity, - - [Parameter()] - [AllowEmptyCollection()] - [string[]]$Before = @() + [string]$Sid ) - $rules = @(Get-GrantEntry -Path $Path -Identity $Identity | Where-Object { $_.Text -notin $Before }) - $because = "the entries the grant added for $Identity are: $(($rules.Text) -join '; ')" - - $below = @($rules | Where-Object { - "$($_.PropagationFlags)" -eq 'InheritOnly' -and "$($_.FileSystemRights)" -like '*Modify*' + $sidType = [System.Security.Principal.SecurityIdentifier] + $rules = @((Get-Acl -LiteralPath $Path).Access | Where-Object { + -not $_.IsInherited -and $_.IdentityReference.Translate($sidType).Value -eq $Sid }) - $below.Count | Should-BeGreaterThan 0 -Because $because - $adding = [System.Security.AccessControl.FileSystemRights]'ListDirectory, CreateFiles, CreateDirectories' - $onFolder = @($rules | Where-Object { "$($_.PropagationFlags)" -ne 'InheritOnly' }) - @($onFolder | Where-Object { ($_.FileSystemRights -band $adding) -eq $adding }).Count | - Should-BeGreaterThan 0 -Because $because + $listed = ($rules | ForEach-Object { + '{0} {1}/{2}' -f $_.FileSystemRights, $_.InheritanceFlags, $_.PropagationFlags + }) -join '; ' + $because = "the entries of $Sid are: $listed" + + $rules | Should-BeCollection -Count 2 -Because $because + $below = @($rules | Where-Object { "$($_.PropagationFlags)" -eq 'InheritOnly' }) + $below | Should-BeCollection -Count 1 -Because $because + "$($below[0].FileSystemRights)" | Should-BeLikeString '*Modify*' -Because $because + "$($below[0].InheritanceFlags)" | Should-Be 'ContainerInherit, ObjectInherit' -Because $because + $itself = @($rules | Where-Object { "$($_.InheritanceFlags)" -eq 'None' }) + $itself | Should-BeCollection -Count 1 -Because $because + $rights = $itself[0].FileSystemRights + # Listing and adding, which the run needs; deleting or renaming the folder, which it must not + $wanted = [System.Security.AccessControl.FileSystemRights]'ListDirectory, CreateFiles, CreateDirectories' + ($rights -band $wanted) | Should-Be $wanted -Because $because $deleting = [System.Security.AccessControl.FileSystemRights]'Delete, DeleteSubdirectoriesAndFiles' - @($onFolder | Where-Object { - "$($_.AccessControlType)" -eq 'Allow' -and [int]($_.FileSystemRights -band $deleting) -ne 0 - }).Count | Should-Be 0 -Because $because + [int]($rights -band $deleting) | Should-Be 0 -Because $because } } @@ -194,39 +147,21 @@ Describe 'Grant-IslFolderAccess' -Tag 'Unit', 'Private' { # S-1-5-32-545 is BUILTIN\Users, standing in for the account: the grant has to land on the # SID it was given, whatever the name passed in Grant-Access -Path $script:Folder -Account 'isl-verylongusername-test01@4nlnm3.onmicrosoft.com' - $sidType = [System.Security.Principal.SecurityIdentifier] - $rules = @((Get-Acl -Path $script:Folder).Access | Where-Object { - -not $_.IsInherited -and $_.IdentityReference.Translate($sidType).Value -eq 'S-1-5-32-545' - }) - $rules | Should-BeCollection -Count 2 - $below = @($rules | Where-Object { "$($_.PropagationFlags)" -eq 'InheritOnly' }) - $below | Should-BeCollection -Count 1 - "$($below[0].FileSystemRights)" | Should-BeLikeString '*Modify*' - "$($below[0].InheritanceFlags)" | Should-Be 'ContainerInherit, ObjectInherit' - $itself = @($rules | Where-Object { "$($_.InheritanceFlags)" -eq 'None' }) - $itself | Should-BeCollection -Count 1 - $rights = $itself[0].FileSystemRights - # Listing and adding, which the run needs; deleting or renaming the folder, which it must not - $wanted = [System.Security.AccessControl.FileSystemRights]'ListDirectory, CreateFiles, CreateDirectories' - ($rights -band $wanted) | Should-Be $wanted - $deleting = [System.Security.AccessControl.FileSystemRights]'Delete, DeleteSubdirectoriesAndFiles' - [int]($rights -band $deleting) | Should-Be 0 + Assert-RunGrant -Path $script:Folder -Sid 'S-1-5-32-545' } It 'grants by the name as given when Windows does not resolve it' { Mock Resolve-IslAccount -ModuleName IntuneScriptLab { } - $before = @(Get-GrantEntry -Path $script:Folder -Identity $script:Stranger | ForEach-Object { $_.Text }) Grant-Access -Path $script:Folder -Account $script:Stranger - Assert-RunGrant -Path $script:Folder -Identity $script:Stranger -Before $before + Assert-RunGrant -Path $script:Folder -Sid $script:StrangerSid } It 'grants on a folder path that ends in a backslash' { # Before, the backslash escaped the closing quote and icacls was handed a path with the rest # of the arguments in it: "The filename, directory name, or volume label syntax is incorrect" Mock Resolve-IslAccount -ModuleName IntuneScriptLab { } - $before = @(Get-GrantEntry -Path $script:Folder -Identity $script:Stranger | ForEach-Object { $_.Text }) Grant-Access -Path "$($script:Folder)\" -Account $script:Stranger - Assert-RunGrant -Path $script:Folder -Identity $script:Stranger -Before $before + Assert-RunGrant -Path $script:Folder -Sid $script:StrangerSid } It 'names the account and the folder when icacls refuses, under error action ' -ForEach @( From 941bcf268ab5414e19da5d640d98aa83229bdc95 Mon Sep 17 00:00:00 2001 From: Jeffrey Stuhr <110697945+fadwen@users.noreply.github.com> Date: Wed, 25 Nov 2026 16:26:14 -0800 Subject: [PATCH 5/5] test: drop the unused current identity from the grant tests --- Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 b/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 index c2392d8..6315d70 100644 --- a/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 +++ b/Tests/Unit/Private/Grant-IslFolderAccess.Tests.ps1 @@ -14,7 +14,6 @@ BeforeAll { if (-not $loaded -or $loaded.ModuleBase -ne $script:ModuleRoot) { Import-Module (Join-Path $script:ModuleRoot 'IntuneScriptLab.psd1') -Force } - $script:Me = [System.Security.Principal.WindowsIdentity]::GetCurrent() # LOCAL SERVICE, an account on no folder of the tests, granted by its name in the system's own # language. Not the account that runs them: on a hosted runner it owns its test folder, and a # grant to it there also writes FullControl for it @@ -42,9 +41,9 @@ BeforeAll { The error action preference in force inside the module, Continue by default. .EXAMPLE - Grant-Access -Path $script:Folder -Account $script:Me.Name + Grant-Access -Path $script:Folder -Account $script:Stranger - Grants the current user access to the test folder. + Grants LOCAL SERVICE access to the test folder. .INPUTS None.