Remove dead token-based verification system
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 12m26s

- Remove verificationsCache array and loadVerifications() function from verification.ts
- Remove verifyToken() and verifyTokenSync() functions (multi-replica unsafe, never used)
- Remove createVerification() function (stores unused data)
- Remove GET /verify route and verifyPage() helper function
- Remove loadVerifications() call from startup
- Remove createVerification() usage from signup route
- Update imports and test mocks to match removed functions
- Keep active 6-digit code system intact (createPendingVerification, verifyCode, etc.)

All 559 tests passing. The active verification system using pending_verifications
table and 6-digit codes continues to work normally.
This commit is contained in:
Hoid 2026-03-08 08:07:20 +01:00
parent d376d586fe
commit 2793207b39
6 changed files with 108 additions and 146 deletions

View file

@ -0,0 +1,101 @@
import { describe, it, expect } from "vitest";
import request from "supertest";
import { app } from "../index.js";
describe("Dead Token Verification System Removal", () => {
describe("Removed Functions", () => {
it("should not export verificationsCache from verification service", async () => {
try {
const verification = await import("../services/verification.js");
expect(verification).not.toHaveProperty("verificationsCache");
} catch (error) {
// This is fine - the export doesn't exist
expect(true).toBe(true);
}
});
it("should not export loadVerifications from verification service", async () => {
try {
const verification = await import("../services/verification.js");
expect(verification).not.toHaveProperty("loadVerifications");
} catch (error) {
// This is fine - the export doesn't exist
expect(true).toBe(true);
}
});
it("should not export verifyToken from verification service", async () => {
try {
const verification = await import("../services/verification.js");
expect(verification).not.toHaveProperty("verifyToken");
} catch (error) {
// This is fine - the export doesn't exist
expect(true).toBe(true);
}
});
it("should not export verifyTokenSync from verification service", async () => {
try {
const verification = await import("../services/verification.js");
expect(verification).not.toHaveProperty("verifyTokenSync");
} catch (error) {
// This is fine - the export doesn't exist
expect(true).toBe(true);
}
});
it("should not export createVerification from verification service", async () => {
try {
const verification = await import("../services/verification.js");
expect(verification).not.toHaveProperty("createVerification");
} catch (error) {
// This is fine - the export doesn't exist
expect(true).toBe(true);
}
});
});
describe("Removed Routes", () => {
it("should return 404 for GET /verify route", async () => {
const response = await request(app).get("/verify").query({ token: "some-token" });
expect(response.status).toBe(404);
});
it("should return 404 for GET /verify route without token", async () => {
const response = await request(app).get("/verify");
expect(response.status).toBe(404);
});
});
describe("Active System Still Works", () => {
it("should export createPendingVerification", async () => {
const verification = await import("../services/verification.js");
expect(verification).toHaveProperty("createPendingVerification");
expect(typeof verification.createPendingVerification).toBe("function");
});
it("should export verifyCode", async () => {
const verification = await import("../services/verification.js");
expect(verification).toHaveProperty("verifyCode");
expect(typeof verification.verifyCode).toBe("function");
});
it("should export isEmailVerified", async () => {
const verification = await import("../services/verification.js");
expect(verification).toHaveProperty("isEmailVerified");
expect(typeof verification.isEmailVerified).toBe("function");
});
it("should export getVerifiedApiKey", async () => {
const verification = await import("../services/verification.js");
expect(verification).toHaveProperty("getVerifiedApiKey");
expect(typeof verification.getVerifiedApiKey).toBe("function");
});
it("should export PendingVerification interface", async () => {
// TypeScript interface test - if compilation passes, the interface exists
const verification = await import("../services/verification.js");
expect(verification).toBeDefined();
});
});
});

View file

@ -72,12 +72,9 @@ vi.mock("../services/browser.js", () => ({
// Mock verification service
vi.mock("../services/verification.js", () => ({
verifyToken: vi.fn().mockReturnValue({ status: "invalid" }),
loadVerifications: vi.fn().mockResolvedValue(undefined),
createPendingVerification: vi.fn().mockResolvedValue({ email: "test@test.com", code: "123456" }),
verifyCode: vi.fn().mockResolvedValue({ status: "ok" }),
isEmailVerified: vi.fn().mockResolvedValue(false),
createVerification: vi.fn().mockResolvedValue({ email: "test@test.com", token: "tok", apiKey: "key", createdAt: "", verifiedAt: null }),
getVerifiedApiKey: vi.fn().mockResolvedValue(null),
}));

View file

@ -8,7 +8,7 @@ beforeEach(async () => {
vi.clearAllMocks();
vi.resetModules();
const { isEmailVerified, createPendingVerification, verifyCode, createVerification } = await import("../services/verification.js");
const { isEmailVerified, createPendingVerification, verifyCode } = await import("../services/verification.js");
const { sendVerificationEmail } = await import("../services/email.js");
const { createFreeKey } = await import("../services/keys.js");
@ -16,7 +16,7 @@ beforeEach(async () => {
vi.mocked(createPendingVerification).mockResolvedValue({ email: "test@test.com", code: "123456", createdAt: "", expiresAt: "", attempts: 0 });
vi.mocked(verifyCode).mockResolvedValue({ status: "ok" });
vi.mocked(createFreeKey).mockResolvedValue({ key: "free-key-123", tier: "free", email: "test@test.com", createdAt: "" });
vi.mocked(createVerification).mockResolvedValue({ email: "test@test.com", token: "tok", apiKey: "free-key-123", createdAt: "", verifiedAt: null });
vi.mocked(sendVerificationEmail).mockResolvedValue(true);
const { signupRouter } = await import("../routes/signup.js");