Skip to main content
Latest
File
import { assertEquals } from 'https://deno.land/std@v0.177.0/testing/asserts.ts'import { nanoid } from 'https://cdn.skypack.dev/nanoid@4.0.1/async?dts'import jwt from './jwt.ts'
Deno.test('jwt module', async t => { const tokenSecret = await nanoid(32) , encryptionSecret = await nanoid(128)
, token = await jwt.sign({ message: 'content' }, tokenSecret) , encryptedToken = await jwt.sign( { message: 'secret message', aud: 'world' }, tokenSecret, { encrypt: encryptionSecret } )
, expiredToken = await jwt.sign({ exp: '-5m' }, tokenSecret)
await t.step('verify token', () => { assertEquals(typeof token, 'string')
assertEquals(typeof encryptedToken, 'string')
assertEquals(typeof expiredToken, 'string') })
await t.step('verify token', async () => { assertEquals(await jwt.verify(token, tokenSecret), { message: 'content' })
assertEquals( await jwt.verify(encryptedToken, tokenSecret, { decrypt: encryptionSecret, audience: 'world' }), { aud: 'world', message: 'secret message' } )
assertEquals(await jwt.verify(expiredToken, tokenSecret), undefined) })})