import { describe, expect, it } from "vitest"; import { CAL_DAV_ALLOW } from "@/worker/caldav/handler"; import { CARD_DAV_ALLOW } from "@/worker/carddav/handler"; import { DAV_DISCOVERY_ALLOW } from "@/worker/dav/discovery"; import { FILES_DAV_ALLOW } from "@/worker/webdav/constants"; import { createDavFixture, davRequest } from "@tests/worker/helpers/dav"; import { fetchWorker } from "@tests/worker/helpers/http"; describe("DAV runtime registry", () => { it("keeps scoped OPTIONS and method-not-allowed Allow headers per area", async () => { const calOnly = await createDavFixture(["caldav.readonly"]); const calOptions = await fetchWorker(davRequest(calOnly, "/calendars/", { method: "OPTIONS" })); expect(calOptions.status).toBe(204); expect(calOptions.headers.get("allow")).toBe(CAL_DAV_ALLOW); const filesOptions = await fetchWorker(davRequest(calOnly, "/files/", { method: "OPTIONS" })); expect(filesOptions.status).toBe(403); const full = await createDavFixture(["dav.full"]); const filesPost = await fetchWorker(davRequest(full, "/files/", { method: "POST" })); expect(filesPost.status).toBe(405); expect(filesPost.headers.get("allow")).toBe(FILES_DAV_ALLOW); const calPost = await fetchWorker(davRequest(full, "/calendars/", { method: "POST" })); expect(calPost.status).toBe(405); expect(calPost.headers.get("allow")).toBe(CAL_DAV_ALLOW); const cardPost = await fetchWorker(davRequest(full, "/addressbooks/", { method: "POST" })); expect(cardPost.status).toBe(405); expect(cardPost.headers.get("allow")).toBe(CARD_DAV_ALLOW); const discoveryPost = await fetchWorker(davRequest(full, "/", { method: "POST" })); expect(discoveryPost.status).toBe(405); expect(discoveryPost.headers.get("allow")).toBe(DAV_DISCOVERY_ALLOW); }); it("leaves unknown subject-host DAV paths as not found", async () => { const fixture = await createDavFixture(["dav.full"]); const response = await fetchWorker( davRequest(fixture, "/not-dav/", { method: "PROPFIND", headers: { depth: "infinity" } }), ); expect(response.status).toBe(404); }); });