31 lines
1.5 KiB
TypeScript
31 lines
1.5 KiB
TypeScript
import { NextRequest } from "next/server";
|
|
import { afterEach, expect, it, vi } from "vitest";
|
|
|
|
vi.mock("@/shared/config", () => ({ CLAIM_NAME: "custom-auth-cookie", AUTH_USER_ID: "token-id" }));
|
|
vi.mock("next/headers", () => ({
|
|
cookies: async () => ({ get: (name: string) =>
|
|
name === "custom-auth-cookie" ? { value: "login.jwt.signature" } : undefined }),
|
|
}));
|
|
vi.mock("@/server/category-scope-attestation", async importOriginal => ({
|
|
...await importOriginal<typeof import("@/server/category-scope-attestation")>(),
|
|
prepareCategoryScope: vi.fn(async () => ({ required: false, questionSha256: "hash", family: null })),
|
|
}));
|
|
|
|
import { POST } from "./route";
|
|
|
|
afterEach(() => { vi.unstubAllGlobals(); });
|
|
|
|
it("uses the same cookie principal for the gateway claim and DC Authorization headers", async () => {
|
|
const fetchMock = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {
|
|
expect(new Headers(init?.headers).get("Authorization")).toBe("login.jwt.signature");
|
|
expect(new Headers(init?.headers).get("custom-auth-cookie")).toBe("login.jwt.signature");
|
|
return new Response("data: done\n\n", { headers: { "Content-Type": "text/event-stream" } });
|
|
});
|
|
vi.stubGlobal("fetch", fetchMock);
|
|
const response = await POST(new NextRequest("https://dc.invalid/api/flask-service/ask-question", {
|
|
method: "POST", body: JSON.stringify({ question: "자료관 질문" }),
|
|
}));
|
|
expect(response.status).toBe(200);
|
|
expect(fetchMock).toHaveBeenCalledOnce();
|
|
});
|