Skip to content

Commit fb553b5

Browse files
LekoMylesBorins
authored andcommitted
test: improve crypto test coverage
- Call Sign without new - Call Verify without new - Call Verify#verify with options.padding !== options.padding >> 0 - Call Verify#verify with options.saltLength !== options.saltLength >> 0 PR-URL: #17426 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 928aecc commit fb553b5

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

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

+36
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,42 @@ const certPem = fixtures.readSync('test_cert.pem', 'ascii');
1515
const keyPem = fixtures.readSync('test_key.pem', 'ascii');
1616
const modSize = 1024;
1717

18+
{
19+
const Sign = crypto.Sign;
20+
const instance = Sign('SHA256');
21+
assert(instance instanceof Sign, 'Sign is expected to return a new ' +
22+
'instance when called without `new`');
23+
}
24+
25+
{
26+
const Verify = crypto.Verify;
27+
const instance = Verify('SHA256');
28+
assert(instance instanceof Verify, 'Verify is expected to return a new ' +
29+
'instance when called without `new`');
30+
}
31+
32+
common.expectsError(
33+
() => crypto.createVerify('SHA256').verify({
34+
key: certPem,
35+
padding: undefined,
36+
}, ''),
37+
{
38+
code: 'ERR_INVALID_OPT_VALUE',
39+
type: Error,
40+
message: 'The value "undefined" is invalid for option "padding"'
41+
});
42+
43+
common.expectsError(
44+
() => crypto.createVerify('SHA256').verify({
45+
key: certPem,
46+
saltLength: undefined,
47+
}, ''),
48+
{
49+
code: 'ERR_INVALID_OPT_VALUE',
50+
type: Error,
51+
message: 'The value "undefined" is invalid for option "saltLength"'
52+
});
53+
1854
// Test signing and verifying
1955
{
2056
const s1 = crypto.createSign('SHA1')

0 commit comments

Comments
 (0)