Merge branch 'popomore-standard-callback'

This commit is contained in:
José F. Romaniello
2016-04-27 11:34:59 -03:00
2 changed files with 13 additions and 2 deletions
+5 -1
View File
@@ -132,7 +132,11 @@ JWT.sign = function(payload, secretOrPrivateKey, options, callback) {
header: header,
privateKey: secretOrPrivateKey,
payload: JSON.stringify(payload)
}).on('done', callback);
})
.on('error', callback)
.on('done', function(signature) {
callback(null, signature);
});
} else {
return jws.sign({header: header, payload: payload, secret: secretOrPrivateKey, encoding: encoding});
}
+8 -1
View File
@@ -9,12 +9,19 @@ describe('signing a token asynchronously', function() {
var syncToken = jwt.sign({ foo: 'bar' }, 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' }, secret, { algorithm: 'HS256' }, function (err, asyncToken) {
expect(asyncToken).to.be.a('string');
expect(asyncToken.split('.')).to.have.length(3);
expect(asyncToken).to.equal(syncToken);
done();
});
});
it('should throw error', function(done) {
jwt.sign({ foo: 'bar' }, secret, { algorithm: 'HS2561' }, function (err) {
expect(err).to.be.ok();
done();
});
});
});
});