From 7a055f1d399a74dc6ed59a6f3f70da2cf6a14847 Mon Sep 17 00:00:00 2001 From: Leko Date: Sat, 9 Dec 2017 02:29:34 +0900 Subject: [PATCH] test: improve crypto/random.js coverage - Call randomBytes with a non-function callback - Call randomFill with a non-function callback PR-URL: https://github.com/nodejs/node/pull/17555 Reviewed-By: Anatoli Papirovski Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca --- test/parallel/test-crypto-random.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/parallel/test-crypto-random.js b/test/parallel/test-crypto-random.js index 320a4358ff3ccb..3926eb385044d9 100644 --- a/test/parallel/test-crypto-random.js +++ b/test/parallel/test-crypto-random.js @@ -488,6 +488,7 @@ common.expectsError( ); [1, true, NaN, null, undefined, {}, []].forEach((i) => { + const buf = Buffer.alloc(10); common.expectsError( () => crypto.randomFillSync(i), { @@ -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', + } + ); });