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
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.ok(instance instanceof Sign, 'Sign is expected to return a new \
instance when called without `new` keyword');
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, two more things:

  1. assert instead of assert.ok
  2. We usually try to break strings using + and line them up beneath each other, so something like this:
assert(instance instanceof Sign, 'Sign is expected to return a new instance ' +
                                 'when called without `new` keyword');

Same below. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't mind.

assert instead of assert.ok

What difference between assert.ok and assert ?
I think assert() is better because there are fewer characters, right ?

Copy link
Member

@apapirovski apapirovski Dec 2, 2017

Choose a reason for hiding this comment

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

assert.ok is just an alias for assert (or, well, the other way around...). Not better but I think in general we try to use assert.

The practical difference in this case is it lets us fit that first line instead of having to split everything significantly more awkwardly. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your detailed information.
I understood that assert was better.

}

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

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