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
@@ -24,11 +24,8 @@ vi.mock("../cache.server", () => ({ cachified: vi.fn(), clearCacheKey: vi.fn() }
|
||||
const testDir = path.dirname(fileURLToPath(import.meta.url));
|
||||
const usersSource = readFileSync(path.join(testDir, "users.db.server.ts"), "utf8");
|
||||
const schemaSource = readFileSync(path.join(testDir, "../../../../../prisma/schema/accounts.prisma"), "utf8");
|
||||
const migrationSource = readFileSync(path.join(testDir, "../../../../../prisma/migrations/20260508130000_user_totp_mfa/migration.sql"), "utf8");
|
||||
const recoveryCodesMigrationSource = readFileSync(
|
||||
path.join(testDir, "../../../../../prisma/migrations/20260508133000_user_mfa_recovery_codes/migration.sql"),
|
||||
"utf8"
|
||||
);
|
||||
const baselineSource = readFileSync(path.join(testDir, "../../../../../prisma/migrations/00000000000000_hivegrid_baseline/migration.sql"), "utf8");
|
||||
const userTableSource = baselineSource.match(/CREATE TABLE public\."User" \([\s\S]*?\n\);/)?.[0] ?? "";
|
||||
|
||||
describe("user TOTP MFA storage contract", () => {
|
||||
beforeEach(() => {
|
||||
@@ -38,28 +35,30 @@ describe("user TOTP MFA storage contract", () => {
|
||||
mockFindUnique.mockReset();
|
||||
});
|
||||
|
||||
test("schema and migration define nullable encrypted TOTP state without defaults", () => {
|
||||
test("schema and baseline define nullable encrypted TOTP state without defaults", () => {
|
||||
expect(schemaSource).toContain("totpSecretEncrypted String?");
|
||||
expect(schemaSource).toContain("totpPendingSecretEncrypted String?");
|
||||
expect(schemaSource).toContain("totpEnabledAt DateTime?");
|
||||
expect(schemaSource).toContain("totpPendingCreatedAt DateTime?");
|
||||
|
||||
for (const column of ["totpSecretEncrypted", "totpPendingSecretEncrypted", "totpEnabledAt", "totpPendingCreatedAt"]) {
|
||||
expect(migrationSource).toContain(`ADD COLUMN "${column}"`);
|
||||
expect(userTableSource).toMatch(new RegExp(`"${column}"\\s+(?:text|timestamp\\(3\\) without time zone),`, "i"));
|
||||
}
|
||||
expect(migrationSource).not.toMatch(/NOT NULL|DEFAULT|otpauth|secret_fixture|totp-secret/i);
|
||||
expect(userTableSource).not.toMatch(/"totp(?:SecretEncrypted|PendingSecretEncrypted|EnabledAt|PendingCreatedAt)"[^,]*(?:NOT NULL|DEFAULT)/i);
|
||||
expect(userTableSource).not.toMatch(/otpauth|secret_fixture|totp-secret/i);
|
||||
});
|
||||
|
||||
test("schema and migration define nullable hashed recovery-code state without plaintext fixtures", () => {
|
||||
test("schema and baseline define nullable hashed recovery-code state without plaintext fixtures", () => {
|
||||
expect(schemaSource).toContain("mfaRecoveryCodeHashes Json?");
|
||||
expect(schemaSource).toContain("mfaRecoveryCodesGeneratedAt DateTime?");
|
||||
expect(schemaSource).toContain("mfaRecoveryCodeLastUsedAt DateTime?");
|
||||
expect(schemaSource).not.toMatch(/recoveryCodesPlaintext|recoveryCodePlaintext|mfaRecoveryCodePlain|mfaRecoveryCodesPlain/i);
|
||||
|
||||
for (const column of ["mfaRecoveryCodeHashes", "mfaRecoveryCodesGeneratedAt", "mfaRecoveryCodeLastUsedAt"]) {
|
||||
expect(recoveryCodesMigrationSource).toContain(`ADD COLUMN "${column}"`);
|
||||
expect(userTableSource).toMatch(new RegExp(`"${column}"\\s+(?:jsonb|timestamp\\(3\\) without time zone),`, "i"));
|
||||
}
|
||||
expect(recoveryCodesMigrationSource).not.toMatch(/NOT NULL|DEFAULT|\b[A-Z0-9]{4}-[A-Z0-9]{4}\b|plaintext|plain text|secret_fixture|recovery-code-secret/i);
|
||||
expect(userTableSource).not.toMatch(/"mfaRecoveryCode(?:Hashes|sGeneratedAt|LastUsedAt)"[^,]*(?:NOT NULL|DEFAULT)/i);
|
||||
expect(userTableSource).not.toMatch(/\b[A-Z0-9]{4}-[A-Z0-9]{4}\b|plaintext|plain text|secret_fixture|recovery-code-secret/i);
|
||||
});
|
||||
|
||||
test("generic getUser select omits encrypted TOTP fields and recovery-code hashes", () => {
|
||||
@@ -89,6 +88,31 @@ describe("user TOTP MFA storage contract", () => {
|
||||
expect(clearCacheKey).toHaveBeenCalledWith("user:user_1");
|
||||
});
|
||||
|
||||
test("clearUserTotpPendingSecret only clears the expected pending enrollment", async () => {
|
||||
const { clearUserTotpPendingSecret } = await import("./users.db.server");
|
||||
const { clearCacheKey } = await import("../cache.server");
|
||||
const pendingCreatedAt = new Date("2026-05-08T13:00:00.000Z");
|
||||
mockUpdateMany.mockResolvedValueOnce({ count: 1 });
|
||||
|
||||
await clearUserTotpPendingSecret("user_1", {
|
||||
totpPendingSecretEncrypted: "encrypted-pending-secret",
|
||||
totpPendingCreatedAt: pendingCreatedAt,
|
||||
});
|
||||
|
||||
expect(mockUpdateMany).toHaveBeenCalledWith({
|
||||
where: {
|
||||
id: "user_1",
|
||||
totpPendingSecretEncrypted: "encrypted-pending-secret",
|
||||
totpPendingCreatedAt: pendingCreatedAt,
|
||||
},
|
||||
data: {
|
||||
totpPendingSecretEncrypted: null,
|
||||
totpPendingCreatedAt: null,
|
||||
},
|
||||
});
|
||||
expect(clearCacheKey).toHaveBeenCalledWith("user:user_1");
|
||||
});
|
||||
|
||||
test("activateUserTotpPendingSecret promotes pending secret, clears pending fields, and clears cache", async () => {
|
||||
const { activateUserTotpPendingSecret } = await import("./users.db.server");
|
||||
const { clearCacheKey } = await import("../cache.server");
|
||||
|
||||
Reference in new issue
Block a user