CI (SIAX Cloud) / integration (push) Has been skipped
masterplan-lock / check (push) Successful in 4s
CI (SIAX Cloud) / security (push) Successful in 14s
masterplan-lock / check (pull_request) Successful in 4s
CI (SIAX Cloud) / security (pull_request) Successful in 14s
Security Scan (SIAX Cloud) / security (push) Successful in 30s
CI (SIAX Cloud) / quality (push) Successful in 35s
CI (SIAX Cloud) / integration (pull_request) Successful in 25s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 54s
CI (SIAX Cloud) / quality (pull_request) Successful in 1m31s
30 lines
1.3 KiB
TypeScript
30 lines
1.3 KiB
TypeScript
import { beforeEach, expect, it, vi } from "vitest";
|
|
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
const mocks = vi.hoisted(() => ({ routeAuth: vi.fn() }));
|
|
vi.mock("@/src/auth/require-route-auth", () => ({ requireRouteAuth: mocks.routeAuth }));
|
|
|
|
import { requireOrderOwner } from "@/src/auth/require-order-owner";
|
|
|
|
beforeEach(() => mocks.routeAuth.mockReset());
|
|
|
|
const request = () => new NextRequest("https://0pt.app/api/orders", { method: "POST" });
|
|
|
|
it("passes through a failed Zitadel route-auth decision", async () => {
|
|
mocks.routeAuth.mockResolvedValue({ response: NextResponse.json({ error: "unauthenticated" }, { status: 401 }) });
|
|
expect((await requireOrderOwner(request())).response?.status).toBe(401);
|
|
});
|
|
|
|
it("rejects the local-dev auth bypass when no verified principal exists", async () => {
|
|
mocks.routeAuth.mockResolvedValue({ ctx: { tenantId: "spoofable-header" } });
|
|
expect((await requireOrderOwner(request())).response?.status).toBe(401);
|
|
});
|
|
|
|
it("uses only the verified JWT principal, not a request-supplied tenant", async () => {
|
|
mocks.routeAuth.mockResolvedValue({
|
|
ctx: { tenantId: "header-tenant", principal: { tenantId: "signed-tenant", sub: "signed-subject" } },
|
|
});
|
|
const result = await requireOrderOwner(request());
|
|
expect(result.owner).toEqual({ tenantId: "signed-tenant", subject: "signed-subject" });
|
|
});
|