Skip to content
Merged
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
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: #36997
  • Loading branch information
tniessen committed Mar 17, 2023
commit 2416f780a5b26b1d6b1669b0831a68f791e854d2
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