test: merge test with unnecessary child process

Test didn't require child process creation. While this test has not been
unstable, child process creation is slower and can be flaky in ci, so
test directly for the segfault regression.

PR-URL: https://github.com/nodejs/node/pull/25025
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
This commit is contained in:
Sam Roberts authored and Rich Trott committed 2018-12-16 21:29:15 -08:00
1 parent 3439c955ab
commit b54d4a68e3
3 files changed
+21 -27

No files matched your search

+11
View File
@@ -111,6 +111,17 @@ assert.throws(function() {
crypto.createHash('xyzzy');
}, /Digest method not supported/);
// Issue https://github.com/nodejs/node/issues/9819: throwing encoding used to
// segfault.
common.expectsError(
() => crypto.createHash('sha256').digest({
toString: () => { throw new Error('boom'); },
}),
{
type: Error,
message: 'boom'
});
// Default UTF-8 encoding
const hutf8 = crypto.createHash('sha512').update('УТФ-8 text').digest('hex');
assert.strictEqual(
+10
View File
@@ -21,6 +21,16 @@ common.expectsError(
message: 'The "hmac" argument must be of type string. Received type object'
});
// This used to segfault. See: https://github.com/nodejs/node/issues/9819
common.expectsError(
() => crypto.createHmac('sha256', 'key').digest({
toString: () => { throw new Error('boom'); },
}),
{
type: Error,
message: 'boom'
});
common.expectsError(
() => crypto.createHmac('sha1', null),
{
@@ -1,27 +0,0 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
// This test ensures that node doesn't SEGFAULT when either of
// `crypto.createHash` or `crypto.createHmac` are given an object that defines
// a throwing `toString`.
// https://github.com/nodejs/node/issues/9819
const assert = require('assert');
const execFile = require('child_process').execFile;
const setup = 'const enc = { toString: () => { throw new Error("xyz"); } };';
const scripts = [
'crypto.createHash("sha256").digest(enc)',
'crypto.createHmac("sha256", "msg").digest(enc)'
];
scripts.forEach((script) => {
const node = process.execPath;
const code = `${setup};${script}`;
execFile(node, [ '-e', code ], common.mustCall((err, stdout, stderr) => {
assert(stderr.includes('Error: xyz'), 'digest crashes');
}));
});