Skip to content

Commit

Permalink
test: fix 'checks' validation test for checkPrime
Browse files Browse the repository at this point in the history
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: #36997
PR-URL: #47139
Reviewed-By: Filip Skokan <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
tniessen authored and RafaelGSS committed Apr 7, 2023
1 parent 5749dfa commit 45e7b10
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions test/parallel/test-crypto-prime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])));
Expand Down

0 comments on commit 45e7b10

Please sign in to comment.