31 lines
881 B
TypeScript
31 lines
881 B
TypeScript
import { describe, expect, it } from "vitest";
|
||
import type { Request } from "express";
|
||
import { getSessionCookieOptions } from "./cookies";
|
||
|
||
function requestFor(protocol: "http" | "https", forwardedProto?: string): Request {
|
||
return {
|
||
protocol,
|
||
headers: forwardedProto ? { "x-forwarded-proto": forwardedProto } : {},
|
||
} as Request;
|
||
}
|
||
|
||
describe("getSessionCookieOptions", () => {
|
||
it("utilise des cookies sécurisés derrière le proxy HTTPS", () => {
|
||
expect(getSessionCookieOptions(requestFor("http", "https"))).toMatchObject({
|
||
httpOnly: true,
|
||
path: "/",
|
||
secure: true,
|
||
sameSite: "none",
|
||
});
|
||
});
|
||
|
||
it("reste compatible avec l’environnement HTTP local", () => {
|
||
expect(getSessionCookieOptions(requestFor("http"))).toMatchObject({
|
||
httpOnly: true,
|
||
path: "/",
|
||
secure: false,
|
||
sameSite: "lax",
|
||
});
|
||
});
|
||
});
|