Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
@@ -0,0 +1,112 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { resolveApiSessionCookiePolicy, resolveSessionCookiePolicy } from "./session-cookie.js";
|
||||
|
||||
const productionRouting = {
|
||||
appBaseDomain: "example.com",
|
||||
protocol: "https" as const,
|
||||
};
|
||||
|
||||
describe("session cookie policy", () => {
|
||||
test("sets a shared hardened cookie policy for production app base domains", () => {
|
||||
const policy = resolveSessionCookiePolicy({
|
||||
nodeEnv: "production",
|
||||
routing: productionRouting,
|
||||
name: "session",
|
||||
maxAge: 60 * 60,
|
||||
});
|
||||
|
||||
expect(policy).toEqual({
|
||||
name: "session",
|
||||
maxAge: 3600,
|
||||
domain: "example.com",
|
||||
sameSite: "lax",
|
||||
secure: true,
|
||||
httpOnly: true,
|
||||
path: "/",
|
||||
});
|
||||
expect(JSON.stringify(policy)).not.toContain("secret");
|
||||
});
|
||||
|
||||
test("keeps localhost cookies domainless for local development", () => {
|
||||
expect(
|
||||
resolveSessionCookiePolicy({
|
||||
nodeEnv: "development",
|
||||
routing: {
|
||||
appBaseDomain: "localhost:3000",
|
||||
protocol: "http",
|
||||
},
|
||||
})
|
||||
).toEqual({
|
||||
sameSite: "lax",
|
||||
secure: false,
|
||||
httpOnly: true,
|
||||
path: "/",
|
||||
});
|
||||
|
||||
expect(
|
||||
resolveSessionCookiePolicy({
|
||||
nodeEnv: "development",
|
||||
routing: {
|
||||
appBaseDomain: "app.localhost",
|
||||
protocol: "http",
|
||||
},
|
||||
})
|
||||
).not.toHaveProperty("domain");
|
||||
});
|
||||
|
||||
test("enables secure cookies for HTTPS routing outside production", () => {
|
||||
expect(
|
||||
resolveSessionCookiePolicy({
|
||||
nodeEnv: "test",
|
||||
routing: {
|
||||
appBaseDomain: "example.test",
|
||||
protocol: "https",
|
||||
},
|
||||
})
|
||||
).toMatchObject({
|
||||
domain: "example.test",
|
||||
sameSite: "lax",
|
||||
secure: true,
|
||||
httpOnly: true,
|
||||
path: "/",
|
||||
});
|
||||
});
|
||||
|
||||
test("resolves API session cookies with the API name and shared production hardening", () => {
|
||||
const policy = resolveApiSessionCookiePolicy({
|
||||
nodeEnv: "production",
|
||||
routing: productionRouting,
|
||||
maxAge: 60 * 15,
|
||||
});
|
||||
|
||||
expect(policy).toEqual({
|
||||
name: "RJ_api_session",
|
||||
maxAge: 900,
|
||||
domain: "example.com",
|
||||
sameSite: "lax",
|
||||
secure: true,
|
||||
httpOnly: true,
|
||||
path: "/",
|
||||
});
|
||||
expect(policy.name).not.toBe("RJ_session");
|
||||
expect(JSON.stringify(policy)).not.toContain("secret");
|
||||
});
|
||||
|
||||
test("keeps API session cookies domainless and insecure on localhost HTTP", () => {
|
||||
const policy = resolveApiSessionCookiePolicy({
|
||||
nodeEnv: "development",
|
||||
routing: {
|
||||
appBaseDomain: "localhost:3000",
|
||||
protocol: "http",
|
||||
},
|
||||
});
|
||||
|
||||
expect(policy).toEqual({
|
||||
name: "RJ_api_session",
|
||||
sameSite: "lax",
|
||||
secure: false,
|
||||
httpOnly: true,
|
||||
path: "/",
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user