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: fix flaky test-webcrypto-encrypt-decrypt-aes #37380

Closed
Closed
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions test/parallel/parallel.status
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ test-worker-memory: PASS,FLAKY
test-worker-message-port-transfer-terminate: PASS,FLAKY

[$system==linux]
# https://github.com/nodejs/node/issues/35586
test-webcrypto-encrypt-decrypt-aes: PASS,FLAKY

[$system==macos]

Expand Down
9 changes: 7 additions & 2 deletions test/parallel/test-webcrypto-encrypt-decrypt-aes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const assert = require('assert');
const { getRandomValues, subtle } = require('crypto').webcrypto;

async function testEncrypt({ keyBuffer, algorithm, plaintext, result }) {
// Using a copy of plaintext to prevent tampering of the original
plaintext = Buffer.from(plaintext);

const key = await subtle.importKey(
'raw',
keyBuffer,
Expand All @@ -23,8 +26,10 @@ async function testEncrypt({ keyBuffer, algorithm, plaintext, result }) {
Buffer.from(output).toString('hex'),
Buffer.from(result).toString('hex'));

const check = await subtle.decrypt(algorithm, key, output);
output[0] = 255 - output[0];
// Converting the returned ArrayBuffer into a Buffer right away,
// so that the next line works
const check = Buffer.from(await subtle.decrypt(algorithm, key, output));
check[0] = 255 - check[0];

assert.strictEqual(
Buffer.from(check).toString('hex'),
Expand Down