Skip to content

Commit

Permalink
test: improve crypto/random.js coverage
Browse files Browse the repository at this point in the history
- Call randomBytes with a non-function callback
- Call randomFill with a non-function callback

PR-URL: #17555
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
Leko authored and MylesBorins committed Jan 8, 2018
1 parent 316da5e commit b379d8d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/parallel/test-crypto-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ common.expectsError(
);

[1, true, NaN, null, undefined, {}, []].forEach((i) => {
const buf = Buffer.alloc(10);
common.expectsError(
() => crypto.randomFillSync(i),
{
Expand All @@ -502,4 +503,22 @@ common.expectsError(
type: TypeError
}
);
common.expectsError(
() => crypto.randomFill(buf, 0, 10, i),
{
code: 'ERR_INVALID_CALLBACK',
type: TypeError,
message: 'Callback must be a function',
});
});

[1, true, NaN, null, {}, []].forEach((i) => {
common.expectsError(
() => crypto.randomBytes(1, i),
{
code: 'ERR_INVALID_CALLBACK',
type: TypeError,
message: 'Callback must be a function',
}
);
});

0 comments on commit b379d8d

Please sign in to comment.