Skip to content

Commit

Permalink
test: add broken test case
Browse files Browse the repository at this point in the history
  • Loading branch information
salmanm committed Feb 14, 2024
1 parent 4882005 commit f15bc16
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/jwt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3047,3 +3047,37 @@ test('local sign options should not overwrite global sign options', async functi

t.equal(fastify.jwt.options.sign.expiresIn, '15m')
})

test('local sign options.key should take effect', async function (t) {
t.plan(1)

const options = {
secret: 'test'
}

const fastify = Fastify()
fastify.register(jwt, options)

fastify.post('/sign', async function (request, reply) {
const { token, refreshToken } = request.body
const refreshTokenSigned = await reply.jwtSign(refreshToken, { key: 'something-else' }) // signing by different key
const tokenSigned = await reply.jwtSign(token)
return reply.send({ tokenSigned, refreshTokenSigned })
})

await fastify.ready()

const signResponse = await fastify.inject({
method: 'post',
url: '/sign',
payload: { token: { foo: 'bar' }, refreshToken: { bar: 'foo' } }
})

const token = JSON.parse(signResponse.payload).tokenSigned
const refreshToken = JSON.parse(signResponse.payload).refreshTokenSigned

fastify.jwt.verify(token, { key: 'test' })
fastify.jwt.verify(refreshToken, { key: 'something-else' }) // should not throw

t.ok(true)
})

0 comments on commit f15bc16

Please sign in to comment.