clean up tests
This commit is contained in:
@@ -13,27 +13,27 @@ describe("Verify", async () => {
|
|||||||
const notYetValidToken = await jwt.sign({ sub: "me", nbf: now + offset }, secret)
|
const notYetValidToken = await jwt.sign({ sub: "me", nbf: now + offset }, secret)
|
||||||
const expiredToken = await jwt.sign({ sub: "me", exp: now - offset }, secret)
|
const expiredToken = await jwt.sign({ sub: "me", exp: now - offset }, secret)
|
||||||
|
|
||||||
test("Valid", () => {
|
test("Valid", async () => {
|
||||||
expect(jwt.verify(validToken, secret, { throwError: true })).resolves.toBeTruthy()
|
await expect(jwt.verify(validToken, secret, { throwError: true })).resolves.toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
||||||
test("Not yet expired", () => {
|
test("Not yet expired", async () => {
|
||||||
expect(jwt.verify(notYetExpired, secret, { throwError: true })).resolves.toBeTruthy()
|
await expect(jwt.verify(notYetExpired, secret, { throwError: true })).resolves.toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
||||||
test("Not yet valid", () => {
|
test("Not yet valid", async () => {
|
||||||
expect(jwt.verify(notYetValidToken, secret, { throwError: true })).rejects.toThrowError("NOT_YET_VALID")
|
await expect(jwt.verify(notYetValidToken, secret, { throwError: true })).rejects.toThrowError("NOT_YET_VALID")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("Expired", () => {
|
test("Expired", async () => {
|
||||||
expect(jwt.verify(expiredToken, secret, { throwError: true })).rejects.toThrowError("EXPIRED")
|
await expect(jwt.verify(expiredToken, secret, { throwError: true })).rejects.toThrowError("EXPIRED")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("Clock offset", () => {
|
test("Clock offset", async () => {
|
||||||
expect(jwt.verify(notYetValidToken, secret, { clockTolerance: offset, throwError: true })).resolves.toBeTruthy()
|
await expect(jwt.verify(notYetValidToken, secret, { clockTolerance: offset, throwError: true })).resolves.toBeTruthy()
|
||||||
expect(jwt.verify(expiredToken, secret, { clockTolerance: offset, throwError: true })).resolves.toBeTruthy()
|
await expect(jwt.verify(expiredToken, secret, { clockTolerance: offset, throwError: true })).resolves.toBeTruthy()
|
||||||
|
|
||||||
expect(jwt.verify(notYetValidToken, secret, { clockTolerance: offset - 1, throwError: true })).rejects.toThrowError("NOT_YET_VALID")
|
await expect(jwt.verify(notYetValidToken, secret, { clockTolerance: offset - 1, throwError: true })).rejects.toThrowError("NOT_YET_VALID")
|
||||||
expect(jwt.verify(expiredToken, secret, { clockTolerance: offset - 1, throwError: true })).rejects.toThrowError("EXPIRED")
|
await expect(jwt.verify(expiredToken, secret, { clockTolerance: offset - 1, throwError: true })).rejects.toThrowError("EXPIRED")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -67,7 +67,7 @@ describe("Imports", () => {
|
|||||||
const testAlgorithm = { name: "HMAC", hash: { name: "SHA-256" } }
|
const testAlgorithm = { name: "HMAC", hash: { name: "SHA-256" } }
|
||||||
const testCryptoKey = { type: "secret", extractable: true, algorithm: { ...testAlgorithm, length: 168 }, usages: ["verify", "sign"] }
|
const testCryptoKey = { type: "secret", extractable: true, algorithm: { ...testAlgorithm, length: 168 }, usages: ["verify", "sign"] }
|
||||||
|
|
||||||
expect(await importTextSecret(testKey, testAlgorithm, ["verify", "sign"])).toMatchObject(testCryptoKey)
|
await expect(importTextSecret(testKey, testAlgorithm, ["verify", "sign"])).resolves.toMatchObject(testCryptoKey)
|
||||||
})
|
})
|
||||||
|
|
||||||
test.todo("importJwk")
|
test.todo("importJwk")
|
||||||
|
|||||||
Reference in New Issue
Block a user