Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KuSh authored and Nicolas Le Cam committed Oct 5, 2021
1 parent cc13ce3 commit 4fda24e
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 111 deletions.
14 changes: 2 additions & 12 deletions test/claim-aud.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ describe('audience', function() {
Infinity,
NaN,
{},
{foo: 'bar'},
{foo: 'bar'}
].forEach((audience) => {
it(`should error with with value ${util.inspect(audience)}`, function (done) {
it(`should error with value ${util.inspect(audience)}`, function (done) {
signWithAudience(audience, {}, (err) => {
testUtils.asyncCheck(done, () => {
expect(err).to.be.instanceOf(Error);
Expand All @@ -45,16 +45,6 @@ describe('audience', function() {
});
});

// undefined needs special treatment because {} is not the same as {aud: undefined}
it('should error with with value undefined', function (done) {
testUtils.signJWTHelper({}, 'secret', {audience: undefined, algorithm: 'none'}, (err) => {
testUtils.asyncCheck(done, () => {
expect(err).to.be.instanceOf(Error);
expect(err).to.have.property('message', '"audience" must be a string or array');
});
});
});

it('should error when "aud" is in payload', function (done) {
signWithAudience('my_aud', {aud: ''}, (err) => {
testUtils.asyncCheck(done, () => {
Expand Down
26 changes: 6 additions & 20 deletions test/claim-exp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ describe('expires', function() {
[],
['foo'],
{},
{foo: 'bar'},
{foo: 'bar'}
].forEach((expiresIn) => {
it(`should error with with value ${util.inspect(expiresIn)}`, function (done) {
it(`should error with value ${util.inspect(expiresIn)}`, function (done) {
signWithExpiresIn(expiresIn, {}, (err) => {
testUtils.asyncCheck(done, () => {
expect(err).to.be.instanceOf(Error);
Expand All @@ -47,19 +47,6 @@ describe('expires', function() {
});
});

// undefined needs special treatment because {} is not the same as {expiresIn: undefined}
it('should error with with value undefined', function (done) {
testUtils.signJWTHelper({}, undefined, {expiresIn: undefined, algorithm: 'none'}, (err) => {
testUtils.asyncCheck(done, () => {
expect(err).to.be.instanceOf(Error);
expect(err).to.have.property(
'message',
'"expiresIn" should be a number of seconds or string representing a timespan'
);
});
});
});

it ('should error when "exp" is in payload', function(done) {
signWithExpiresIn(100, {exp: 100}, (err) => {
testUtils.asyncCheck(done, () => {
Expand Down Expand Up @@ -96,16 +83,15 @@ describe('expires', function() {
true,
false,
null,
undefined,
'',
' ',
'invalid',
[],
['foo'],
{},
{foo: 'bar'},
{foo: 'bar'}
].forEach((exp) => {
it(`should error with with value ${util.inspect(exp)}`, function (done) {
it(`should error with value ${util.inspect(exp)}`, function (done) {
signWithExpiresIn(undefined, {exp}, (err) => {
testUtils.asyncCheck(done, () => {
expect(err).to.be.instanceOf(Error);
Expand All @@ -130,9 +116,9 @@ describe('expires', function() {
[],
['foo'],
{},
{foo: 'bar'},
{foo: 'bar'}
].forEach((exp) => {
it(`should error with with value ${util.inspect(exp)}`, function (done) {
it(`should error with value ${util.inspect(exp)}`, function (done) {
const encodedPayload = base64UrlEncode(JSON.stringify({exp}));
const token = `${noneAlgorithmHeader}.${encodedPayload}.`;
testUtils.verifyJWTHelper(token, undefined, {exp}, (err) => {
Expand Down
12 changes: 1 addition & 11 deletions test/claim-iat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('issue at', function() {
[],
['foo'],
{},
{foo: 'bar'},
{foo: 'bar'}
].forEach((iat) => {
it(`should error with iat of ${util.inspect(iat)}`, function (done) {
signWithIssueAt(iat, {}, (err) => {
Expand All @@ -47,16 +47,6 @@ describe('issue at', function() {
});
});
});

// undefined needs special treatment because {} is not the same as {iat: undefined}
it('should error with iat of undefined', function (done) {
testUtils.signJWTHelper({iat: undefined}, 'secret', {algorithm: 'none'}, (err) => {
testUtils.asyncCheck(done, () => {
expect(err).to.be.instanceOf(Error);
expect(err.message).to.equal('"iat" should be a number of seconds');
});
});
});
});

describe('"iat" in payload with "maxAge" option validation', function () {
Expand Down
14 changes: 2 additions & 12 deletions test/claim-iss.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ describe('issuer', function() {
[],
['foo'],
{},
{foo: 'bar'},
{foo: 'bar'}
].forEach((issuer) => {
it(`should error with with value ${util.inspect(issuer)}`, function (done) {
it(`should error with value ${util.inspect(issuer)}`, function (done) {
signWithIssuer(issuer, {}, (err) => {
testUtils.asyncCheck(done, () => {
expect(err).to.be.instanceOf(Error);
Expand All @@ -42,16 +42,6 @@ describe('issuer', function() {
});
});

// undefined needs special treatment because {} is not the same as {issuer: undefined}
it('should error with with value undefined', function (done) {
testUtils.signJWTHelper({}, undefined, {issuer: undefined, algorithm: 'none'}, (err) => {
testUtils.asyncCheck(done, () => {
expect(err).to.be.instanceOf(Error);
expect(err).to.have.property('message', '"issuer" must be a string');
});
});
});

it('should error when "iss" is in payload', function (done) {
signWithIssuer('foo', {iss: 'bar'}, (err) => {
testUtils.asyncCheck(done, () => {
Expand Down
14 changes: 2 additions & 12 deletions test/claim-jti.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ describe('jwtid', function() {
[],
['foo'],
{},
{foo: 'bar'},
{foo: 'bar'}
].forEach((jwtid) => {
it(`should error with with value ${util.inspect(jwtid)}`, function (done) {
it(`should error with value ${util.inspect(jwtid)}`, function (done) {
signWithJWTId(jwtid, {}, (err) => {
testUtils.asyncCheck(done, () => {
expect(err).to.be.instanceOf(Error);
Expand All @@ -42,16 +42,6 @@ describe('jwtid', function() {
});
});

// undefined needs special treatment because {} is not the same as {jwtid: undefined}
it('should error with with value undefined', function (done) {
testUtils.signJWTHelper({}, undefined, {jwtid: undefined, algorithm: 'none'}, (err) => {
testUtils.asyncCheck(done, () => {
expect(err).to.be.instanceOf(Error);
expect(err).to.have.property('message', '"jwtid" must be a string');
});
});
});

it('should error when "jti" is in payload', function (done) {
signWithJWTId('foo', {jti: 'bar'}, (err) => {
testUtils.asyncCheck(done, () => {
Expand Down
22 changes: 4 additions & 18 deletions test/claim-nbf.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ describe('not before', function() {
[],
['foo'],
{},
{foo: 'bar'},
{foo: 'bar'}
].forEach((notBefore) => {
it(`should error with with value ${util.inspect(notBefore)}`, function (done) {
it(`should error with value ${util.inspect(notBefore)}`, function (done) {
signWithNotBefore(notBefore, {}, (err) => {
testUtils.asyncCheck(done, () => {
expect(err).to.be.instanceOf(Error);
Expand All @@ -47,19 +47,6 @@ describe('not before', function() {
});
});

// undefined needs special treatment because {} is not the same as {notBefore: undefined}
it('should error with with value undefined', function (done) {
testUtils.signJWTHelper({}, undefined, {notBefore: undefined, algorithm: 'none'}, (err) => {
testUtils.asyncCheck(done, () => {
expect(err).to.be.instanceOf(Error);
expect(err).to.have.property(
'message',
'"notBefore" should be a number of seconds or string representing a timespan'
);
});
});
});

it('should error when "nbf" is in payload', function (done) {
signWithNotBefore(100, {nbf: 100}, (err) => {
testUtils.asyncCheck(done, () => {
Expand Down Expand Up @@ -96,7 +83,6 @@ describe('not before', function() {
true,
false,
null,
undefined,
'',
' ',
'invalid',
Expand All @@ -105,7 +91,7 @@ describe('not before', function() {
{},
{foo: 'bar'},
].forEach((nbf) => {
it(`should error with with value ${util.inspect(nbf)}`, function (done) {
it(`should error with value ${util.inspect(nbf)}`, function (done) {
signWithNotBefore(undefined, {nbf}, (err) => {
testUtils.asyncCheck(done, () => {
expect(err).to.be.instanceOf(Error);
Expand All @@ -132,7 +118,7 @@ describe('not before', function() {
{},
{foo: 'bar'},
].forEach((nbf) => {
it(`should error with with value ${util.inspect(nbf)}`, function (done) {
it(`should error with value ${util.inspect(nbf)}`, function (done) {
const encodedPayload = base64UrlEncode(JSON.stringify({nbf}));
const token = `${noneAlgorithmHeader}.${encodedPayload}.`;
testUtils.verifyJWTHelper(token, undefined, {nbf}, (err) => {
Expand Down
4 changes: 2 additions & 2 deletions test/claim-private.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('with a private claim', function() {
[],
['foo'],
{},
{foo: 'bar'},
{foo: 'bar'}
].forEach((privateClaim) => {
it(`should sign and verify with claim of ${util.inspect(privateClaim)}`, function (done) {
signWithPayload({privateClaim}, (e1, token) => {
Expand All @@ -43,7 +43,7 @@ describe('with a private claim', function() {
[
-Infinity,
Infinity,
NaN,
NaN
].forEach((privateClaim) => {
it(`should sign and verify with claim of ${util.inspect(privateClaim)}`, function (done) {
signWithPayload({privateClaim}, (e1, token) => {
Expand Down
14 changes: 2 additions & 12 deletions test/claim-sub.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ describe('subject', function() {
[],
['foo'],
{},
{foo: 'bar'},
{foo: 'bar'}
].forEach((subject) => {
it(`should error with with value ${util.inspect(subject)}`, function (done) {
it(`should error with value ${util.inspect(subject)}`, function (done) {
signWithSubject(subject, {}, (err) => {
testUtils.asyncCheck(done, () => {
expect(err).to.be.instanceOf(Error);
Expand All @@ -42,16 +42,6 @@ describe('subject', function() {
});
});

// undefined needs special treatment because {} is not the same as {subject: undefined}
it('should error with with value undefined', function (done) {
testUtils.signJWTHelper({}, undefined, {subject: undefined, algorithm: 'none'}, (err) => {
testUtils.asyncCheck(done, () => {
expect(err).to.be.instanceOf(Error);
expect(err).to.have.property('message', '"subject" must be a string');
});
});
});

it('should error when "sub" is in payload', function (done) {
signWithSubject('foo', {sub: 'bar'}, (err) => {
testUtils.asyncCheck(done, () => {
Expand Down
14 changes: 2 additions & 12 deletions test/header-kid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ describe('keyid', function() {
[],
['foo'],
{},
{foo: 'bar'},
{foo: 'bar'}
].forEach((keyid) => {
it(`should error with with value ${util.inspect(keyid)}`, function (done) {
it(`should error with value ${util.inspect(keyid)}`, function (done) {
signWithKeyId(keyid, {}, (err) => {
testUtils.asyncCheck(done, () => {
expect(err).to.be.instanceOf(Error);
Expand All @@ -41,16 +41,6 @@ describe('keyid', function() {
});
});
});

// undefined needs special treatment because {} is not the same as {keyid: undefined}
it('should error with with value undefined', function (done) {
testUtils.signJWTHelper({}, undefined, {keyid: undefined, algorithm: 'none'}, (err) => {
testUtils.asyncCheck(done, () => {
expect(err).to.be.instanceOf(Error);
expect(err).to.have.property('message', '"keyid" must be a string');
});
});
});
});

describe('when signing a token', function () {
Expand Down

0 comments on commit 4fda24e

Please sign in to comment.