use the same timestamp in sync and async

This commit is contained in:
Jacopo
2016-03-25 22:35:53 +01:00
parent 08a5ff5836
commit ac7e6a6a4a
+4 -2
View File
@@ -6,10 +6,12 @@ describe('signing a token asynchronously', function() {
describe('when signing a token', function() {
var secret = 'shhhhhh';
var syncToken = jwt.sign({ foo: 'bar' }, secret, { algorithm: 'HS256' });
//use the same timestamp, or it may differ in the two tokens
var currentTimestamp = Math.floor(new Date()/1000);
var syncToken = jwt.sign({ foo: 'bar', iat: currentTimestamp }, secret, { algorithm: 'HS256' });
it('should return the same result as singing synchronously', function(done) {
jwt.sign({ foo: 'bar' }, secret, { algorithm: 'HS256' }, function (asyncToken) {
jwt.sign({ foo: 'bar', iat: currentTimestamp }, secret, { algorithm: 'HS256' }, function (asyncToken) {
expect(asyncToken).to.be.a('string');
expect(asyncToken.split('.')).to.have.length(3);
expect(asyncToken).to.equal(syncToken);