Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor of zlib-from-gzip-with-trailing-garbage #10674

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions test/parallel/test-zlib-from-gzip-with-trailing-garbage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ let data = Buffer.concat([
Buffer(10).fill(0)
]);

assert.equal(zlib.gunzipSync(data).toString(), 'abcdef');
assert.strictEqual(zlib.gunzipSync(data).toString(), 'abcdef');

zlib.gunzip(data, common.mustCall((err, result) => {
assert.ifError(err);
assert.equal(result, 'abcdef', 'result should match original string');
assert.strictEqual(
result.toString(),
'abcdef',
'result should match original string'
);
}));

// if the trailing garbage happens to look like a gzip header, it should
Expand All @@ -28,10 +32,16 @@ data = Buffer.concat([
Buffer(10).fill(0)
]);

assert.throws(() => zlib.gunzipSync(data));
assert.throws(
() => zlib.gunzipSync(data),
/^Error: unknown compression method$/
);

zlib.gunzip(data, common.mustCall((err, result) => {
assert(err);
assert(err instanceof Error);
assert.strictEqual(err.code, 'Z_DATA_ERROR');
assert.strictEqual(err.message, 'unknown compression method');
assert.strictEqual(result, undefined);
}));

// In this case the trailing junk is too short to be a gzip segment
Expand All @@ -42,8 +52,14 @@ data = Buffer.concat([
Buffer([0x1f, 0x8b, 0xff, 0xff])
]);

assert.throws(() => zlib.gunzipSync(data));
assert.throws(
() => zlib.gunzipSync(data),
/^Error: unknown compression method$/
);

zlib.gunzip(data, common.mustCall((err, result) => {
assert(err);
assert(err instanceof Error);
assert.strictEqual(err.code, 'Z_DATA_ERROR');
assert.strictEqual(err.message, 'unknown compression method');
assert.strictEqual(result, undefined);
}));