Skip to content
Closed
Changes from 2 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
20 changes: 20 additions & 0 deletions test/parallel/test-crypto-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ process.setMaxListeners(256);
assert.notStrictEqual(before, after);
}

{
const buf = Buffer.alloc(10);
common.expectsError(
() => crypto.randomFill(buf, 0, 10, null),
{
code: 'ERR_INVALID_CALLBACK',
type: TypeError,
message: 'Callback must be a function',
});
}

{
const buf = Buffer.alloc(10);
const before = buf.toString('hex');
Expand Down Expand Up @@ -487,6 +498,15 @@ common.expectsError(
}
);

common.expectsError(
() => crypto.randomBytes(1, null),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this also be put inside the forEach loop? Or have a new forEach loop around it? Then we're good to go. :)

Copy link
Copy Markdown
Contributor Author

@Leko Leko Dec 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it to inside the new forEach loop to omit undefined in test case.

function randomBytes(size, cb) {
  assertSize(size);
  Iif (cb !== undefined && typeof cb !== 'function') // <- undefined is omitted
    throw new errors.TypeError('ERR_INVALID_CALLBACK');

{
code: 'ERR_INVALID_CALLBACK',
type: TypeError,
message: 'Callback must be a function',
}
);

[1, true, NaN, null, undefined, {}, []].forEach((i) => {
common.expectsError(
() => crypto.randomFillSync(i),
Expand Down