From c8b1459a06c5cf6f14dd88c92887b64942d16a7b Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Mon, 15 Feb 2021 18:50:54 +0530 Subject: [PATCH 1/3] 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: https://github.com/nodejs/node/issues/35586 --- test/parallel/test-webcrypto-encrypt-decrypt-aes.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-webcrypto-encrypt-decrypt-aes.js b/test/parallel/test-webcrypto-encrypt-decrypt-aes.js index 38d2b70bcb0567..1bf3b9ed1c60d2 100644 --- a/test/parallel/test-webcrypto-encrypt-decrypt-aes.js +++ b/test/parallel/test-webcrypto-encrypt-decrypt-aes.js @@ -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, @@ -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'), From 0a0fe6facc23b0c701f07df178a0e304cda1b1a2 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Mon, 15 Feb 2021 19:05:59 +0530 Subject: [PATCH 2/3] fixup! test: fix flaky test-webcrypto-encrypt-decrypt-aes --- test/parallel/test-webcrypto-encrypt-decrypt-aes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-webcrypto-encrypt-decrypt-aes.js b/test/parallel/test-webcrypto-encrypt-decrypt-aes.js index 1bf3b9ed1c60d2..7adb18918d2205 100644 --- a/test/parallel/test-webcrypto-encrypt-decrypt-aes.js +++ b/test/parallel/test-webcrypto-encrypt-decrypt-aes.js @@ -9,7 +9,7 @@ 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 + // Using a copy of plaintext to prevent tampering of the original plaintext = Buffer.from(plaintext); const key = await subtle.importKey( @@ -26,7 +26,7 @@ async function testEncrypt({ keyBuffer, algorithm, plaintext, result }) { Buffer.from(output).toString('hex'), Buffer.from(result).toString('hex')); - // converting the returned ArrayBuffer into a Buffer right away, + // 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]; From 1af93760445011bcfdfe7a1ac67cb553087e2571 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Mon, 15 Feb 2021 20:46:26 +0530 Subject: [PATCH 3/3] remove flaky test from parallel.status --- test/parallel/parallel.status | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/parallel/parallel.status b/test/parallel/parallel.status index 8f886c76333e3b..574bc1c9fe13a3 100644 --- a/test/parallel/parallel.status +++ b/test/parallel/parallel.status @@ -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]