Skip to content

Commit 4411a99

Browse files
RaisinTenMylesBorins
authored andcommitted
test: fix flaky test-webcrypto-encrypt-decrypt-aes
* Use a copy of plaintext to prevent tampering of the original * Since subtle.decrypt returns a Promise containing an ArrayBuffer and ArrayBuffers cannot be modified directly, create a Buffer from it right away so that the modification in the next line works as intended Fixes: #35586 PR-URL: #37380 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
1 parent 38f6e5a commit 4411a99

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

test/parallel/parallel.status

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ test-worker-memory: PASS,FLAKY
2727
test-worker-message-port-transfer-terminate: PASS,FLAKY
2828

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

3331
[$system==macos]
3432

test/parallel/test-webcrypto-encrypt-decrypt-aes.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const assert = require('assert');
99
const { getRandomValues, subtle } = require('crypto').webcrypto;
1010

1111
async function testEncrypt({ keyBuffer, algorithm, plaintext, result }) {
12+
// Using a copy of plaintext to prevent tampering of the original
13+
plaintext = Buffer.from(plaintext);
14+
1215
const key = await subtle.importKey(
1316
'raw',
1417
keyBuffer,
@@ -23,8 +26,10 @@ async function testEncrypt({ keyBuffer, algorithm, plaintext, result }) {
2326
Buffer.from(output).toString('hex'),
2427
Buffer.from(result).toString('hex'));
2528

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

2934
assert.strictEqual(
3035
Buffer.from(check).toString('hex'),

0 commit comments

Comments
 (0)