From 77f61dcc54ed14965e5980ca6173e59425945bf4 Mon Sep 17 00:00:00 2001 From: Leko Date: Mon, 4 Dec 2017 16:32:06 +0900 Subject: [PATCH 1/7] test: Add test call Hash without new keyword --- test/parallel/test-crypto-hash.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/parallel/test-crypto-hash.js b/test/parallel/test-crypto-hash.js index f55a6768900e65..ddd4c8695ff027 100644 --- a/test/parallel/test-crypto-hash.js +++ b/test/parallel/test-crypto-hash.js @@ -154,3 +154,10 @@ common.expectsError( message: 'The "algorithm" argument must be of type string' } ); + +{ + const Hash = crypto.Hash; + const instance = crypto.Hash('sha256'); + assert(instance instanceof Hash, 'Hash is expected to return a new instance' + + 'when called without `new`'); +} From d5ba19ddcd1e7af289ba02c554db9003496be12a Mon Sep 17 00:00:00 2001 From: Leko Date: Mon, 4 Dec 2017 16:42:29 +0900 Subject: [PATCH 2/7] test: Add test call Hmac without new keyword --- test/parallel/test-crypto-hmac.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/parallel/test-crypto-hmac.js b/test/parallel/test-crypto-hmac.js index 8b9473704d3032..426fd92b7d1389 100644 --- a/test/parallel/test-crypto-hmac.js +++ b/test/parallel/test-crypto-hmac.js @@ -6,6 +6,13 @@ if (!common.hasCrypto) const assert = require('assert'); const crypto = require('crypto'); +{ + const Hmac = crypto.Hmac; + const instance = crypto.Hmac('sha256'); + assert(instance instanceof Hmac, 'Hmac is expected to return a new instance' + + 'when called without `new`'); +} + { // Test HMAC const actual = crypto.createHmac('sha1', 'Node') From b38e323dab543e5f11467ec4dbdc9a8d5a5f4cdb Mon Sep 17 00:00:00 2001 From: Leko Date: Mon, 4 Dec 2017 16:43:24 +0900 Subject: [PATCH 3/7] test: Add test call Hmac with hmac=null --- test/parallel/test-crypto-hmac.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/parallel/test-crypto-hmac.js b/test/parallel/test-crypto-hmac.js index 426fd92b7d1389..c705e032512cd7 100644 --- a/test/parallel/test-crypto-hmac.js +++ b/test/parallel/test-crypto-hmac.js @@ -13,6 +13,14 @@ const crypto = require('crypto'); 'when called without `new`'); } +common.expectsError( + () => new crypto.Hmac(null), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "hmac" argument must be of type string' + }); + { // Test HMAC const actual = crypto.createHmac('sha1', 'Node') From cfa073ab4f27729af1e1e2c9186e787f85ac10d3 Mon Sep 17 00:00:00 2001 From: Leko Date: Mon, 4 Dec 2017 16:44:04 +0900 Subject: [PATCH 4/7] test: Add test call Hmac with hmac=string, key=null --- test/parallel/test-crypto-hmac.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/parallel/test-crypto-hmac.js b/test/parallel/test-crypto-hmac.js index c705e032512cd7..a6674d430749e3 100644 --- a/test/parallel/test-crypto-hmac.js +++ b/test/parallel/test-crypto-hmac.js @@ -21,6 +21,15 @@ common.expectsError( message: 'The "hmac" argument must be of type string' }); +common.expectsError( + () => new crypto.Hmac('sha1', null), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "key" argument must be one of type string, TypedArray, or ' + + 'DataView' + }); + { // Test HMAC const actual = crypto.createHmac('sha1', 'Node') From 4dc97afda677f035316b9a8604d459b799e75312 Mon Sep 17 00:00:00 2001 From: Leko Date: Mon, 4 Dec 2017 16:45:50 +0900 Subject: [PATCH 5/7] test: add missing key parameter --- test/parallel/test-crypto-hmac.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-crypto-hmac.js b/test/parallel/test-crypto-hmac.js index a6674d430749e3..56d4e15196ef5a 100644 --- a/test/parallel/test-crypto-hmac.js +++ b/test/parallel/test-crypto-hmac.js @@ -8,7 +8,7 @@ const crypto = require('crypto'); { const Hmac = crypto.Hmac; - const instance = crypto.Hmac('sha256'); + const instance = crypto.Hmac('sha256', 'Node'); assert(instance instanceof Hmac, 'Hmac is expected to return a new instance' + 'when called without `new`'); } From 380a158b263aa36265099a44d06d6a6c0a1f6813 Mon Sep 17 00:00:00 2001 From: Leko Date: Mon, 4 Dec 2017 23:47:53 +0900 Subject: [PATCH 6/7] test: add space after new line Right now it says "instance when". --- test/parallel/test-crypto-hash.js | 2 +- test/parallel/test-crypto-hmac.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-crypto-hash.js b/test/parallel/test-crypto-hash.js index ddd4c8695ff027..4702a9a5f175df 100644 --- a/test/parallel/test-crypto-hash.js +++ b/test/parallel/test-crypto-hash.js @@ -159,5 +159,5 @@ common.expectsError( const Hash = crypto.Hash; const instance = crypto.Hash('sha256'); assert(instance instanceof Hash, 'Hash is expected to return a new instance' + - 'when called without `new`'); + ' when called without `new`'); } diff --git a/test/parallel/test-crypto-hmac.js b/test/parallel/test-crypto-hmac.js index 56d4e15196ef5a..c59af23dc30ded 100644 --- a/test/parallel/test-crypto-hmac.js +++ b/test/parallel/test-crypto-hmac.js @@ -10,7 +10,7 @@ const crypto = require('crypto'); const Hmac = crypto.Hmac; const instance = crypto.Hmac('sha256', 'Node'); assert(instance instanceof Hmac, 'Hmac is expected to return a new instance' + - 'when called without `new`'); + ' when called without `new`'); } common.expectsError( From 6a967519686311a500b263285c9f8fcee37132ad Mon Sep 17 00:00:00 2001 From: Leko Date: Tue, 5 Dec 2017 13:15:03 +0900 Subject: [PATCH 7/7] test: use factory method instead of constructor --- test/parallel/test-crypto-hmac.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-crypto-hmac.js b/test/parallel/test-crypto-hmac.js index c59af23dc30ded..6c2102fe23c82c 100644 --- a/test/parallel/test-crypto-hmac.js +++ b/test/parallel/test-crypto-hmac.js @@ -14,7 +14,7 @@ const crypto = require('crypto'); } common.expectsError( - () => new crypto.Hmac(null), + () => crypto.createHmac(null), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, @@ -22,7 +22,7 @@ common.expectsError( }); common.expectsError( - () => new crypto.Hmac('sha1', null), + () => crypto.createHmac('sha1', null), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError,