Skip to content

Commit 1bfa3bb

Browse files
committed
Additional test for Info-Zip generated ZipCrypto encrypted file. Relates to Issue 471.
1 parent e1cddb3 commit 1bfa3bb

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
331 Bytes
Binary file not shown.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+

0 commit comments

Comments
 (0)