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
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-bb_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-bb_admin")!));
|
|
obj.resetPasswordRequired = false;
|
|
h.store.set("__Host-bb_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-bb_admin")!));
|
|
expect(sig).toEqual(expect.any(String));
|
|
h.store.set("__Host-bb_admin", encodeSession(unsigned));
|
|
expect(await readSession()).toBeNull();
|
|
});
|
|
});
|