-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deprecate expireInMinutes and expireInSeconds - in favor of expiresIn
- Loading branch information
1 parent
4b70ae3
commit 39ecc6f
Showing
3 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
var jwt = require('../index'); | ||
var expect = require('chai').expect; | ||
|
||
describe('expires option', function() { | ||
|
||
it('should work with a number of seconds', function () { | ||
var token = jwt.sign({foo: 123}, '123', { expiresIn: 10 }); | ||
var result = jwt.verify(token, '123'); | ||
expect(result.exp).to.be.closeTo(Math.floor(Date.now() / 1000) + 10, 0.2); | ||
}); | ||
|
||
it('should work with a string', function () { | ||
var token = jwt.sign({foo: 123}, '123', { expiresIn: '2d' }); | ||
var result = jwt.verify(token, '123'); | ||
var two_days_in_secs = 2 * 24 * 60 * 60; | ||
expect(result.exp).to.be.closeTo(Math.floor(Date.now() / 1000) + two_days_in_secs, 0.2); | ||
}); | ||
|
||
it('should work with a string second example', function () { | ||
var token = jwt.sign({foo: 123}, '123', { expiresIn: '36h' }); | ||
var result = jwt.verify(token, '123'); | ||
var day_and_a_half_in_secs = 1.5 * 24 * 60 * 60; | ||
expect(result.exp).to.be.closeTo(Math.floor(Date.now() / 1000) + day_and_a_half_in_secs, 0.2); | ||
}); | ||
|
||
|
||
it('should throw if expires has a bad string format', function () { | ||
expect(function () { | ||
jwt.sign({foo: 123}, '123', { expiresIn: '1 monkey' }); | ||
}).to.throw(/bad "expiresIn" format: 1 monkey/); | ||
}); | ||
|
||
it('should throw if expires is not an string or number', function () { | ||
expect(function () { | ||
jwt.sign({foo: 123}, '123', { expiresIn: { crazy : 213 } }); | ||
}).to.throw(/"expiresIn" should be a number of seconds or string representing a timespan/); | ||
}); | ||
|
||
}); |