Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeChampion committed Nov 21, 2024
1 parent 792e3ff commit b7a9108
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Binary file modified pkg/csp_nonce_html_transformer_bg.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export async function csp(originalResponse: Response, params?: Params) {
}

const querySelectors = ["script", 'link[rel="preload"][as="script"]'];
await init()
await init();
return new HTMLRewriter()
.on(querySelectors.join(","), {
element(element: Element) {
Expand Down
22 changes: 11 additions & 11 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
assertMatch,
assertStrictEquals,
} from "https://deno.land/std@0.224.0/assert/mod.ts";
import { csp, init } from "../src/index.ts";
import { csp } from "../src/index.ts";

import * as cheerio from "https://cdn.jsdelivr.net/npm/cheerio/+esm";

Expand All @@ -17,7 +17,7 @@ Deno.test({
fn: async () => {
let response = await fetch("https://html.spec.whatwg.org/");
response = new Response(response.body, response);
await init();

const result = await csp(response);
const policy: Map<string, string[]> = parseContentSecurityPolicy(
result.headers.get("content-security-policy")!,
Expand Down Expand Up @@ -46,7 +46,7 @@ Deno.test({
const response = new Response("meow", {
headers: { "content-type": "text/plain" },
});
await init();

const result = await csp(response);
assertStrictEquals(response, result);
assertEquals(result.headers.has("content-security-policy"), false);
Expand Down Expand Up @@ -133,7 +133,7 @@ Deno.test({
},
);
const originBody = await response.clone().arrayBuffer();
await init();

const result = await csp(response);
assertEquals(originBody, await result.arrayBuffer());
},
Expand All @@ -149,7 +149,7 @@ Deno.test({
},
},
);
await init();

const result = await csp(response);
const policy: Map<string, string[]> = parseContentSecurityPolicy(
result.headers.get("content-security-policy")!,
Expand Down Expand Up @@ -181,7 +181,7 @@ Deno.test({
"img-src 'self' blob: data:; script-src 'strict-dynamic' 'sha256-/Cb4VxgL2aVP0MVDvbP0DgEOUv+MeNQmZX4yXHkn/c0='",
},
});
await init();

const result = await csp(response);
const policy: Map<string, string[]> = parseContentSecurityPolicy(
result.headers.get("content-security-policy") || "",
Expand Down Expand Up @@ -209,7 +209,7 @@ Deno.test({
"img-src 'self' blob: data:; script-src 'sha256-/Cb4VxgL2aVP0MVDvbP0DgEOUv+MeNQmZX4yXHkn/c0='",
},
});
await init();

const result = await csp(response, { distribution: "0" });
assertStrictEquals(
result.headers.get("content-security-policy")!,
Expand All @@ -233,7 +233,7 @@ Deno.test({
"img-src 'self' blob: data:; script-src 'sha256-/Cb4VxgL2aVP0MVDvbP0DgEOUv+MeNQmZX4yXHkn/c0='",
},
});
await init();

const result = await csp(response, { distribution: "0%" });
assertStrictEquals(
result.headers.get("content-security-policy")!,
Expand All @@ -255,7 +255,7 @@ Deno.test({
"content-type": "text/html; charset=utf-8",
},
});
await init();

const result = await csp(response, { reportOnly: true });
assertMatch(
result.headers.get("content-security-policy-report-only")!,
Expand All @@ -273,7 +273,7 @@ Deno.test({
"content-type": "text/html; charset=utf-8",
},
});
await init();

const result = await csp(response, { unsafeEval: true });
assertMatch(
result.headers.get("content-security-policy")!,
Expand All @@ -291,7 +291,7 @@ Deno.test({
"content-type": "text/html; charset=utf-8",
},
});
await init();

const result = await csp(response, { reportUri: "https://example.com" });
assertMatch(
result.headers.get("content-security-policy")!,
Expand Down

0 comments on commit b7a9108

Please sign in to comment.