From 25bce535dc01690dd94acc1e51f9697a4ae4e0a7 Mon Sep 17 00:00:00 2001 From: Raimund Andree Date: Thu, 8 Oct 2026 10:11:25 +0000 Subject: [PATCH] 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 --- Tests/SecurityDescriptor.Tests.ps1 | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Tests/SecurityDescriptor.Tests.ps1 b/Tests/SecurityDescriptor.Tests.ps1 index e77adce..3fa8050 100644 --- a/Tests/SecurityDescriptor.Tests.ps1 +++ b/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] } } }