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
Closed

Enhance crypto/sig.js coverage #17426

wants to merge 9 commits into from

Conversation

Leko
Copy link
Contributor

@Leko Leko commented Dec 2, 2017

I added these case:

  1. Call Sign without new
  2. Call Verify without new
  3. Call Verify#verify with options.padding !== options.padding >> 0
  4. Call Verify#verify with options.saltLength !== options.saltLength >> 0

Current coverage: https://coverage.nodejs.org/coverage-06e1b0386196f8f8/root/internal/crypto/sig.js.html

After this PR: crypto/sig.js become 100% covered even in branch coverage.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

test

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Dec 2, 2017
{
const Verify = crypto.Verify;
const instance = Verify('SHA256');
assert.ok(instance instanceof Verify, 'call sign constructor without new');
Copy link
Contributor

Choose a reason for hiding this comment

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

sign -> verify

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I made a mistake.
Thank you for your review.

@mscdex mscdex added the crypto Issues and PRs related to the crypto subsystem. label Dec 2, 2017
Copy link
Member

@apapirovski apapirovski left a comment

Choose a reason for hiding this comment

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

LGTM but the assert message should be adjusted, IMHO.

{
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.

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.

@apapirovski
Copy link
Member

@apapirovski
Copy link
Member

Landed in 0ab98f1

@apapirovski apapirovski closed this Dec 8, 2017
apapirovski pushed a commit that referenced this pull request Dec 8, 2017
- 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>
@Leko Leko deleted the enhance_crypto_sig_coverage branch December 8, 2017 13:54
MylesBorins pushed a commit that referenced this pull request Dec 12, 2017
- 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>
MylesBorins pushed a commit that referenced this pull request Dec 12, 2017
- 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>
@MylesBorins MylesBorins mentioned this pull request Dec 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crypto Issues and PRs related to the crypto subsystem. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants