Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -4,6 +4,28 @@ const storeMock = vi.hoisted(() => ({
createUserSession: vi.fn(),
revokeSessionByToken: vi.fn(),
}));
const adminStoreMock = vi.hoisted(() => ({
createAdminSession: vi.fn(),
revokeAdminSessionByToken: vi.fn(),
}));
vi.mock("@hivegrid/config", async (importOriginal) => {
const actual = await importOriginal<typeof import("@hivegrid/config")>();
return {
...actual,
loadRequiredWebConfig: () => ({
routing: {
appBaseDomain: "example.test",
protocol: "https",
webAppHost: "app.example.test",
adminAppHost: "admin.example.test",
},
}),
};
});
vi.mock("@hivegrid/db/admin-sessions.server", () => ({
createAdminSession: (...args: unknown[]) => adminStoreMock.createAdminSession(...args),
revokeAdminSessionByToken: (...args: unknown[]) => adminStoreMock.revokeAdminSessionByToken(...args),
}));
vi.mock("./sessionStore.server", () => ({
createUserSession: (...args: unknown[]) => storeMock.createUserSession(...args),
revokeSessionByToken: (...args: unknown[]) => storeMock.revokeSessionByToken(...args),
@@ -22,6 +44,10 @@ function requestWith(headers: Record<string, string>) {
return new Request("https://example.test/login", { headers });
}
function adminRequestWith(headers: Record<string, string>) {
return new Request("https://admin.example.test/login", { headers });
}
beforeEach(() => {
vi.clearAllMocks();
geoMock.lookupCountry.mockResolvedValue({ countryCode: "DE", countryName: "Germany" });
@@ -29,7 +55,13 @@ beforeEach(() => {
describe("buildSessionDeviceContext (AD-22)", () => {
it("hashes the IP and resolves the country, never exposing the raw IP", async () => {
const ctx = await buildSessionDeviceContext(requestWith({ "user-agent": "Safari", "x-forwarded-for": "9.9.9.9" }));
const ctx = await buildSessionDeviceContext(
requestWith({
"user-agent": "Safari",
"cf-connecting-ip": "9.9.9.9",
"x-forwarded-for": "198.51.100.9, 173.245.48.10",
}),
);
expect(ctx.ipHash).toBe("HASHED");
expect(ctx.userAgent).toBe("Safari");
expect(ctx.approxLocation).toBe("Germany");
@@ -48,10 +80,45 @@ describe("buildSessionDeviceContext (AD-22)", () => {
describe("startServerSession", () => {
it("creates a session row with the pseudonymized device context and returns the raw token", async () => {
storeMock.createUserSession.mockResolvedValue({ session: { id: "s1" }, rawToken: "tok-123" });
const token = await startServerSession({ request: requestWith({ "user-agent": "Safari", "x-forwarded-for": "1.2.3.4" }), userId: "u1" });
const token = await startServerSession({
request: requestWith({
"user-agent": "Safari",
"cf-connecting-ip": "1.2.3.4",
"x-forwarded-for": "198.51.100.4, 173.245.48.10",
}),
userId: "u1",
});
expect(token).toBe("tok-123");
expect(storeMock.createUserSession).toHaveBeenCalledWith({ userId: "u1", ipHash: "HASHED", userAgent: "Safari", approxLocation: "Germany" });
});
it("creates a dedicated eight-hour AdminSession only with Authentik MFA assurance", async () => {
const mfaAssuredAt = new Date("2026-07-24T18:00:00.000Z");
adminStoreMock.createAdminSession.mockResolvedValue({ session: { id: "as1" }, rawToken: "admin-token" });
const token = await startServerSession({
request: adminRequestWith({ "user-agent": "Safari" }),
userId: "admin-1",
adminAuthenticationMethods: ["pwd", "mfa"],
adminMfaAssuredAt: mfaAssuredAt,
});
expect(token).toBe("admin-token");
expect(adminStoreMock.createAdminSession).toHaveBeenCalledWith({
adminUserId: "admin-1",
authenticationMethods: ["pwd", "mfa"],
mfaAssuredAt,
ipHash: null,
userAgent: "Safari",
approxLocation: null,
});
expect(storeMock.createUserSession).not.toHaveBeenCalled();
});
it("fails closed on the admin host without MFA assurance", async () => {
await expect(startServerSession({ request: adminRequestWith({}), userId: "admin-1" })).rejects.toThrow(
"Admin server session requires Authentik MFA assurance"
);
expect(adminStoreMock.createAdminSession).not.toHaveBeenCalled();
});
});
describe("endServerSession", () => {
@@ -60,4 +127,12 @@ describe("endServerSession", () => {
await endServerSession("tok-123");
expect(storeMock.revokeSessionByToken).toHaveBeenCalledWith("tok-123");
});
it("revokes only the dedicated AdminSession on the admin host", async () => {
adminStoreMock.revokeAdminSessionByToken.mockResolvedValue(true);
const request = adminRequestWith({});
await endServerSession("admin-token", request);
expect(adminStoreMock.revokeAdminSessionByToken).toHaveBeenCalledWith("admin-token");
expect(storeMock.revokeSessionByToken).not.toHaveBeenCalled();
});
});