test: improve test coverage of native crypto code

PR-URL: https://github.com/nodejs/node/pull/25400
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Tobias Nießen 2019-01-07 20:27:31 +01:00
parent 84f0581d36
commit 7710235ec3
No known key found for this signature in database
GPG Key ID: 718207F8FD156B70
3 changed files with 24 additions and 0 deletions

View File

@ -205,3 +205,15 @@ for (let n = 1; n < 256; n += 1) {
if (common.hasFipsCrypto && n < 12) continue;
crypto.createCipheriv('aes-128-gcm', Buffer.alloc(16), Buffer.alloc(n));
}
{
// Passing an invalid cipher name should throw.
assert.throws(
() => crypto.createCipheriv('aes-127', Buffer.alloc(16), null),
/Unknown cipher/);
// Passing a key with an invalid length should throw.
assert.throws(
() => crypto.createCipheriv('aes-128-ecb', Buffer.alloc(17), null),
/Invalid key length/);
}

View File

@ -449,3 +449,9 @@ common.expectsError(
assert.deepStrictEqual(h.digest('latin1'), '');
}
}
{
assert.throws(
() => crypto.createHmac('sha7', 'key'),
/Unknown message digest/);
}

View File

@ -363,3 +363,9 @@ common.expectsError(
assert.throws(() => verify.verify('test', input), errObj);
});
}
{
assert.throws(
() => crypto.createSign('sha8'),
/Unknown message digest/);
}