Skip to content

Commit

Permalink
Add a unit test for parseJwt
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Oliver authored and n4bb12 committed Jun 5, 2024
1 parent 73ab93d commit a815fd6
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/client/plugin/parseJwt.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { describe, expect, it } from "vitest"
import { parseJwt } from "src/client/plugin/lib"

const MOCK_TOKEN =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyZWFsX2dyb3VwcyI6WyJnaXRodWIvb3JnL3Rlc3Qtb3JnIl0sIm5hbWUiOiJKb2huRG9lIiwiZ3JvdXBzIjpbIiRhbGwiLCJAYWxsIiwiJGF1dGhlbnRpY2F0ZWQiLCJAYXV0aGVudGljYXRlZCIsImdpdGh1Yi9vcmcvdGVzdC1vcmciXSwiaWF0IjoxNzE2NTIxNzY0LCJuYmYiOjE3MTY1MjE3NjQsImV4cCI6MTcxOTExMzc2NH0.O9UoSVBvKyM5UAJzoVa_kNvjJR0C06SP57nVXwzxEBY"

describe("parseJwt", () => {
it("should decode a valid JWT token", () => {
const decodedToken = parseJwt(MOCK_TOKEN)

expect(decodedToken).toEqual({
real_groups: ["github/org/test-org"],
name: "JohnDoe",
groups: [
"$all",
"@all",
"$authenticated",
"@authenticated",
"github/org/test-org",
],
iat: 1716521764,
nbf: 1716521764,
exp: 1719113764,
})
})
})

0 comments on commit a815fd6

Please sign in to comment.