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

Refactor tests related to notBefore and nbf (#492) #497

Merged
merged 1 commit into from
Jun 27, 2018

Conversation

MitMaro
Copy link
Contributor

@MitMaro MitMaro commented Jun 24, 2018

First PR for #492.

This change extracts all tests in the current files related to notBefore and nbf into a single test file. It also adds several missing related tests.

I believe I removed all references to nbf and notBefore from the current tests.

There are two TODOs in the tests, because I found a few unhandled cases that I expected would cause an error but did not. They are:

  • Passing an empty string to notBefore. I'm not sure if this should default to 0 or should throw an error. Currently it throws a val is not a non-empty string or a valid number. val="" from ms.
  • Passing -Infinity, Infinity and NaN to nbf. These all JSON.stringify to null, so I would assume should be considered invalid.

Any suggestions of missing tests are more than welcome, and I will gladly add!

Copy link
Contributor

@ziluvatar ziluvatar left a comment

Choose a reason for hiding this comment

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

👏 😍

package.json Outdated
@@ -4,7 +4,8 @@
"description": "JSON Web Token implementation (symmetric and asymmetric)",
"main": "index.js",
"scripts": {
"test": "nyc --reporter=html --reporter=text mocha && nsp check && cost-of-modules"
"test:unit": "nyc --reporter=html --reporter=text mocha",
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 they are not unit tests. I guess you wanted a fast way to develop the tests getting coverage feedback without the delay of nsp + cost-of-modules, right? since this is test + coverage, let's name it: coverage or test:coverage or similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing! cost-of-modules temporarily renames the node_modules/ directory, and it was causing my editor to continually re-index. This was a way to run the tests without those checks.

I'm okay with a coverage task.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in MitMaro@f564d20 before I squashed commits.

test/nbf.test.js Outdated
Infinity,
NaN,
// TODO empty string currently fails
// '',
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's create a test with the current behavior and a PR to fix this, since it should be invalid too (with same error message), and we can merge the fix on next major release.

Copy link
Contributor Author

@MitMaro MitMaro Jun 26, 2018

Choose a reason for hiding this comment

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

Just to make sure I understand correctly before I update:

  • add a test for an empty string that checks for the ms error
  • add another PR that fixes the behaviour

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in MitMaro@b037c26 before I squashed commits.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes

test/nbf.test.js Outdated
// TODO should these fail in validation?
// -Infinity,
// Infinity,
// NaN,
Copy link
Contributor

Choose a reason for hiding this comment

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

As you said, yes, I think they should fail, like I said before, let's add the current behavior and a PR (same one as before?) to fix in next major.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in MitMaro@b037c26 before I squashed commits.

@MitMaro MitMaro force-pushed the refactor-nbf-tests branch from 9179675 to b55f2ab Compare June 26, 2018 16:23
This change extracts all tests in the current files related to notBefore
and nbf into a single test file. It also adds several missing related
tests.
@MitMaro MitMaro force-pushed the refactor-nbf-tests branch from b55f2ab to e529ca3 Compare June 26, 2018 16:23
@MitMaro
Copy link
Contributor Author

MitMaro commented Jun 26, 2018

I fixed some of the formatting in MitMaro@943dab9 after fixing the issues noted above.

@ziluvatar ziluvatar merged commit 39adf87 into auth0:master Jun 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants