From a38219f962ed27c25f5351a5841778f6f923950c Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 30 Jun 2020 20:15:39 +0200 Subject: [PATCH] test: add regression test for C++-created Buffer transfer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a test for a regression that occurs when transferring some `Buffer` objects that were created from C++ to a parent thread. Fixes: https://github.com/nodejs/node/issues/34126 PR-URL: https://github.com/nodejs/node/pull/34140 Reviewed-By: Gerhard Stöbich --- ...test-worker-crypto-sign-transfer-result.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/parallel/test-worker-crypto-sign-transfer-result.js diff --git a/test/parallel/test-worker-crypto-sign-transfer-result.js b/test/parallel/test-worker-crypto-sign-transfer-result.js new file mode 100644 index 00000000000000..ca5675d1426c60 --- /dev/null +++ b/test/parallel/test-worker-crypto-sign-transfer-result.js @@ -0,0 +1,30 @@ +'use strict'; +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); + +const assert = require('assert'); +const { Worker } = require('worker_threads'); +const fixturesPath = require.resolve('../common/fixtures'); + +// Test that transferring the result of e.g. crypto.sign() from Worker to parent +// thread does not crash + +const w = new Worker(` +const { parentPort } = require('worker_threads'); +const crypto = require('crypto'); +const assert = require('assert'); +const fixtures = require(${JSON.stringify(fixturesPath)}); + +const keyPem = fixtures.readKey('rsa_private.pem'); + +const buf = crypto.sign('sha256', Buffer.from('hello'), keyPem); +assert.notStrictEqual(buf.byteLength, 0); +parentPort.postMessage(buf, [buf.buffer]); +assert.strictEqual(buf.byteLength, 0); +`, { eval: true }); + +w.on('message', common.mustCall((buf) => { + assert.notStrictEqual(buf.byteLength, 0); +})); +w.on('exit', common.mustCall());