mirror of https://github.com/raandree/NTFSSecurity
Browse Source
Defect 22: - [OutputType]: Test-Path2 writes System.Boolean, not file objects; Get-FileHash2 writes the file object with Hash and Algorithm, not access rules; Add-NTFSAudit and Remove-NTFSAudit write audit entries since defect 6; Copy-Item2, Move-Item2, Remove-Item2, and the five inheritance cmdlets with -PassThru declared no type. - Enable-Privileges and Disable-Privileges with -PassThru wrote the privileges as one collection; they now enumerate it. - New-NTFSSymbolicLink -PassThru returned a FileInfo for a link to a folder; it now returns a DirectoryInfo. The OUTPUTS sections of the pages name the same types. Tests/OutputTypes.Tests.ps1 (new): 15 tests; Disable-Privileges and the symbolic link need privileges and run in CI. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: AI Assistant <ai@example.com>pull/103/head
30 changed files with 187 additions and 57 deletions
@ -0,0 +1,87 @@ |
|||
<# |
|||
Tests the output types of the cmdlets of the module built in NTFSSecurity\bin\Release: the [OutputType] that |
|||
Get-Command reports, and the objects that -PassThru writes. Tests that need a privilege skip without it and run |
|||
in CI, whose runners are elevated. |
|||
#> |
|||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute( |
|||
'PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Pester shares variables between blocks.' |
|||
)] |
|||
param () |
|||
|
|||
BeforeDiscovery { |
|||
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath 'TestHelpers.psm1') -Force |
|||
$holdsBackupPrivilege = Test-PrivilegeHeld -Name 'SeBackupPrivilege' |
|||
$canCreateSymbolicLinks = Test-PrivilegeHeld -Name 'SeCreateSymbolicLinkPrivilege' |
|||
|
|||
$itemTypes = @('Alphaleonis.Win32.Filesystem.FileInfo', 'Alphaleonis.Win32.Filesystem.DirectoryInfo') |
|||
$declaredTypes = @( |
|||
@{ Name = 'Test-Path2'; Types = @('System.Boolean') } |
|||
@{ Name = 'Get-FileHash2'; Types = @('Alphaleonis.Win32.Filesystem.FileInfo') } |
|||
@{ Name = 'Add-NTFSAudit'; Types = @('Security2.FileSystemAuditRule2') } |
|||
@{ Name = 'Remove-NTFSAudit'; Types = @('Security2.FileSystemAuditRule2') } |
|||
@{ Name = 'Copy-Item2'; Types = $itemTypes } |
|||
@{ Name = 'Move-Item2'; Types = $itemTypes } |
|||
@{ Name = 'Remove-Item2'; Types = $itemTypes } |
|||
@{ Name = 'Enable-NTFSAccessInheritance'; Types = @('Security2.FileSystemInheritanceInfo') } |
|||
@{ Name = 'Disable-NTFSAccessInheritance'; Types = @('Security2.FileSystemInheritanceInfo') } |
|||
@{ Name = 'Enable-NTFSAuditInheritance'; Types = @('Security2.FileSystemInheritanceInfo') } |
|||
@{ Name = 'Disable-NTFSAuditInheritance'; Types = @('Security2.FileSystemInheritanceInfo') } |
|||
@{ Name = 'Set-NTFSInheritance'; Types = @('Security2.FileSystemInheritanceInfo') } |
|||
) |
|||
} |
|||
|
|||
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 'OutputTypes' |
|||
Push-Location -LiteralPath $sandbox |
|||
} |
|||
|
|||
AfterAll { |
|||
Pop-Location |
|||
Remove-TestSandbox -Sandbox $sandbox |
|||
Remove-Module -Name NTFSSecurity -Force -ErrorAction SilentlyContinue |
|||
} |
|||
|
|||
Describe 'Declared output types' { |
|||
It '<Name> should declare the type of the objects it writes' -ForEach $declaredTypes { |
|||
@((Get-Command -Name $Name).OutputType.Name) | Should -Be $Types |
|||
} |
|||
} |
|||
|
|||
Describe 'Privilege cmdlets with -PassThru' { |
|||
AfterEach { |
|||
Disable-Privileges -ErrorAction SilentlyContinue -WarningAction SilentlyContinue |
|||
} |
|||
|
|||
# Before 5.0.0, -PassThru wrote the privileges as one collection. |
|||
It 'Enable-Privileges should write one object per privilege' { |
|||
$result = @(Enable-Privileges -PassThru -ErrorAction SilentlyContinue) |
|||
|
|||
$result.Count | Should -BeGreaterThan 1 |
|||
$result | ForEach-Object -Process { $_ | Should -BeOfType [ProcessPrivileges.PrivilegeAndAttributes] } |
|||
} |
|||
|
|||
It 'Disable-Privileges should write one object per privilege' -Skip:(-not $holdsBackupPrivilege) { |
|||
Enable-Privileges -ErrorAction SilentlyContinue |
|||
|
|||
$result = @(Disable-Privileges -PassThru -WarningAction SilentlyContinue) |
|||
|
|||
$result.Count | Should -BeGreaterThan 1 |
|||
$result | ForEach-Object -Process { $_ | Should -BeOfType [ProcessPrivileges.PrivilegeAndAttributes] } |
|||
} |
|||
} |
|||
|
|||
Describe 'New-NTFSSymbolicLink with -PassThru' { |
|||
# Before 5.0.0, the cmdlet returned a file object for a link to a folder as well. |
|||
It 'Should return a folder object for a link to a folder' -Skip:(-not $canCreateSymbolicLinks) { |
|||
$folder = New-TestSandboxItem -Sandbox $sandbox -Name 'Target' -Directory |
|||
$link = Join-Path -Path $sandbox -ChildPath 'FolderLink' |
|||
Assert-TestSandboxPath -Sandbox $sandbox -Path $link |
|||
|
|||
$result = New-NTFSSymbolicLink -Path $link -Target $folder -PassThru |
|||
|
|||
$result | Should -BeOfType [Alphaleonis.Win32.Filesystem.DirectoryInfo] |
|||
} |
|||
} |
|||
Loading…
Reference in new issue