File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ // Tests for github issue 471: https://github.com/cthackers/adm-zip/issues/471
4+
5+ const assert = require ( "assert" ) ;
6+ const path = require ( "path" ) ;
7+ const Zip = require ( "../../adm-zip" ) ;
8+
9+ describe ( "decryption with info-zip spec password check" , ( ) => {
10+
11+
12+ // test decryption with both password types
13+ it ( "test decrypted data with password" , ( ) => {
14+ // the issue-471-infozip-encrypted.zip file has been generated with Info-Zip Zip 2.32, but the Info-Zip
15+ // standard is used by other zip generators as well.
16+ const infoZip = new Zip ( path . join ( __dirname , "../assets/issue-471-infozip-encrypted.zip" ) ) ;
17+ const entries = infoZip . getEntries ( ) ;
18+ assert ( entries . length === 1 , "Good: Test archive contains exactly 1 file" ) ;
19+
20+ const testFile = entries . filter ( function ( entry ) {
21+ return entry . entryName === "dummy.txt" ;
22+ } ) ;
23+ assert ( testFile . length === 1 , "Good: dummy.txt file exists as archive entry" ) ;
24+
25+ const readData = entries [ 0 ] . getData ( 'secret' ) ;
26+ assert ( readData . toString ( 'utf8' ) . startsWith ( 'How much wood could a woodchuck chuck' ) , "Good: buffer matches expectations" ) ;
27+
28+ // assert that the following call throws an exception
29+ assert . throws ( ( ) => {
30+ const readDataBad = entries [ 0 ] . getData ( 'badpassword' ) ;
31+ } , "Good: error thrown for bad password" ) ;
32+
33+ } ) ;
34+ } ) ;
35+
You can’t perform that action at this time.
0 commit comments