Skip to content

Commit 3f66109

Browse files
tniessenaddaleax
authored andcommitted
test: improve test coverage of native crypto code
PR-URL: #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>
1 parent 2a85cc7 commit 3f66109

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

test/parallel/test-crypto-cipheriv-decipheriv.js

+12
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,15 @@ for (let n = 1; n < 256; n += 1) {
205205
if (common.hasFipsCrypto && n < 12) continue;
206206
crypto.createCipheriv('aes-128-gcm', Buffer.alloc(16), Buffer.alloc(n));
207207
}
208+
209+
{
210+
// Passing an invalid cipher name should throw.
211+
assert.throws(
212+
() => crypto.createCipheriv('aes-127', Buffer.alloc(16), null),
213+
/Unknown cipher/);
214+
215+
// Passing a key with an invalid length should throw.
216+
assert.throws(
217+
() => crypto.createCipheriv('aes-128-ecb', Buffer.alloc(17), null),
218+
/Invalid key length/);
219+
}

test/parallel/test-crypto-hmac.js

+6
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,9 @@ common.expectsError(
449449
assert.deepStrictEqual(h.digest('latin1'), '');
450450
}
451451
}
452+
453+
{
454+
assert.throws(
455+
() => crypto.createHmac('sha7', 'key'),
456+
/Unknown message digest/);
457+
}

test/parallel/test-crypto-sign-verify.js

+6
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,9 @@ common.expectsError(
363363
assert.throws(() => verify.verify('test', input), errObj);
364364
});
365365
}
366+
367+
{
368+
assert.throws(
369+
() => crypto.createSign('sha8'),
370+
/Unknown message digest/);
371+
}

0 commit comments

Comments
 (0)