Skip to content

Commit

Permalink
test: improve test coverage of native crypto code
Browse files Browse the repository at this point in the history
PR-URL: #25400
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Sam Roberts <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
tniessen authored and MylesBorins committed May 16, 2019
1 parent 21500a8 commit 9833bff
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/parallel/test-crypto-cipheriv-decipheriv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
}
6 changes: 6 additions & 0 deletions test/parallel/test-crypto-hmac.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,9 @@ common.expectsError(
assert.deepStrictEqual(h.digest('latin1'), '');
}
}

{
assert.throws(
() => crypto.createHmac('sha7', 'key'),
/Unknown message digest/);
}
6 changes: 6 additions & 0 deletions test/parallel/test-crypto-sign-verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,9 @@ common.expectsError(
assert.throws(() => verify.verify('test', input), errObj);
});
}

{
assert.throws(
() => crypto.createSign('sha8'),
/Unknown message digest/);
}

0 comments on commit 9833bff

Please sign in to comment.