Honor the share-link miss limit before querying, and keep Escape inside the access menu.

This commit is contained in:
adilallo committed 2026-11-21 11:56:34 -07:00
1 parent 75649a9a42
commit 1b3d055c81
8 files changed
+189 -19

No files matched your search

+19 -1
View File
@@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
const getReadablePublishedRuleMock = vi.fn();
const getSessionUserMock = vi.fn();
const rateLimitKeyMock = vi.fn();
const notFoundMock = vi.fn(() => {
throw new Error("NEXT_NOT_FOUND");
});
@@ -16,10 +17,11 @@ vi.mock("next/headers", () => ({
}));
vi.mock("../../lib/server/rateLimit", () => ({
rateLimitKey: () => ({ ok: true }),
rateLimitKey: (...args: unknown[]) => rateLimitKeyMock(...args),
}));
vi.mock("../../lib/server/publishedRules", () => ({
SHARE_LOOKUP_MISS_INTERVAL_MS: 1_000,
getReadablePublishedRule: (...args: unknown[]) =>
getReadablePublishedRuleMock(...args),
}));
@@ -34,6 +36,8 @@ describe("shared Rule page", () => {
beforeEach(() => {
getReadablePublishedRuleMock.mockReset();
getSessionUserMock.mockReset();
rateLimitKeyMock.mockReset();
rateLimitKeyMock.mockReturnValue({ ok: true });
notFoundMock.mockClear();
getSessionUserMock.mockResolvedValue(null);
});
@@ -47,4 +51,18 @@ describe("shared Rule page", () => {
).rejects.toThrow("NEXT_NOT_FOUND");
expect(notFoundMock).toHaveBeenCalled();
});
it("does not look up a malformed slug when the miss limit refuses", async () => {
rateLimitKeyMock.mockReturnValue({ ok: false, retryAfterMs: 1_000 });
await expect(
generateMetadata({
params: Promise.resolve({ shareSlug: "not-a-slug" }),
}),
).rejects.toThrow("NEXT_NOT_FOUND");
expect(rateLimitKeyMock).toHaveBeenCalledWith(
"share-lookup-miss:203.0.113.8",
1_000,
);
expect(getReadablePublishedRuleMock).not.toHaveBeenCalled();
});
});