mirror of https://github.com/raandree/NTFSSecurity
Browse Source
Found while fixing defect 4: Get-NTFSAccess has the same pattern as Get-NTFSAudit. It kept the entries of the previous item and wrote them in a finally block, so a path whose ACL failed to read returned the previous item's entries again, next to the error. Each item now starts empty, and entries are written only after a successful read. Tests/Access.Tests.ps1 (new): 1 test; it failed before the fix with 6 entries instead of 3. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: AI Assistant <ai@example.com>pull/100/head
5 changed files with 58 additions and 23 deletions
@ -0,0 +1,37 @@ |
|||||
|
<# |
||||
|
Tests the access cmdlets of the module built in NTFSSecurity\bin\Release on files in a sandbox folder. |
||||
|
#> |
||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute( |
||||
|
'PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Pester shares variables between blocks.' |
||||
|
)] |
||||
|
param () |
||||
|
|
||||
|
BeforeAll { |
||||
|
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath 'TestHelpers.psm1') -Force |
||||
|
$modulePath = Join-Path -Path $PSScriptRoot -ChildPath '..\NTFSSecurity\bin\Release\NTFSSecurity.psd1' |
||||
|
Import-Module -Name $modulePath -Force -ErrorAction Stop |
||||
|
$sandbox = New-TestSandbox -Name 'Access' |
||||
|
Push-Location -LiteralPath $sandbox |
||||
|
} |
||||
|
|
||||
|
AfterAll { |
||||
|
Pop-Location |
||||
|
Remove-TestSandbox -Sandbox $sandbox |
||||
|
Remove-Module -Name NTFSSecurity -Force -ErrorAction SilentlyContinue |
||||
|
} |
||||
|
|
||||
|
Describe 'Get-NTFSAccess' { |
||||
|
Context 'When a path fails after a readable path' { |
||||
|
# Before 5.0.0, the cmdlet wrote the entries of the previous item again for the failing path. |
||||
|
It 'Should return the entries of the first item once' { |
||||
|
$folder = New-TestSandboxItem -Sandbox $sandbox -Name 'Readable' -Directory |
||||
|
$denied = New-TestSandboxItem -Sandbox $sandbox -Name 'Denied' |
||||
|
Block-TestReadPermission -Sandbox $sandbox -Path $denied |
||||
|
$expected = @(Get-NTFSAccess -Path $folder).Count |
||||
|
|
||||
|
$entries = @(Get-NTFSAccess -Path $folder, $denied -ErrorAction SilentlyContinue) |
||||
|
|
||||
|
@($entries | Where-Object -Property FullName -EQ -Value $folder) | Should -HaveCount $expected |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue