Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance crypto/sig.js coverage #17426

Closed
wants to merge 9 commits into from
34 changes: 34 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,40 @@ 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.ok(instance instanceof Sign, 'call sign constructor without new');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message here seems to be more of a description of the test than communicate what was expected. Maybe something like "expected Sign to return a new instance when called without new keyword"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for review.
I got it. I'll revise error message.

}

{
const Verify = crypto.Verify;
const instance = Verify('SHA256');
assert.ok(instance instanceof Verify, 'call verify constructor without new');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

}

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