Skip to content

Commit a407a48

Browse files
LekoMylesBorins
authored andcommittedDec 12, 2017
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: #17447 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 35d492c commit a407a48

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
 

‎test/parallel/test-crypto-hash.js

+7
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,10 @@ common.expectsError(
154154
message: 'The "algorithm" argument must be of type string'
155155
}
156156
);
157+
158+
{
159+
const Hash = crypto.Hash;
160+
const instance = crypto.Hash('sha256');
161+
assert(instance instanceof Hash, 'Hash is expected to return a new instance' +
162+
' when called without `new`');
163+
}

‎test/parallel/test-crypto-hmac.js

+24
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,30 @@ if (!common.hasCrypto)
66
const assert = require('assert');
77
const crypto = require('crypto');
88

9+
{
10+
const Hmac = crypto.Hmac;
11+
const instance = crypto.Hmac('sha256', 'Node');
12+
assert(instance instanceof Hmac, 'Hmac is expected to return a new instance' +
13+
' when called without `new`');
14+
}
15+
16+
common.expectsError(
17+
() => crypto.createHmac(null),
18+
{
19+
code: 'ERR_INVALID_ARG_TYPE',
20+
type: TypeError,
21+
message: 'The "hmac" argument must be of type string'
22+
});
23+
24+
common.expectsError(
25+
() => crypto.createHmac('sha1', null),
26+
{
27+
code: 'ERR_INVALID_ARG_TYPE',
28+
type: TypeError,
29+
message: 'The "key" argument must be one of type string, TypedArray, or ' +
30+
'DataView'
31+
});
32+
933
{
1034
// Test HMAC
1135
const actual = crypto.createHmac('sha1', 'Node')

0 commit comments

Comments
 (0)