-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests into internal/crypto/random.js to improve coverage #17555
Add tests into internal/crypto/random.js to improve coverage #17555
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems fine but you could make it even better by using something similar to line 510. That is, having a forEach
that iterates over several different types and makes sure that none of them are accepted for the callback param.
The current version makes sure that null
isn't accepted but if someone accidentally changed the function to have a falsey check instead of typeof
then it wouldn't catch that.
@apapirovski Thank you for review.
I think it would be nice. |
test/parallel/test-crypto-random.js
Outdated
@@ -487,7 +487,17 @@ common.expectsError( | |||
} | |||
); | |||
|
|||
common.expectsError( | |||
() => crypto.randomBytes(1, null), |
There was a problem hiding this comment.
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. :)
There was a problem hiding this comment.
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');
Landed in 7a055f1 |
- 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]>
- 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]>
I added these test case:
Current coverage is here: https://coverage.nodejs.org/coverage-06e1b0386196f8f8/root/internal/crypto/random.js.html
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test