diff --git a/.github/workflows/www.yml b/.github/workflows/www.yml index 1709666a..e1f006f5 100644 --- a/.github/workflows/www.yml +++ b/.github/workflows/www.yml @@ -30,3 +30,7 @@ jobs: - name: Type check website run: deno check main.ts dev.ts working-directory: www/ + + - name: Run tests + run: deno test -A + working-directory: www/ diff --git a/deno.json b/deno.json index f366d5bc..9adebb45 100644 --- a/deno.json +++ b/deno.json @@ -9,5 +9,10 @@ "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" + }, + "test": { + "files": { + "exclude": ["www/"] + } } } diff --git a/www/main_test.ts b/www/main_test.ts new file mode 100644 index 00000000..98db2d11 --- /dev/null +++ b/www/main_test.ts @@ -0,0 +1,37 @@ +import { assertEquals } from "$std/testing/asserts.ts"; +import { TextLineStream } from "$std/streams/delimiter.ts"; + +Deno.test("CORS should not set on GET /fresh-badge.svg", { + sanitizeResources: false, +}, async () => { + const serverProcess = Deno.run({ + cmd: ["deno", "run", "-A", "./main.ts"], + stdin: "null", + stdout: "piped", + stderr: "inherit", + }); + const decoder = new TextDecoderStream(); + const lines = serverProcess.stdout.readable + .pipeThrough(decoder) + .pipeThrough(new TextLineStream()); + + let started = false; + for await (const line of lines) { + if (line.includes("Listening on http://")) { + started = true; + break; + } + } + if (!started) { + throw new Error("Server didn't start up"); + } + + const res = await fetch("http://localhost:8000/fresh-badge.svg"); + await res.body?.cancel(); + + assertEquals(res.headers.get("cross-origin-resource-policy"), null); + + await lines.cancel(); + serverProcess.kill("SIGTERM"); + serverProcess.close(); +}); diff --git a/www/routes/_middleware.ts b/www/routes/_middleware.ts index 259503a4..c813f053 100644 --- a/www/routes/_middleware.ts +++ b/www/routes/_middleware.ts @@ -76,15 +76,6 @@ export async function handler( try { const resp = await ctx.next(); const headers = new Headers(resp.headers); - headers.set( - "Strict-Transport-Security", - "max-age=63072000; includeSubDomains; preload", - ); - headers.set("X-Content-Type-Options", "nosniff"); - headers.set("X-Frame-Options", "DENY"); - headers.set("Cross-Origin-Resource-Policy", "same-origin"); - headers.set("Cross-Origin-Opener-Policy", "same-origin"); - headers.set("Cross-Origin-Embedder-Policy", "same-origin"); res = new Response(resp.body, { status: resp.status, headers }); return res; } catch (e) {