Skip to content
File

Blob: tests/worker/protocol/dav/runtime.workers.test.ts

typescript46 lines
1import { describe, expect, it } from "vitest";
2 
3import { CAL_DAV_ALLOW } from "@/worker/caldav/handler";
4import { CARD_DAV_ALLOW } from "@/worker/carddav/handler";
5import { DAV_DISCOVERY_ALLOW } from "@/worker/dav/discovery";
6import { FILES_DAV_ALLOW } from "@/worker/webdav/constants";
7import { createDavFixture, davRequest } from "@tests/worker/helpers/dav";
8import { fetchWorker } from "@tests/worker/helpers/http";
9 
10describe("DAV runtime registry", () => {
11 it("keeps scoped OPTIONS and method-not-allowed Allow headers per area", async () => {
12 const calOnly = await createDavFixture(["caldav.readonly"]);
13 const calOptions = await fetchWorker(davRequest(calOnly, "/calendars/", { method: "OPTIONS" }));
14 expect(calOptions.status).toBe(204);
15 expect(calOptions.headers.get("allow")).toBe(CAL_DAV_ALLOW);
16 
17 const filesOptions = await fetchWorker(davRequest(calOnly, "/files/", { method: "OPTIONS" }));
18 expect(filesOptions.status).toBe(403);
19 
20 const full = await createDavFixture(["dav.full"]);
21 const filesPost = await fetchWorker(davRequest(full, "/files/", { method: "POST" }));
22 expect(filesPost.status).toBe(405);
23 expect(filesPost.headers.get("allow")).toBe(FILES_DAV_ALLOW);
24 
25 const calPost = await fetchWorker(davRequest(full, "/calendars/", { method: "POST" }));
26 expect(calPost.status).toBe(405);
27 expect(calPost.headers.get("allow")).toBe(CAL_DAV_ALLOW);
28 
29 const cardPost = await fetchWorker(davRequest(full, "/addressbooks/", { method: "POST" }));
30 expect(cardPost.status).toBe(405);
31 expect(cardPost.headers.get("allow")).toBe(CARD_DAV_ALLOW);
32 
33 const discoveryPost = await fetchWorker(davRequest(full, "/", { method: "POST" }));
34 expect(discoveryPost.status).toBe(405);
35 expect(discoveryPost.headers.get("allow")).toBe(DAV_DISCOVERY_ALLOW);
36 });
37 
38 it("leaves unknown subject-host DAV paths as not found", async () => {
39 const fixture = await createDavFixture(["dav.full"]);
40 const response = await fetchWorker(
41 davRequest(fixture, "/not-dav/", { method: "PROPFIND", headers: { depth: "infinity" } }),
42 );
43 expect(response.status).toBe(404);
44 });
45});