Skip to content

Commit

Permalink
test: expand coverage for crypto
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Leko authored and MylesBorins committed Dec 12, 2017
1 parent 35d492c commit a407a48
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/parallel/test-crypto-hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`');
}
24 changes: 24 additions & 0 deletions test/parallel/test-crypto-hmac.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit a407a48

Please sign in to comment.