-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathzitadelConnector.test.ts
More file actions
57 lines (48 loc) · 1.67 KB
/
Copy pathzitadelConnector.test.ts
File metadata and controls
57 lines (48 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import {
ZitadelConnectionError,
introspectAccessToken,
} from "@lib/integration/zitadelConnector.js";
import { logMessage } from "@lib/logging/logger.js";
import got from "got";
import { SignJWT } from "jose";
import { beforeEach, describe, expect, it, vi } from "vitest";
vi.spyOn(SignJWT.prototype, "sign").mockResolvedValue("signedJwtToken");
describe("introspectAccessToken should", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("call Got post function with valid payload format", async () => {
await expect(introspectAccessToken("accessToken")).resolves.not.toThrow();
expect(got.post).toHaveBeenCalledWith("http://test/oauth/v2/introspect", {
http2: true,
timeout: { request: 5000 },
retry: { limit: 1 },
headers: {
Host: "http://test",
},
form: {
client_assertion_type:
"urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
client_assertion: "signedJwtToken",
token: "accessToken",
},
});
});
it("throw an error if Zitadel post request fails", async () => {
const connectionError = new ZitadelConnectionError();
vi.spyOn(got, "post").mockReturnValueOnce({
json: vi.fn().mockRejectedValueOnce(connectionError),
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
} as any);
const logMessageSpy = vi.spyOn(logMessage, "info");
await expect(() => introspectAccessToken("accessToken")).rejects.toThrow(
ZitadelConnectionError,
);
expect(logMessageSpy).toHaveBeenCalledWith(
connectionError,
expect.stringContaining(
"[zitadel-connector] Failed to introspect access token",
),
);
});
});