Skip to content

Commit

Permalink
Fix tests in jwt.rs.tests.js which causes 4 to fail
Browse files Browse the repository at this point in the history
  • Loading branch information
BigAB authored and jfromaniello committed Feb 16, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent bd82ab3 commit 8aedf2b
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions test/jwt.rs.tests.js
Original file line number Diff line number Diff line change
@@ -259,98 +259,107 @@ describe('RS256', function() {
describe('when signing a token with issuer', function() {
var token = jwt.sign({ foo: 'bar' }, priv, { algorithm: 'RS256', issuer: 'urn:foo' });

it('should check issuer', function() {
it('should check issuer', function(done) {
jwt.verify(token, pub, { issuer: 'urn:foo' }, function(err, decoded) {
assert.isNotNull(decoded);
assert.isNull(err);
done();
});
});

it('should throw when invalid issuer', function() {
it('should throw when invalid issuer', function(done) {
jwt.verify(token, pub, { issuer: 'urn:wrong' }, function(err, decoded) {
assert.isUndefined(decoded);
assert.isNotNull(err);
assert.equal(err.name, 'JsonWebTokenError');
assert.instanceOf(err, jwt.JsonWebTokenError);
done();
});
});
});

describe('when signing a token without issuer', function() {
var token = jwt.sign({ foo: 'bar' }, priv, { algorithm: 'RS256' });

it('should check issuer', function() {
it('should check issuer', function(done) {
jwt.verify(token, pub, { issuer: 'urn:foo' }, function(err, decoded) {
assert.isUndefined(decoded);
assert.isNotNull(err);
assert.equal(err.name, 'JsonWebTokenError');
assert.instanceOf(err, jwt.JsonWebTokenError);
done();
});
});
});

describe('when signing a token with subject', function() {
var token = jwt.sign({ foo: 'bar' }, priv, { algorithm: 'RS256', subject: 'subject' });

it('should check subject', function() {
it('should check subject', function(done) {
jwt.verify(token, pub, { subject: 'subject' }, function(err, decoded) {
assert.isNotNull(decoded);
assert.isNull(err);
done();
});
});

it('should throw when invalid subject', function() {
jwt.verify(token, pub, { issuer: 'wrongSubject' }, function(err, decoded) {
it('should throw when invalid subject', function(done) {
jwt.verify(token, pub, { subject: 'wrongSubject' }, function(err, decoded) {
assert.isUndefined(decoded);
assert.isNotNull(err);
assert.equal(err.name, 'JsonWebTokenError');
assert.instanceOf(err, jwt.JsonWebTokenError);
done();
});
});
});

describe('when signing a token without subject', function() {
var token = jwt.sign({ foo: 'bar' }, priv, { algorithm: 'RS256' });

it('should check subject', function() {
it('should check subject', function(done) {
jwt.verify(token, pub, { subject: 'subject' }, function(err, decoded) {
assert.isUndefined(decoded);
assert.isNotNull(err);
assert.equal(err.name, 'JsonWebTokenError');
assert.instanceOf(err, jwt.JsonWebTokenError);
done();
});
});
});

describe('when signing a token with jwt id', function() {
var token = jwt.sign({ foo: 'bar' }, priv, { algorithm: 'RS256', jwtid: 'jwtid' });

it('should check jwt id', function() {
it('should check jwt id', function(done) {
jwt.verify(token, pub, { jwtid: 'jwtid' }, function(err, decoded) {
assert.isNotNull(decoded);
assert.isNull(err);
done();
});
});

it('should throw when invalid jwt id', function() {
it('should throw when invalid jwt id', function(done) {
jwt.verify(token, pub, { jwtid: 'wrongJwtid' }, function(err, decoded) {
assert.isUndefined(decoded);
assert.isNotNull(err);
assert.equal(err.name, 'JsonWebTokenError');
assert.instanceOf(err, jwt.JsonWebTokenError);
done();
});
});
});

describe('when signing a token without jwt id', function() {
var token = jwt.sign({ foo: 'bar' }, priv, { algorithm: 'RS256' });

it('should check jwt id', function() {
it('should check jwt id', function(done) {
jwt.verify(token, pub, { jwtid: 'jwtid' }, function(err, decoded) {
assert.isUndefined(decoded);
assert.isNotNull(err);
assert.equal(err.name, 'JsonWebTokenError');
assert.instanceOf(err, jwt.JsonWebTokenError);
done();
});
});
});

0 comments on commit 8aedf2b

Please sign in to comment.