Honor the share-link miss limit before querying, and keep Escape inside the access menu.
This commit is contained in:
1 parent
75649a9a42
commit
1b3d055c81
8 files changed
+189
-19
No files matched your search
@@ -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();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user