33 lines
1.5 KiB
TypeScript
33 lines
1.5 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
vi.mock("~/services/auth/session-handoff.server", () => ({ consumeSessionHandoff: vi.fn() }));
|
|
|
|
import { consumeSessionHandoff } from "~/services/auth/session-handoff.server";
|
|
import { loader } from "./auth.session-handoff";
|
|
|
|
describe("session handoff route", () => {
|
|
it("returns the completed host-only session response", async () => {
|
|
const completed = new Response(null, { status: 302, headers: { Location: "/acme/dashboard" } });
|
|
vi.mocked(consumeSessionHandoff).mockResolvedValueOnce(completed);
|
|
const request = new Request("https://app.example.test/auth/session-handoff?code=opaque-code");
|
|
|
|
await expect(loader({ request, params: {}, context: {} } as never)).resolves.toBe(completed);
|
|
expect(consumeSessionHandoff).toHaveBeenCalledWith(request, "opaque-code");
|
|
});
|
|
|
|
it("redirects invalid or replayed codes without reflecting them", async () => {
|
|
vi.mocked(consumeSessionHandoff).mockResolvedValueOnce(null);
|
|
const response = await loader({
|
|
request: new Request("https://app.example.test/auth/session-handoff?code=secret-replayed-code"),
|
|
params: {},
|
|
context: {},
|
|
} as never);
|
|
|
|
expect(response.status).toBe(302);
|
|
expect(response.headers.get("Location")).toBe("/login?error=session_handoff_invalid");
|
|
expect(response.headers.get("Location")).not.toContain("secret-replayed-code");
|
|
expect(response.headers.get("Cache-Control")).toBe("no-store");
|
|
expect(response.headers.get("Referrer-Policy")).toBe("no-referrer");
|
|
});
|
|
});
|