Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+55
-5
@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("~/locale/i18next.server", () => ({ getTranslations: vi.fn(async () => ({ t: (key: string) => `translated:${key}` })) }));
|
||||
vi.mock("~/modules/onboarding/db/onboardingSessions.db.server", () => ({ getOnboardingSession: vi.fn() }));
|
||||
vi.mock("~/utils/db/tenants.db.server", () => ({ getTenantSessionIdentityForUser: vi.fn() }));
|
||||
vi.mock("~/modules/onboarding/services/OnboardingSessionService", () => ({
|
||||
default: {
|
||||
addActions: vi.fn(),
|
||||
@@ -18,8 +19,10 @@ vi.mock("~/utils/session.server", () => ({
|
||||
}));
|
||||
|
||||
const onboardingDb = await import("~/modules/onboarding/db/onboardingSessions.db.server");
|
||||
const tenantDb = await import("~/utils/db/tenants.db.server");
|
||||
const serviceModule = await import("~/modules/onboarding/services/OnboardingSessionService");
|
||||
const sessionServer = await import("~/utils/session.server");
|
||||
const rlsContext = await import("@hivegrid/db/rls-context.server");
|
||||
const { action, loader } = await import("./onboarding.$id");
|
||||
|
||||
const ownedSession = {
|
||||
@@ -46,6 +49,21 @@ describe("onboarding session route security", () => {
|
||||
expect(response).toMatchObject({ item: ownedSession });
|
||||
});
|
||||
|
||||
it("binds the authenticated user before reading the protected onboarding resource", async () => {
|
||||
vi.mocked(onboardingDb.getOnboardingSession).mockImplementationOnce(async () => {
|
||||
expect(rlsContext.getRlsExecutionContext()).toMatchObject({ userId: "user_1" });
|
||||
return ownedSession;
|
||||
});
|
||||
|
||||
await loader({
|
||||
request: new Request("https://app.example.com/onboarding/session_1"),
|
||||
params: { id: "session_1" },
|
||||
context: {},
|
||||
} as unknown as LoaderFunctionArgs);
|
||||
|
||||
expect(rlsContext.getRlsExecutionContext()).toBeNull();
|
||||
});
|
||||
|
||||
it("rejects onboarding sessions owned by another user", async () => {
|
||||
vi.mocked(onboardingDb.getOnboardingSession).mockResolvedValueOnce({ ...ownedSession, userId: "user_2" });
|
||||
|
||||
@@ -59,8 +77,8 @@ describe("onboarding session route security", () => {
|
||||
context: {},
|
||||
} as unknown as ActionFunctionArgs)) as Response;
|
||||
|
||||
expect(response.status).toBe(401);
|
||||
await expect(response.json()).resolves.toEqual({ error: "translated:onboarding.session.errors.unauthorized" });
|
||||
expect(response.status).toBe(404);
|
||||
await expect(response.json()).resolves.toEqual({ error: "translated:onboarding.session.errors.notFound" });
|
||||
expect(serviceModule.default.started).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -73,8 +91,8 @@ describe("onboarding session route security", () => {
|
||||
context: {},
|
||||
} as unknown as LoaderFunctionArgs).catch((error: Response) => error);
|
||||
|
||||
expect(response.status).toBe(401);
|
||||
await expect(response.json()).resolves.toEqual({ error: "translated:onboarding.session.errors.unauthorized" });
|
||||
expect(response.status).toBe(404);
|
||||
await expect(response.json()).resolves.toEqual({ error: "translated:onboarding.session.errors.notFound" });
|
||||
});
|
||||
|
||||
it("returns localized not-found errors for missing onboarding sessions", async () => {
|
||||
@@ -121,6 +139,38 @@ describe("onboarding session route security", () => {
|
||||
expect(serviceModule.default.started).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("rejects a tenant-owned session when the user has no active membership", async () => {
|
||||
vi.mocked(onboardingDb.getOnboardingSession).mockResolvedValueOnce({ ...ownedSession, tenantId: "tenant_2" });
|
||||
vi.mocked(tenantDb.getTenantSessionIdentityForUser).mockResolvedValueOnce(null);
|
||||
|
||||
const response = (await action({
|
||||
request: new Request("https://app.example.com/onboarding/session_1", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
||||
body: new URLSearchParams({ action: "started", csrf: "csrf-token" }),
|
||||
}),
|
||||
params: { id: "session_1" },
|
||||
context: {},
|
||||
} as unknown as ActionFunctionArgs)) as Response;
|
||||
|
||||
expect(response.status).toBe(404);
|
||||
expect(tenantDb.getTenantSessionIdentityForUser).toHaveBeenCalledWith({ userId: "user_1", tenant: "tenant_2" });
|
||||
expect(serviceModule.default.started).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("authenticates before attempting the onboarding resource lookup", async () => {
|
||||
vi.mocked(sessionServer.getUserInfo).mockResolvedValueOnce({ userId: null } as any);
|
||||
|
||||
const response = await loader({
|
||||
request: new Request("https://app.example.com/onboarding/session_1"),
|
||||
params: { id: "session_1" },
|
||||
context: {},
|
||||
} as unknown as LoaderFunctionArgs).catch((error: Response) => error);
|
||||
|
||||
expect(response.status).toBe(401);
|
||||
expect(onboardingDb.getOnboardingSession).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not mutate when CSRF validation fails", async () => {
|
||||
vi.mocked(sessionServer.validateCSRFToken).mockRejectedValueOnce(new Error("Invalid CSRF token"));
|
||||
|
||||
@@ -135,7 +185,7 @@ describe("onboarding session route security", () => {
|
||||
} as unknown as ActionFunctionArgs)) as Response;
|
||||
|
||||
expect(response.status).toBe(400);
|
||||
await expect(response.json()).resolves.toEqual({ error: "Invalid CSRF token" });
|
||||
await expect(response.json()).resolves.toEqual({ error: "translated:errors:invalidCsrfToken" });
|
||||
expect(serviceModule.default.started).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user