f7fd1c4402
* feat: remove unused x-cal-timezone header and middleware matcher - Remove x-cal-timezone header setting from middleware.ts - Remove x-cal-timezone header setting from createNextApiHandler.ts - Remove /api/trpc/:path* from middleware matcher - Eliminates ~50M edge requests per month for unused functionality - All timezone handling uses browser detection and localStorage instead Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * update POST_METHODS_ALLOWED_API_ROUTES * test: remove api/trpc POST validation test - Remove test for /api/trpc/book/event POST requests since /api/trpc/:path* was removed from middleware matcher - Keep test for /api/auth/signup which is still processed by middleware Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: hbjORbj <sldisek783@gmail.com>
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { NextRequest } from "next/server";
|
|
import { describe, it, expect } from "vitest";
|
|
|
|
import { WEBAPP_URL } from "@calcom/lib/constants";
|
|
|
|
import { checkPostMethod } from "./middleware";
|
|
|
|
describe("Middleware - POST requests restriction", () => {
|
|
const createRequest = (path: string, method: string) => {
|
|
return new NextRequest(
|
|
new Request(`${WEBAPP_URL}${path}`, {
|
|
method,
|
|
})
|
|
);
|
|
};
|
|
|
|
it("should allow POST requests to /api routes", async () => {
|
|
const req1 = createRequest("/api/auth/signup", "POST");
|
|
const res1 = checkPostMethod(req1);
|
|
expect(res1).toBeNull();
|
|
});
|
|
|
|
it("should block POST requests to not-allowed app routes", async () => {
|
|
const req = createRequest("/team/xyz", "POST");
|
|
const res = checkPostMethod(req);
|
|
expect(res).not.toBeNull();
|
|
expect(res?.status).toBe(405);
|
|
expect(res?.statusText).toBe("Method Not Allowed");
|
|
expect(res?.headers.get("Allow")).toBe("GET");
|
|
});
|
|
|
|
it("should allow GET requests to app routes", async () => {
|
|
const req = createRequest("/team/xyz", "GET");
|
|
const res = checkPostMethod(req);
|
|
expect(res).toBeNull();
|
|
});
|
|
|
|
it("should allow GET requests to /api routes", async () => {
|
|
const req = createRequest("/api/auth/signup", "GET");
|
|
const res = checkPostMethod(req);
|
|
expect(res).toBeNull();
|
|
});
|
|
});
|