File
Blob: tests/worker/protocol/dav/runtime.test.ts
| 1 | import { describe, expect, it } from "vitest"; |
| 2 | |
| 3 | import { DAV_AREAS } from "@/worker/dav/areas"; |
| 4 | import { expensiveDavRequestArea, findDavArea, isExpensiveDavRequest } from "@/worker/dav/runtime"; |
| 5 | |
| 6 | describe("DAV runtime registry", () => { |
| 7 | it("matches registered areas and preserves expensive request area keys", () => { |
| 8 | expect(findDavArea("/files/", DAV_AREAS)?.name).toBe("files"); |
| 9 | expect(findDavArea("/calendars/default/", DAV_AREAS)?.name).toBe("caldav"); |
| 10 | expect(findDavArea("/addressbooks/default/", DAV_AREAS)?.name).toBe("carddav"); |
| 11 | expect(findDavArea("/principals/me/", DAV_AREAS)?.name).toBe("discovery"); |
| 12 | expect(findDavArea("/not-dav/", DAV_AREAS)).toBeNull(); |
| 13 | |
| 14 | expect(expensiveDavRequestArea("/files/a.txt")).toBe("files"); |
| 15 | expect(expensiveDavRequestArea("/calendars/default/")).toBe("calendars"); |
| 16 | expect(expensiveDavRequestArea("/addressbooks/default/")).toBe("addressbooks"); |
| 17 | expect(expensiveDavRequestArea("/principals/me/")).toBe("principals"); |
| 18 | expect(expensiveDavRequestArea("/")).toBe(""); |
| 19 | }); |
| 20 | |
| 21 | it("classifies REPORT and Depth infinity PROPFIND as expensive DAV requests", () => { |
| 22 | expect(isExpensiveDavRequest(new Request("https://dav.example.com/calendars/", { method: "REPORT" }))).toBe(true); |
| 23 | expect( |
| 24 | isExpensiveDavRequest( |
| 25 | new Request("https://dav.example.com/files/", { method: "PROPFIND", headers: { depth: "infinity" } }), |
| 26 | ), |
| 27 | ).toBe(true); |
| 28 | expect( |
| 29 | isExpensiveDavRequest( |
| 30 | new Request("https://dav.example.com/files/", { method: "PROPFIND", headers: { depth: "1" } }), |
| 31 | ), |
| 32 | ).toBe(false); |
| 33 | }); |
| 34 | }); |