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
45 lines
1.7 KiB
TypeScript
45 lines
1.7 KiB
TypeScript
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
|
|
// sign-session-cookies (F32): the server session reader only trusts a signed cookie.
|
|
const h = vi.hoisted(() => ({ store: new Map<string, string>() }));
|
|
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) => {
|
|
h.store.set(name, value);
|
|
},
|
|
delete: (n: string) => {
|
|
h.store.delete(n);
|
|
},
|
|
}),
|
|
}));
|
|
|
|
import { encodeSession } from "@/app/lib/sessionCodec";
|
|
import { setSession, readSession } from "./session";
|
|
|
|
beforeEach(() => h.store.clear());
|
|
|
|
describe("session cookie signature", () => {
|
|
it("writes a signed cookie that reads back", async () => {
|
|
await setSession("jwt-xyz", true);
|
|
expect(JSON.parse(decodeURIComponent(h.store.get("__Host-colite_admin")!)).sig).toEqual(expect.any(String));
|
|
expect((await readSession())?.token).toBe("jwt-xyz");
|
|
});
|
|
|
|
it("treats an edited cookie as signed out", async () => {
|
|
await setSession("jwt-xyz", true);
|
|
const obj = JSON.parse(decodeURIComponent(h.store.get("__Host-colite_admin")!));
|
|
obj.resetPasswordRequired = false;
|
|
h.store.set("__Host-colite_admin", encodeURIComponent(JSON.stringify(obj)));
|
|
expect(await readSession()).toBeNull();
|
|
});
|
|
|
|
it("treats an unsigned cookie as signed out", async () => {
|
|
await setSession("jwt-xyz", true);
|
|
const { sig, ...unsigned } = JSON.parse(decodeURIComponent(h.store.get("__Host-colite_admin")!));
|
|
expect(sig).toEqual(expect.any(String));
|
|
h.store.set("__Host-colite_admin", encodeSession(unsigned));
|
|
expect(await readSession()).toBeNull();
|
|
});
|
|
});
|