Files
co-lite/solvway-admin-portal/app/lib/server/directFetchTraversal.test.ts
T
ngqileandClaude Opus 5.5 5ee51d1913 chore: copy kept Tastefully modules and portals into Co-Lite
Backend modules from tastefully 8bd93d15: core-libs, core-session,
api-gateway, mobile-api, services-auth, services-system,
services-counter, services-member, services-log, services-email.
solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal
from tastefully 8bd93d15. Copied as tracked files only.

Literal secrets replaced with environment placeholders:
- services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY,
  MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default)
- services-system: JUMIO_TOKEN, JUMIO_SECRET (optional)
- services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed
- core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default
  removed, ipgeolocation key read from IPGEOLOCATION_API_KEY
- services-system EkycAppConfig: commented Jumio credentials removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-11-26 15:55:45 +08:00

42 lines
2.0 KiB
TypeScript

import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
const mocks = vi.hoisted(() => ({ getToken: vi.fn() }));
vi.mock("@/app/lib/server/session", () => ({ getToken: mocks.getToken }));
import { GET as refundPhoto } from "@/app/api/refunds/[uuid]/photos/[index]/route";
import { GET as warrantyPhoto } from "@/app/api/warranty-claims/[uuid]/photos/[index]/route";
import { GET as reviewImage } from "@/app/api/product-reviews/[refno]/images/[index]/route";
import { GET as webOrderInvoice } from "@/app/api/web-orders/[uuid]/invoice/route";
import { NextRequest } from "next/server";
// portal-path-segment-encoding: these routes fetch mobile-api directly (bytes out), so they do not get
// callMobileApi's dot-segment guard for free. encodeURIComponent("..") is still "..", which the URL parser
// would climb, so a dot-segment id must be refused before any upstream call.
const req = new Request("http://localhost") as never;
const ROUTES = [
["refunds photo", (id: string) => refundPhoto(req, { params: Promise.resolve({ uuid: id, index: "0" }) })],
["warranty photo", (id: string) => warrantyPhoto(req, { params: Promise.resolve({ uuid: id, index: "0" }) })],
["review image", (id: string) => reviewImage(req, { params: Promise.resolve({ refno: id, index: "0" }) })],
[
"web-order invoice",
(id: string) => webOrderInvoice(new NextRequest("http://localhost/api/web-orders/x/invoice"), { params: Promise.resolve({ uuid: id }) }),
],
] as const;
const fetchMock = vi.fn();
beforeEach(() => {
mocks.getToken.mockReset().mockResolvedValue("jwt");
fetchMock.mockReset();
vi.stubGlobal("fetch", fetchMock);
process.env.MOBILE_API_BASE_URL = "http://mobile";
process.env.MOBILE_API_KEY = "k";
});
afterEach(() => vi.unstubAllGlobals());
describe.each(ROUTES)("%s refuses a dot-segment id", (_name, call) => {
it.each([".", "..", "..;x"])("refuses %s without calling upstream", async id => {
expect((await call(id)).status).toBe(400);
expect(fetchMock).not.toHaveBeenCalled();
});
});