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 <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Leko 2017-12-04 16:32:06 +09:00 коммит произвёл Anatoli Papirovski
Родитель c892f6f97d
Коммит 3d645338a0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 614E2E1ABEB4B2C0
2 изменённых файлов: 31 добавлений и 0 удалений

Просмотреть файл

@ -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`');
}

Просмотреть файл

@ -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')