From a407a48bdf7aa52e28490c31ce22a6647edfcef0 Mon Sep 17 00:00:00 2001 From: Leko Date: Mon, 4 Dec 2017 16:32:06 +0900 Subject: [PATCH] test: expand coverage for crypto crypto.Hash - Call constructor without new keyword crypto.Hmac - Call constructor without new keyword - Call constructor with typeof hmac != string - Call constructor with typeof hmac = string, typeof key != string PR-URL: https://github.com/nodejs/node/pull/17447 Reviewed-By: Luigi Pinca Reviewed-By: Anatoli Papirovski Reviewed-By: Michael Dawson Reviewed-By: Jon Moss Reviewed-By: Ruben Bridgewater --- test/parallel/test-crypto-hash.js | 7 +++++++ test/parallel/test-crypto-hmac.js | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/test/parallel/test-crypto-hash.js b/test/parallel/test-crypto-hash.js index f55a6768900e65..4702a9a5f175df 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`'); +} diff --git a/test/parallel/test-crypto-hmac.js b/test/parallel/test-crypto-hmac.js index 8b9473704d3032..6c2102fe23c82c 100644 --- a/test/parallel/test-crypto-hmac.js +++ b/test/parallel/test-crypto-hmac.js @@ -6,6 +6,30 @@ if (!common.hasCrypto) const assert = require('assert'); 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`'); +} + +common.expectsError( + () => crypto.createHmac(null), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "hmac" argument must be of type string' + }); + +common.expectsError( + () => crypto.createHmac('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')