Add tests into internal/crypto/random.js to improve coverage#17555
Add tests into internal/crypto/random.js to improve coverage#17555Leko wants to merge 4 commits intonodejs:masterfrom Leko:add_test_to_improve_crypto-random_coverage
Conversation
There was a problem hiding this comment.
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
| ); | ||
|
|
||
| common.expectsError( | ||
| () => crypto.randomBytes(1, null), |
There was a problem hiding this comment.
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.
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 <apapirovski@mac.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
- 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>
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