You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
653 B

  1. var jwt = require('../index');
  2. var expect = require('chai').expect;
  3. describe('iat', function () {
  4. it('should work with a exp calculated based on numeric iat', function () {
  5. var dateNow = Math.floor(Date.now() / 1000);
  6. var iat = dateNow - 30;
  7. var expiresIn = 50;
  8. var token = jwt.sign({foo: 123, iat: iat}, '123', {expiresIn: expiresIn});
  9. var result = jwt.verify(token, '123');
  10. expect(result.exp).to.be.closeTo(iat + expiresIn, 0.2);
  11. });
  12. it('should throw if iat is not a number', function () {
  13. expect(function () {
  14. jwt.sign({foo: 123, iat: 'hello'}, '123');
  15. }).to.throw(/"iat" must be a number/);
  16. });
  17. });