@@ -32,7 +32,8 @@ Describe 'Archive Entry Management Commands' {
3232 Compress-TarArchive @compressTarArchiveSplat
3333 }
3434
35- $zip , $file , $uri , $tarArchives , $itemCounts , $totalCount | Out-Null
35+ $encryptedZip = Get-Item $PSScriptRoot / ../ assets/ helloworld.zip
36+ $zip , $file , $uri , $tarArchives , $itemCounts , $totalCount , $encryptedZip | Out-Null
3637 }
3738
3839 Context ' New-ZipEntry' - Tag ' New-ZipEntry' {
@@ -356,6 +357,20 @@ Describe 'Archive Entry Management Commands' {
356357 { $zip | Get-ZipEntry - Type Directory | Get-ZipEntry } |
357358 Should - Throw
358359 }
360+
361+ It ' Can read encrypted entries' {
362+ $passw = ConvertTo-SecureString ' test' - AsPlainText - Force
363+
364+ Use-Object ($stream = $encryptedZip.OpenRead ()) {
365+ $stream | Get-ZipEntry - Type Archive |
366+ Get-ZipEntryContent - Password $passw |
367+ Should - BeExactly ' hello world!'
368+ }
369+
370+ $encryptedZip | Get-ZipEntry - Type Archive |
371+ Get-ZipEntryContent - Password $passw |
372+ Should - BeExactly ' hello world!'
373+ }
359374 }
360375
361376 Context ' Get-TarEntryContent' - Tag ' Get-TarEntryContent' {
@@ -680,6 +695,26 @@ Describe 'Archive Entry Management Commands' {
680695 Get-ChildItem - LiteralPath $destination - Recurse - File |
681696 ForEach-Object { $_ | Get-Content | Should - BeExactly $content }
682697 }
698+
699+ It ' Can extract an encrypted entry' {
700+ $passw = ConvertTo-SecureString ' test' - AsPlainText - Force
701+ $dest = Join-Path $TestDrive encryptedTestFolder
702+ Use-Object ($stream = $encryptedZip.OpenRead ()) {
703+ $info = $stream | Get-ZipEntry - Type Archive |
704+ Expand-ZipEntry - Password $passw - Destination $dest - PassThru
705+
706+ $info | Should - BeOfType ([FileInfo ])
707+ Get-Content $info.FullName | Should - BeExactly ' hello world!'
708+ $info.Delete ()
709+ }
710+
711+ $info = $encryptedZip | Get-ZipEntry |
712+ Expand-ZipEntry - Password $passw - Destination $dest - PassThru
713+
714+ $info | Should - BeOfType ([FileInfo ])
715+ Get-Content $info.FullName | Should - BeExactly ' hello world!'
716+ $info.Delete ()
717+ }
683718 }
684719
685720 Context ' Expand-TarEntry' - Tag ' Expand-TarEntry' {
0 commit comments