From b669de501d285c064a7a765358e93135f67f4476 Mon Sep 17 00:00:00 2001 From: Nicolas Le Cam Date: Sun, 12 Feb 2023 13:38:23 +0100 Subject: [PATCH] Fix tests --- test/claim-aud.test.js | 12 +----------- test/claim-exp.test.js | 20 +++----------------- test/claim-iat.test.js | 10 ---------- test/claim-iss.test.js | 12 +----------- test/claim-jti.test.js | 12 +----------- test/claim-nbf.test.js | 20 +++----------------- test/claim-sub.tests.js | 12 +----------- test/header-kid.test.js | 12 +----------- 8 files changed, 11 insertions(+), 99 deletions(-) diff --git a/test/claim-aud.test.js b/test/claim-aud.test.js index 3a27fd8..50e098c 100644 --- a/test/claim-aud.test.js +++ b/test/claim-aud.test.js @@ -35,7 +35,7 @@ describe('audience', function() { {}, {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); @@ -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: 'HS256'}, (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, () => { diff --git a/test/claim-exp.test.js b/test/claim-exp.test.js index fbdbc52..924f567 100644 --- a/test/claim-exp.test.js +++ b/test/claim-exp.test.js @@ -34,7 +34,7 @@ describe('expires', function() { {}, {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); @@ -45,19 +45,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({}, 'secret', {expiresIn: undefined, algorithm: 'HS256'}, (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, () => { @@ -94,7 +81,6 @@ describe('expires', function() { true, false, null, - undefined, '', ' ', 'invalid', @@ -103,7 +89,7 @@ describe('expires', function() { {}, {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); @@ -130,7 +116,7 @@ describe('expires', function() { {}, {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 header = { alg: 'HS256' }; const payload = { exp }; const token = jws.sign({ header, payload, secret: 'secret', encoding: 'utf8' }); diff --git a/test/claim-iat.test.js b/test/claim-iat.test.js index a3dd474..79eefa9 100644 --- a/test/claim-iat.test.js +++ b/test/claim-iat.test.js @@ -45,16 +45,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: 'HS256'}, (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 () { diff --git a/test/claim-iss.test.js b/test/claim-iss.test.js index 1b1b72f..f6e4471 100644 --- a/test/claim-iss.test.js +++ b/test/claim-iss.test.js @@ -32,7 +32,7 @@ describe('issuer', function() { {}, {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); @@ -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({}, 'secret', {issuer: undefined, algorithm: 'HS256'}, (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, () => { diff --git a/test/claim-jti.test.js b/test/claim-jti.test.js index 9721f7c..bb92170 100644 --- a/test/claim-jti.test.js +++ b/test/claim-jti.test.js @@ -32,7 +32,7 @@ describe('jwtid', function() { {}, {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); @@ -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({}, 'secret', {jwtid: undefined, algorithm: 'HS256'}, (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, () => { diff --git a/test/claim-nbf.test.js b/test/claim-nbf.test.js index 72397de..a26b900 100644 --- a/test/claim-nbf.test.js +++ b/test/claim-nbf.test.js @@ -34,7 +34,7 @@ describe('not before', function() { {}, {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); @@ -45,19 +45,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({}, 'secret', {notBefore: undefined, algorithm: 'HS256'}, (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, () => { @@ -94,7 +81,6 @@ describe('not before', function() { true, false, null, - undefined, '', ' ', 'invalid', @@ -103,7 +89,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); @@ -130,7 +116,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 header = { alg: 'HS256' }; const payload = { nbf }; const token = jws.sign({ header, payload, secret: 'secret', encoding: 'utf8' }); diff --git a/test/claim-sub.tests.js b/test/claim-sub.tests.js index a65b39e..75d6e2b 100644 --- a/test/claim-sub.tests.js +++ b/test/claim-sub.tests.js @@ -32,7 +32,7 @@ describe('subject', function() { {}, {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); @@ -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({}, 'secret', {subject: undefined, algorithm: 'HS256'}, (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, () => { diff --git a/test/header-kid.test.js b/test/header-kid.test.js index e419067..deb509c 100644 --- a/test/header-kid.test.js +++ b/test/header-kid.test.js @@ -32,7 +32,7 @@ describe('keyid', function() { {}, {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); @@ -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({}, 'secret', {keyid: undefined, algorithm: 'HS256'}, (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 () {