fix(confidence-engine): preserve external auth callback origin

This commit is contained in:
2026-09-09 11:26:57 +01:00
parent 0125975ccb
commit bb62a65174
2 changed files with 55 additions and 2 deletions
+39 -1
View File
@@ -19,9 +19,47 @@ vi.mock("@/lib/config", () => ({
}));
vi.mock("@supabase/ssr", () => ({
createServerClient: () => ({ auth: { getUser: () => mockGetUser() } }),
createServerClient: () => ({
auth: {
getUser: () => mockGetUser(),
exchangeCodeForSession: vi.fn().mockResolvedValue(undefined),
},
}),
}));
describe("auth callback redirect origin", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("uses forwarded host/proto for redirect when behind proxy", async () => {
const { GET } = await import("@/app/auth/callback/route.js");
const request = new Request("http://0.0.0.0:3000/auth/callback?code=abc123", {
headers: {
"x-forwarded-host": "confidence.rdbcloud.co.uk",
"x-forwarded-proto": "https",
},
});
const response = await GET(request);
expect(response.status).toBe(307);
expect(response.headers.get("location")).toBe("https://confidence.rdbcloud.co.uk/");
});
it("falls back to request origin when no forwarded headers", async () => {
const { GET } = await import("@/app/auth/callback/route.js");
const request = new Request("http://localhost:3000/auth/callback?code=xyz");
const response = await GET(request);
expect(response.status).toBe(307);
expect(response.headers.get("location")).toBe("http://localhost:3000/");
});
});
describe("authenticated product boundary", () => {
beforeEach(() => {
vi.clearAllMocks();