Browse Source

test: check the written deny entry with .NET in both editions

PowerShell 7 has no static File.GetAccessControl, because .NET Core made
it an extension method, so the assertion of the -PassThru test passed
there for the wrong reason: the method was missing. The test now reads
with FileInfo.GetAccessControl or FileSystemAclExtensions and expects an
UnauthorizedAccessException in both editions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: AI Assistant <ai@example.com>
ai/release-5.0.0-rc6
Raimund Andree 4 days ago
parent
commit
25bce535dc
  1. 19
      Tests/SecurityDescriptor.Tests.ps1

19
Tests/SecurityDescriptor.Tests.ps1

@ -249,8 +249,23 @@ Describe 'Set-NTFSSecurityDescriptor' {
$result | Should -BeNullOrEmpty
$setErrors | Should -HaveCount 1
$setErrors[0].FullyQualifiedErrorId | Should -BeLike 'ReadSecurityError,*'
# Get-Acl of an elevated Windows PowerShell still reads the item, so .NET checks that the entry was written.
{ [System.IO.File]::GetAccessControl($file) } | Should -Throw
# Get-Acl of an elevated Windows PowerShell still reads the item, so .NET checks that the entry was written;
# .NET Core has the method as an extension method.
$info = New-Object -TypeName 'System.IO.FileInfo' -ArgumentList $file
$denied = $null
try {
if ($PSVersionTable.PSEdition -eq 'Desktop') {
$null = $info.GetAccessControl()
}
else {
$null = [System.IO.FileSystemAclExtensions]::GetAccessControl($info)
}
}
catch {
$denied = $_.Exception.GetBaseException()
}
$denied | Should -BeOfType [System.UnauthorizedAccessException]
}
}
}

Loading…
Cancel
Save