mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
992fba4b49
PR-URL: https://github.com/nodejs/node/pull/45811 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
35 lines
1012 B
JavaScript
35 lines
1012 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
// Issue https://github.com/nodejs/node/issues/35263
|
|
// Description: Test that passing keyobject to worker thread does not crash.
|
|
const {
|
|
generateKeySync,
|
|
generateKeyPairSync,
|
|
} = require('crypto');
|
|
const { subtle } = globalThis.crypto;
|
|
|
|
const assert = require('assert');
|
|
|
|
const { Worker, isMainThread, workerData } = require('worker_threads');
|
|
|
|
if (isMainThread) {
|
|
(async () => {
|
|
const secretKey = generateKeySync('aes', { length: 128 });
|
|
const { publicKey, privateKey } = generateKeyPairSync('rsa', {
|
|
modulusLength: 1024
|
|
});
|
|
const cryptoKey = await subtle.generateKey(
|
|
{ name: 'AES-CBC', length: 128 }, false, ['encrypt']);
|
|
|
|
for (const key of [secretKey, publicKey, privateKey, cryptoKey]) {
|
|
new Worker(__filename, { workerData: key });
|
|
}
|
|
})().then(common.mustCall());
|
|
} else {
|
|
console.log(workerData);
|
|
assert.notDeepStrictEqual(workerData, {});
|
|
}
|