Skip to content

Commit

Permalink
test: improve crypto test coverage
Browse files Browse the repository at this point in the history
- 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 <cjihrig@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
Leko authored and MylesBorins committed Dec 12, 2017
1 parent 928aecc commit fb553b5
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/parallel/test-crypto-sign-verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,42 @@ const certPem = fixtures.readSync('test_cert.pem', 'ascii');
const keyPem = fixtures.readSync('test_key.pem', 'ascii');
const modSize = 1024;

{
const Sign = crypto.Sign;
const instance = Sign('SHA256');
assert(instance instanceof Sign, 'Sign is expected to return a new ' +
'instance when called without `new`');
}

{
const Verify = crypto.Verify;
const instance = Verify('SHA256');
assert(instance instanceof Verify, 'Verify is expected to return a new ' +
'instance when called without `new`');
}

common.expectsError(
() => crypto.createVerify('SHA256').verify({
key: certPem,
padding: undefined,
}, ''),
{
code: 'ERR_INVALID_OPT_VALUE',
type: Error,
message: 'The value "undefined" is invalid for option "padding"'
});

common.expectsError(
() => crypto.createVerify('SHA256').verify({
key: certPem,
saltLength: undefined,
}, ''),
{
code: 'ERR_INVALID_OPT_VALUE',
type: Error,
message: 'The value "undefined" is invalid for option "saltLength"'
});

// Test signing and verifying
{
const s1 = crypto.createSign('SHA1')
Expand Down

0 comments on commit fb553b5

Please sign in to comment.