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
+95
@@ -0,0 +1,95 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const getRegistrationVerificationViewByToken = vi.fn();
|
||||
const loadPasswordPolicy = vi.fn(() => ({
|
||||
minLength: 14,
|
||||
requireUpper: true,
|
||||
requireLower: true,
|
||||
requireDigit: true,
|
||||
requireSpecial: false,
|
||||
hibpCheck: true,
|
||||
hibpMaxOccurrences: 0,
|
||||
}));
|
||||
const BOUND_CREATION_REQUEST_KEY = "d7077797-054b-497a-b1ce-8e4f36257a96";
|
||||
|
||||
vi.mock("~/utils/db/registration.db.server", () => ({
|
||||
getRegistrationVerificationViewByToken,
|
||||
}));
|
||||
|
||||
vi.mock("~/locale/i18next.server", () => ({
|
||||
getTranslations: vi.fn(async () => ({ t: (key: string) => key })),
|
||||
}));
|
||||
|
||||
vi.mock("~/modules/users/services/AuthService", () => ({
|
||||
default: { verifyFromRequest: vi.fn() },
|
||||
}));
|
||||
|
||||
vi.mock("~/services/auth/password-policy.server", () => ({ loadPasswordPolicy }));
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe("verify.$id public loader", () => {
|
||||
it("hydrates only the email projection for an unconsumed registration", async () => {
|
||||
getRegistrationVerificationViewByToken.mockResolvedValueOnce({
|
||||
status: "pending",
|
||||
email: "ada@example.test",
|
||||
token: "must-not-be-hydrated",
|
||||
ipAddress: "203.0.113.4",
|
||||
leadConversionToken: "must-not-be-hydrated",
|
||||
creationRequestKey: BOUND_CREATION_REQUEST_KEY,
|
||||
});
|
||||
const route = await import("./verify.$id.tsx");
|
||||
|
||||
const result = await route.loader({
|
||||
params: { id: "verification-token" },
|
||||
request: new Request("https://example.test/verify/verification-token?creationRequestKey=b79f4743-b5ee-48df-9287-10f24b2aedbf"),
|
||||
context: {},
|
||||
} as unknown as Parameters<typeof route.loader>[0]);
|
||||
|
||||
expect(result.registration).toEqual({ email: "ada@example.test" });
|
||||
expect(result.creationRequestKey).toBe(BOUND_CREATION_REQUEST_KEY);
|
||||
expect(result.verificationStatus).toBe("pending");
|
||||
expect(result.passwordPolicy).toMatchObject({ minLength: 14, requireUpper: true, requireSpecial: false });
|
||||
expect(loadPasswordPolicy).toHaveBeenCalledOnce();
|
||||
expect(JSON.stringify(result)).not.toContain("must-not-be-hydrated");
|
||||
expect(JSON.stringify(result)).not.toContain("203.0.113.4");
|
||||
}, 60000);
|
||||
|
||||
it("does not hydrate the email for a consumed registration", async () => {
|
||||
getRegistrationVerificationViewByToken.mockResolvedValueOnce({
|
||||
status: "used",
|
||||
});
|
||||
const route = await import("./verify.$id.tsx");
|
||||
|
||||
const result = await route.loader({
|
||||
params: { id: "used-token" },
|
||||
request: new Request("https://example.test/verify/used-token"),
|
||||
context: {},
|
||||
} as unknown as Parameters<typeof route.loader>[0]);
|
||||
|
||||
expect(result.registration).toBeNull();
|
||||
expect(result.verificationStatus).toBe("used");
|
||||
expect(JSON.stringify(result)).not.toContain("ada@example.test");
|
||||
});
|
||||
|
||||
it.each(["expired", "invalid"] as const)("returns the %s state without hydrating registration PII", async (status) => {
|
||||
getRegistrationVerificationViewByToken.mockResolvedValueOnce({ status });
|
||||
const route = await import("./verify.$id.tsx");
|
||||
|
||||
const result = await route.loader({
|
||||
params: { id: `${status}-token` },
|
||||
request: new Request(`https://example.test/verify/${status}-token`),
|
||||
context: {},
|
||||
} as unknown as Parameters<typeof route.loader>[0]);
|
||||
|
||||
expect(result).toMatchObject({ registration: null, creationRequestKey: "", verificationStatus: status });
|
||||
expect(JSON.stringify(result)).not.toContain("example.test");
|
||||
});
|
||||
|
||||
it("prevents caching and referrer leakage for capability URLs", async () => {
|
||||
const route = await import("./verify.$id.tsx");
|
||||
expect(route.headers()).toEqual({ "Cache-Control": "no-store", "Referrer-Policy": "no-referrer" });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user