From a815fd692c8f1da189fee5054d2b4778abe23eeb Mon Sep 17 00:00:00 2001 From: Michael Oliver Date: Tue, 4 Jun 2024 11:17:19 -0700 Subject: [PATCH] Add a unit test for parseJwt --- test/client/plugin/parseJwt.test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test/client/plugin/parseJwt.test.ts diff --git a/test/client/plugin/parseJwt.test.ts b/test/client/plugin/parseJwt.test.ts new file mode 100644 index 0000000..6b2c9de --- /dev/null +++ b/test/client/plugin/parseJwt.test.ts @@ -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, + }) + }) +})