404
", { status: 404, headers: { "Content-Type": "text/html" } }) }, MAC_RELEASES: { get: async (key: string) => object(key), head: async (key: string) => { const found = object(key); return found ? { size: found.size, httpEtag: found.httpEtag } : null; }, }, } as unknown as Env; } function get(path: string, method = "GET", e = env()) { return worker.fetch(new Request(`https://cottondb.com${path}`, { method }), e); } describe("Cotton for the Mac's update feed", () => { it("serves the published feed as XML with a short cache", async () => { const res = await get("/mac/cotton/appcast.xml"); expect(res.status).toBe(200); expect(res.headers.get("Content-Type")).toBe("application/xml; charset=utf-8"); expect(res.headers.get("Cache-Control")).toBe("public, max-age=300"); expect(await res.text()).toBe(FEED); }); it("says plainly that no feed is published, never with a page", async () => { const res = await get("/mac/cotton/appcast.xml", "GET", env({})); expect(res.status).toBe(404); expect(res.headers.get("Content-Type")).toBe("text/plain; charset=utf-8"); expect(await res.text()).toBe("cotton/appcast.xml is not published"); }); }); describe("Cotton for the Mac's builds", () => { it("serves a published zip with its length, immutable", async () => { const res = await get(`/mac/cotton/${ZIP}`); expect(res.status).toBe(200); expect(res.headers.get("Content-Type")).toBe("application/zip"); expect(res.headers.get("Content-Length")).toBe(String("zip bytes".length)); expect(res.headers.get("Cache-Control")).toBe("public, max-age=31536000, immutable"); }); it("answers HEAD without the bytes", async () => { const res = await get(`/mac/cotton/${ZIP}`, "HEAD"); expect(res.status).toBe(200); expect(res.headers.get("Content-Length")).toBe(String("zip bytes".length)); }); it("refuses names nobody publishes, and other methods", async () => { for (const path of ["/mac/cotton/", "/mac/cotton/../runner/x", "/mac/cotton/Cotton.zip", "/mac/cotton/cotton/appcast.xml"]) { const res = await get(path); expect(res.status, path).toBe(404); expect(res.headers.get("Content-Type"), path).toBe("text/plain; charset=utf-8"); } expect((await get(`/mac/cotton/${ZIP}`, "POST")).status).toBe(405); expect((await get("/mac/cotton/Cotton-0.4.1-5.zip")).status).toBe(404); }); });