mirror of https://github.com/raandree/NTFSSecurity
Browse Source
Defect 3. Get-FileHash2 left ProcessRecord at the first folder in -Path, so the files that followed the folder in the same array were not hashed. It now skips the folder, like Get-FileHash, and continues. Tests/FileHash.Tests.ps1 (new): 1 test. It skips in PowerShell 7, where every Get-FileHash2 call fails until the RIPEMD160 reference goes (decision D5, later in this run). 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 57 additions and 3 deletions
@ -0,0 +1,45 @@ |
|||
<# |
|||
Tests Get-FileHash2 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 'FileHash' |
|||
Push-Location -LiteralPath $sandbox |
|||
|
|||
$folder = Join-Path -Path $sandbox -ChildPath 'Folder' |
|||
$first = Join-Path -Path $sandbox -ChildPath 'One.txt' |
|||
$second = Join-Path -Path $sandbox -ChildPath 'Two.txt' |
|||
Assert-TestSandboxPath -Sandbox $sandbox -Path $folder, $first, $second |
|||
New-Item -ItemType Directory -Path $folder | Out-Null |
|||
Set-Content -LiteralPath $first -Value 'One' |
|||
Set-Content -LiteralPath $second -Value 'Two' |
|||
} |
|||
|
|||
AfterAll { |
|||
Pop-Location |
|||
Remove-TestSandbox -Sandbox $sandbox |
|||
Remove-Module -Name NTFSSecurity -Force -ErrorAction SilentlyContinue |
|||
} |
|||
|
|||
Describe 'Get-FileHash2' { |
|||
Context 'When -Path contains a folder' { |
|||
It 'Should skip the folder and hash the files that follow it' { |
|||
if ($PSVersionTable.PSEdition -eq 'Core') { |
|||
Set-ItResult -Skipped -Because 'Get-FileHash2 fails in PowerShell 7 until it no longer references RIPEMD160' |
|||
} |
|||
|
|||
$results = @(Get-FileHash2 -Path $first, $folder, $second -ErrorVariable hashErrors -ErrorAction SilentlyContinue) |
|||
|
|||
$hashErrors | Should -BeNullOrEmpty |
|||
$results.Name | Should -Be @('One.txt', 'Two.txt') |
|||
$results[1].Hash | Should -BeExactly (Get-FileHash -LiteralPath $second -Algorithm SHA256).Hash |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue