Files
ngqileandClaude Opus 5.5 1071ddaa2a feat(admin-portal): cut babyboo portal down to Co-Lite login, users and roles
Removes every other screen, API route, component, test and the dependencies only
they used. Cookie colite_admin, Co-Lite branding, BO_USERS/BO_ROLES modules only.
The user form no longer loads branches, events or country scope.

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

71 lines
2.5 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
// host-prefixed-session-cookie (F29): the session cookie is host-only (`__Host-`), so no sibling host can set it.
const h = vi.hoisted(() => {
const store = new Map<string, string>();
const setSpy = vi.fn();
return { store, setSpy };
});
vi.mock("next/headers", () => ({
cookies: async () => ({
get: (n: string) => (h.store.has(n) ? { name: n, value: h.store.get(n)! } : undefined),
set: (name: string, value: string, opts: unknown) => {
h.store.set(name, value);
h.setSpy(name, value, opts);
},
delete: (n: string) => {
h.store.delete(n);
},
}),
}));
import { setSession, readSession, clearSession } from "./session";
import { sealSession } from "@/app/lib/sessionSeal";
import { sessionCookieName } from "@/app/lib/sessionCookieName";
const saved = process.env.SESSION_COOKIE_NAME;
beforeEach(() => {
h.store.clear();
h.setSpy.mockClear();
delete process.env.SESSION_COOKIE_NAME;
});
afterEach(() => {
if (saved === undefined) delete process.env.SESSION_COOKIE_NAME;
else process.env.SESSION_COOKIE_NAME = saved;
});
describe("host-prefixed session cookie", () => {
it("names the cookie __Host-colite_admin by default", () => {
expect(sessionCookieName()).toBe("__Host-colite_admin");
});
it("prefixes a configured base name exactly once", () => {
process.env.SESSION_COOKIE_NAME = "cl_x";
expect(sessionCookieName()).toBe("__Host-cl_x");
process.env.SESSION_COOKIE_NAME = "__Host-cl_x";
expect(sessionCookieName()).toBe("__Host-cl_x");
});
it("sets the prefixed cookie Secure, Path=/ and without a Domain", async () => {
await setSession("jwt-xyz");
const [name, , opts] = h.setSpy.mock.calls[0];
expect(name).toBe("__Host-colite_admin");
expect(opts).toMatchObject({ secure: true, path: "/" });
expect(opts).not.toHaveProperty("domain");
});
it("ignores a valid signed cookie under the old un-prefixed name", async () => {
h.store.set("colite_admin", await sealSession({ token: "jwt", resetPasswordRequired: false, absoluteExpiry: 4102444800 }));
expect(await readSession()).toBeNull();
});
it("expires the cookie on sign-out with Secure and Path=/ (a browser ignores a __Host- deletion without them)", async () => {
await setSession("jwt-xyz");
h.setSpy.mockClear();
await clearSession();
expect(h.setSpy).toHaveBeenCalledWith("__Host-colite_admin", "", expect.objectContaining({ secure: true, path: "/", maxAge: 0 }));
expect(await readSession()).toBeNull();
});
});