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 <apapirovski@mac.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
Leko authored and apapirovski committed Dec 12, 2017
1 parent e8a5f7b commit 7a055f1
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 7a055f1

Please sign in to comment.