From 2416f780a5b26b1d6b1669b0831a68f791e854d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Fri, 17 Mar 2023 16:31:56 +0000 Subject: [PATCH] test: fix 'checks' validation test for checkPrime This test had two problems: * The first argument was a number in both cases, which is what caused the (expected) ERR_INVALID_ARG_TYPE error -- the validity of the 'checks' option was not actually verified at all. Thus, the first argument should be valid for this particular test. * The function returned by common.mustNotCall() was passed to assert.throws() as a third argument instead of being passed to checkPrime() as a third argument. (Isn't JavaScript great?) This again led to the (expected) ERR_INVALID_ARG_TYPE error, but again, the validity of the 'checks' option was not verified. Fix both issues by ensuring that all arguments except the 'checks' option are valid. Refs: https://github.com/nodejs/node/pull/36997 --- test/parallel/test-crypto-prime.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/parallel/test-crypto-prime.js b/test/parallel/test-crypto-prime.js index 88eca54bb90560..5eef83fb266bb8 100644 --- a/test/parallel/test-crypto-prime.js +++ b/test/parallel/test-crypto-prime.js @@ -229,14 +229,16 @@ generatePrime( }); }); -['hello', {}, []].forEach((i) => { - assert.throws(() => checkPrime(2, { checks: i }), { - code: 'ERR_INVALID_ARG_TYPE' - }, common.mustNotCall()); - assert.throws(() => checkPrimeSync(2, { checks: i }), { - code: 'ERR_INVALID_ARG_TYPE' +for (const checks of ['hello', {}, []]) { + assert.throws(() => checkPrime(2n, { checks }, common.mustNotCall()), { + code: 'ERR_INVALID_ARG_TYPE', + message: /checks/ }); -}); + assert.throws(() => checkPrimeSync(2n, { checks }), { + code: 'ERR_INVALID_ARG_TYPE', + message: /checks/ + }); +} assert(!checkPrimeSync(Buffer.from([0x1]))); assert(checkPrimeSync(Buffer.from([0x2])));