zlib: tighten up dictionary tests
Uses const where possible, removes inaccurate comments, prefers strictEqual where possible, ensures functions with assertions are called and enures the inflater has correct encoding set. PR-URL: https://github.com/nodejs/node/pull/8512 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
c775514e56
commit
2b5acda7a2
@ -3,7 +3,9 @@ const common = require('../common');
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
|
|
||||||
// Should raise an error, not trigger an assertion in src/node_zlib.cc
|
// String "test" encoded with dictionary "dict".
|
||||||
|
const input = Buffer.from([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]);
|
||||||
|
|
||||||
{
|
{
|
||||||
const stream = zlib.createInflate();
|
const stream = zlib.createInflate();
|
||||||
|
|
||||||
@ -11,11 +13,9 @@ const zlib = require('zlib');
|
|||||||
assert(/Missing dictionary/.test(err.message));
|
assert(/Missing dictionary/.test(err.message));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// String "test" encoded with dictionary "dict".
|
stream.write(input);
|
||||||
stream.write(Buffer.from([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should raise an error, not trigger an assertion in src/node_zlib.cc
|
|
||||||
{
|
{
|
||||||
const stream = zlib.createInflate({ dictionary: Buffer.from('fail') });
|
const stream = zlib.createInflate({ dictionary: Buffer.from('fail') });
|
||||||
|
|
||||||
@ -23,11 +23,9 @@ const zlib = require('zlib');
|
|||||||
assert(/Bad dictionary/.test(err.message));
|
assert(/Bad dictionary/.test(err.message));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// String "test" encoded with dictionary "dict".
|
stream.write(input);
|
||||||
stream.write(Buffer.from([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should raise an error, not trigger an assertion in src/node_zlib.cc
|
|
||||||
{
|
{
|
||||||
const stream = zlib.createInflateRaw({ dictionary: Buffer.from('fail') });
|
const stream = zlib.createInflateRaw({ dictionary: Buffer.from('fail') });
|
||||||
|
|
||||||
@ -37,6 +35,5 @@ const zlib = require('zlib');
|
|||||||
assert(/invalid/.test(err.message));
|
assert(/invalid/.test(err.message));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// String "test" encoded with dictionary "dict".
|
stream.write(input);
|
||||||
stream.write(Buffer.from([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]));
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
// test compression/decompression with dictionary
|
// test compression/decompression with dictionary
|
||||||
|
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
|
|
||||||
@ -32,6 +32,7 @@ function basicDictionaryTest() {
|
|||||||
let output = '';
|
let output = '';
|
||||||
const deflate = zlib.createDeflate({ dictionary: spdyDict });
|
const deflate = zlib.createDeflate({ dictionary: spdyDict });
|
||||||
const inflate = zlib.createInflate({ dictionary: spdyDict });
|
const inflate = zlib.createInflate({ dictionary: spdyDict });
|
||||||
|
inflate.setEncoding('utf-8');
|
||||||
|
|
||||||
deflate.on('data', function(chunk) {
|
deflate.on('data', function(chunk) {
|
||||||
inflate.write(chunk);
|
inflate.write(chunk);
|
||||||
@ -45,9 +46,9 @@ function basicDictionaryTest() {
|
|||||||
inflate.end();
|
inflate.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
inflate.on('end', function() {
|
inflate.on('end', common.mustCall(function() {
|
||||||
assert.equal(input, output);
|
assert.strictEqual(input, output);
|
||||||
});
|
}));
|
||||||
|
|
||||||
deflate.write(input);
|
deflate.write(input);
|
||||||
deflate.end();
|
deflate.end();
|
||||||
@ -58,6 +59,7 @@ function deflateResetDictionaryTest() {
|
|||||||
let output = '';
|
let output = '';
|
||||||
const deflate = zlib.createDeflate({ dictionary: spdyDict });
|
const deflate = zlib.createDeflate({ dictionary: spdyDict });
|
||||||
const inflate = zlib.createInflate({ dictionary: spdyDict });
|
const inflate = zlib.createInflate({ dictionary: spdyDict });
|
||||||
|
inflate.setEncoding('utf-8');
|
||||||
|
|
||||||
deflate.on('data', function(chunk) {
|
deflate.on('data', function(chunk) {
|
||||||
if (doneReset)
|
if (doneReset)
|
||||||
@ -72,9 +74,9 @@ function deflateResetDictionaryTest() {
|
|||||||
inflate.end();
|
inflate.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
inflate.on('end', function() {
|
inflate.on('end', common.mustCall(function() {
|
||||||
assert.equal(input, output);
|
assert.strictEqual(input, output);
|
||||||
});
|
}));
|
||||||
|
|
||||||
deflate.write(input);
|
deflate.write(input);
|
||||||
deflate.flush(function() {
|
deflate.flush(function() {
|
||||||
@ -89,6 +91,7 @@ function rawDictionaryTest() {
|
|||||||
let output = '';
|
let output = '';
|
||||||
const deflate = zlib.createDeflateRaw({ dictionary: spdyDict });
|
const deflate = zlib.createDeflateRaw({ dictionary: spdyDict });
|
||||||
const inflate = zlib.createInflateRaw({ dictionary: spdyDict });
|
const inflate = zlib.createInflateRaw({ dictionary: spdyDict });
|
||||||
|
inflate.setEncoding('utf-8');
|
||||||
|
|
||||||
deflate.on('data', function(chunk) {
|
deflate.on('data', function(chunk) {
|
||||||
inflate.write(chunk);
|
inflate.write(chunk);
|
||||||
@ -102,9 +105,9 @@ function rawDictionaryTest() {
|
|||||||
inflate.end();
|
inflate.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
inflate.on('end', function() {
|
inflate.on('end', common.mustCall(function() {
|
||||||
assert.equal(input, output);
|
assert.strictEqual(input, output);
|
||||||
});
|
}));
|
||||||
|
|
||||||
deflate.write(input);
|
deflate.write(input);
|
||||||
deflate.end();
|
deflate.end();
|
||||||
@ -115,6 +118,7 @@ function deflateRawResetDictionaryTest() {
|
|||||||
let output = '';
|
let output = '';
|
||||||
const deflate = zlib.createDeflateRaw({ dictionary: spdyDict });
|
const deflate = zlib.createDeflateRaw({ dictionary: spdyDict });
|
||||||
const inflate = zlib.createInflateRaw({ dictionary: spdyDict });
|
const inflate = zlib.createInflateRaw({ dictionary: spdyDict });
|
||||||
|
inflate.setEncoding('utf-8');
|
||||||
|
|
||||||
deflate.on('data', function(chunk) {
|
deflate.on('data', function(chunk) {
|
||||||
if (doneReset)
|
if (doneReset)
|
||||||
@ -129,9 +133,9 @@ function deflateRawResetDictionaryTest() {
|
|||||||
inflate.end();
|
inflate.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
inflate.on('end', function() {
|
inflate.on('end', common.mustCall(function() {
|
||||||
assert.equal(input, output);
|
assert.strictEqual(input, output);
|
||||||
});
|
}));
|
||||||
|
|
||||||
deflate.write(input);
|
deflate.write(input);
|
||||||
deflate.flush(function() {
|
deflate.flush(function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user