Files
frontend/test/data/auth.test.ts
Allen Porter fd19a0e4e3 Forward PKCE code_challenge parameters in login flow (#54389)
* Forward PKCE code_challenge parameters in login flow

* Move auth data test to test/data/auth.test.ts
2026-09-27 17:59:30 -04:00

54 lines
1.5 KiB
TypeScript

import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { createLoginFlow } from "../../src/data/auth";
describe("createLoginFlow", () => {
beforeEach(() => {
vi.stubGlobal("fetch", vi.fn());
});
afterEach(() => {
vi.unstubAllGlobals();
vi.resetAllMocks();
});
it("posts basic login flow without PKCE parameters", async () => {
await createLoginFlow(
"https://myclient.com",
"https://myclient.com/callback",
["homeassistant", null]
);
expect(fetch).toHaveBeenCalledWith("/auth/login_flow", {
method: "POST",
credentials: "same-origin",
body: JSON.stringify({
client_id: "https://myclient.com",
handler: ["homeassistant", null],
redirect_uri: "https://myclient.com/callback",
}),
});
});
it("posts login flow with code_challenge and code_challenge_method", async () => {
await createLoginFlow(
"https://myclient.com",
"https://myclient.com/callback",
["homeassistant", null],
"E9Melhoa2OwvFrGMTJguCHaoeK1t8URWbuGJSstw-cM",
"S256"
);
expect(fetch).toHaveBeenCalledWith("/auth/login_flow", {
method: "POST",
credentials: "same-origin",
body: JSON.stringify({
client_id: "https://myclient.com",
handler: ["homeassistant", null],
redirect_uri: "https://myclient.com/callback",
code_challenge: "E9Melhoa2OwvFrGMTJguCHaoeK1t8URWbuGJSstw-cM",
code_challenge_method: "S256",
}),
});
});
});