From 98af967ef6f9c95d82a7688da672ce0d62f69a51 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Mon, 22 Jul 2019 22:38:03 +0200 Subject: [PATCH] test: test jwt sign options over existing payload --- test/jwt/sign.test.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/test/jwt/sign.test.js b/test/jwt/sign.test.js index 5f337c7847..5128354ea5 100644 --- a/test/jwt/sign.test.js +++ b/test/jwt/sign.test.js @@ -92,34 +92,38 @@ test('options.kid', t => { test('options.subject', t => { const subject = 'foo' - const { sub } = JWT.decode(JWT.sign({}, key, { subject })) + const { sub } = JWT.decode(JWT.sign({ sub: 'bar' }, key, { subject })) t.is(sub, subject) }) test('options.issuer', t => { const issuer = 'foo' - const { iss } = JWT.decode(JWT.sign({}, key, { issuer })) + const { iss } = JWT.decode(JWT.sign({ iss: 'bar' }, key, { issuer })) t.is(iss, issuer) }) test('options.jti', t => { const jti = 'foo' - const decoded = JWT.decode(JWT.sign({}, key, { jti })) + const decoded = JWT.decode(JWT.sign({ jti: 'bar' }, key, { jti })) t.is(decoded.jti, jti) }) +const epoch = 1265328501 +const now = new Date(epoch * 1000) + test('options.iat false', t => { const iat = false t.deepEqual(JWT.decode(JWT.sign({}, key, { iat })), {}) }) test('options.iat', t => { - t.true(Object.keys(JWT.decode(JWT.sign({}, key))).includes('iat')) + const decoded = JWT.decode(JWT.sign({ iat: 'bar' }, key, { iat: true, now })) + t.is(decoded.iat, epoch) }) test('options.nonce', t => { const nonce = 'foo' - const { nonce: pNonce } = JWT.decode(JWT.sign({}, key, { nonce })) + const { nonce: pNonce } = JWT.decode(JWT.sign({ nonce: 'bar' }, key, { nonce })) t.is(pNonce, nonce) }) @@ -131,25 +135,22 @@ test('options.audience', t => { test('options.audience (array)', t => { const audience = ['foo'] - const { aud } = JWT.decode(JWT.sign({}, key, { audience })) + const { aud } = JWT.decode(JWT.sign({ aud: 'bar' }, key, { audience })) t.deepEqual(aud, audience) }) -const epoch = 1265328501 -const now = new Date(epoch * 1000) - test('options.now', t => { const { iat } = JWT.decode(JWT.sign({}, key, { now })) t.deepEqual(iat, epoch) }) test('options.expiresIn', t => { - const { exp } = JWT.decode(JWT.sign({}, key, { now, expiresIn: '20s' })) + const { exp } = JWT.decode(JWT.sign({ exp: 'bar' }, key, { now, expiresIn: '20s' })) t.deepEqual(exp, epoch + 20) }) test('options.notBefore', t => { - const { nbf } = JWT.decode(JWT.sign({}, key, { now, notBefore: '20m' })) + const { nbf } = JWT.decode(JWT.sign({ nbf: 'bar' }, key, { now, notBefore: '20m' })) t.deepEqual(nbf, epoch + 20 * 60) })