Skip to content

Commit

Permalink
Implement async/sync tests for exp claim (#536)
Browse files Browse the repository at this point in the history
Refactor existing tests for the exp claim to use the async/sync test
helpers. This required fixing a case where an error was improperly
handled in the async case.
  • Loading branch information
MitMaro authored and ziluvatar committed Oct 16, 2018
1 parent 342b07b commit 9ae3f20
Show file tree
Hide file tree
Showing 2 changed files with 224 additions and 143 deletions.
7 changes: 6 additions & 1 deletion sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ module.exports = function (payload, secretOrPrivateKey, options, callback) {
}

if (typeof options.expiresIn !== 'undefined' && typeof payload === 'object') {
payload.exp = timespan(options.expiresIn, timestamp);
try {
payload.exp = timespan(options.expiresIn, timestamp);
}
catch (err) {
return failure(err);
}
if (typeof payload.exp === 'undefined') {
return failure(new Error('"expiresIn" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60'));
}
Expand Down
Loading

0 comments on commit 9ae3f20

Please sign in to comment.