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