From 512f34f096807df562de071e34bba8ffe00d41bb Mon Sep 17 00:00:00 2001 From: Leko Date: Sat, 9 Dec 2017 02:29:34 +0900 Subject: [PATCH 1/4] test: add test case where call randomFill with argument cb is not a function --- test/parallel/test-crypto-random.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/parallel/test-crypto-random.js b/test/parallel/test-crypto-random.js index 320a4358ff3ccb..38239c707519e6 100644 --- a/test/parallel/test-crypto-random.js +++ b/test/parallel/test-crypto-random.js @@ -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'); From 16b46772a3f66e053fb77af5ccd9cb39c7f1d34e Mon Sep 17 00:00:00 2001 From: Leko Date: Sat, 9 Dec 2017 02:31:33 +0900 Subject: [PATCH 2/4] test: test: add test case where call randomBytes with cb is not a function --- test/parallel/test-crypto-random.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/parallel/test-crypto-random.js b/test/parallel/test-crypto-random.js index 38239c707519e6..bca35884a590d8 100644 --- a/test/parallel/test-crypto-random.js +++ b/test/parallel/test-crypto-random.js @@ -498,6 +498,15 @@ common.expectsError( } ); +common.expectsError( + () => crypto.randomBytes(1, null), + { + code: 'ERR_INVALID_CALLBACK', + type: TypeError, + message: 'Callback must be a function', + } +); + [1, true, NaN, null, undefined, {}, []].forEach((i) => { common.expectsError( () => crypto.randomFillSync(i), From c1ffcfb7fccd827dd5ebadad24622be00058b4b6 Mon Sep 17 00:00:00 2001 From: Leko Date: Sat, 9 Dec 2017 23:08:15 +0900 Subject: [PATCH 3/4] test: update test to check various invalid callback types --- test/parallel/test-crypto-random.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/test/parallel/test-crypto-random.js b/test/parallel/test-crypto-random.js index bca35884a590d8..3de8079c782b01 100644 --- a/test/parallel/test-crypto-random.js +++ b/test/parallel/test-crypto-random.js @@ -119,17 +119,6 @@ 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'); @@ -508,6 +497,7 @@ common.expectsError( ); [1, true, NaN, null, undefined, {}, []].forEach((i) => { + const buf = Buffer.alloc(10); common.expectsError( () => crypto.randomFillSync(i), { @@ -522,4 +512,11 @@ common.expectsError( type: TypeError } ); + common.expectsError( + () => crypto.randomFill(buf, 0, 10, i), + { + code: 'ERR_INVALID_CALLBACK', + type: TypeError, + message: 'Callback must be a function', + }); }); From ded1097fe2d467a504f17c05ccf351fd5e18b84c Mon Sep 17 00:00:00 2001 From: Leko Date: Sun, 10 Dec 2017 20:25:16 +0900 Subject: [PATCH 4/4] test: Move crypto.randomBytes test to inside the new forEach loop --- test/parallel/test-crypto-random.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/test/parallel/test-crypto-random.js b/test/parallel/test-crypto-random.js index 3de8079c782b01..3926eb385044d9 100644 --- a/test/parallel/test-crypto-random.js +++ b/test/parallel/test-crypto-random.js @@ -487,15 +487,6 @@ common.expectsError( } ); -common.expectsError( - () => crypto.randomBytes(1, null), - { - code: 'ERR_INVALID_CALLBACK', - type: TypeError, - message: 'Callback must be a function', - } -); - [1, true, NaN, null, undefined, {}, []].forEach((i) => { const buf = Buffer.alloc(10); common.expectsError( @@ -520,3 +511,14 @@ common.expectsError( 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', + } + ); +});