| | @@ -1,0 +1,64 @@ |
| 1 | +import { spawnSync } from "node:child_process"; |
| 2 | +import { describe, expect, it } from "vitest"; |
| 3 | + |
| 4 | +/** |
| 5 | + * scripts/deploy-log-notes.sh: what the GitHub sync repeats from a Diffinery Deploy job's log. A |
| 6 | + * step's log begins with its script, whose `echo "::warning::..."` lines are not warnings. |
| 7 | + */ |
| 8 | + |
| 9 | +const script = new URL("../../../../scripts/deploy-log-notes.sh", import.meta.url).pathname; |
| 10 | +const notes = (log: string) => { |
| 11 | + const r = spawnSync("bash", [script], { input: log, encoding: "utf8" }); |
| 12 | + expect(r.status).toBe(0); |
| 13 | + return r.stdout.split("\n").filter(Boolean); |
| 14 | +}; |
| 15 | + |
| 16 | +// The "Check sign-in pages" step of a deploy where Access is set up and Turnstile works. |
| 17 | +const step = (lines: string[]) => |
| 18 | + [ |
| 19 | + "2026-10-14T09:14:34.280Z ##[group]Run loc=$(curl -sS -o /dev/null -w '%{http_code} %{redirect_url}' https://$DIFFINERY_DOMAIN/auth/access)", |
| 20 | + "2026-10-14T09:14:34.281Z \u001b[36;1mloc=$(curl -sS -o /dev/null -w '%{http_code} %{redirect_url}' https://$DIFFINERY_DOMAIN/auth/access)\u001b[0m", |
| 21 | + '2026-10-14T09:14:34.281Z \u001b[36;1mecho "/auth/access -> $loc"\u001b[0m', |
| 22 | + '2026-10-14T09:14:34.282Z [[ "$loc" == 302\\ https://*.cloudflareaccess.com/* ]] || echo "::warning::/auth/access is not behind Cloudflare Access yet, so email recovery and first admin sign-in will not work"', |
| 23 | + "2026-10-14T09:14:34.286Z report=$(curl -sS -w '\\n%{http_code}' https://$DIFFINERY_DOMAIN/security/report)", |
| 24 | + '2026-10-14T09:14:34.286Z echo "/security/report shows Turnstile to people who aren\'t signed in"', |
| 25 | + '2026-10-14T09:14:34.286Z elif grep -q \'has no Turnstile configured\' <<<"$report"; then echo "::warning::/security/report has no Turnstile, so only people who are signed in can send security reports: the Worker lacks TURNSTILE_SITE_KEY or TURNSTILE_SECRET"', |
| 26 | + "2026-10-14T09:14:34.287Z ##[endgroup]", |
| 27 | + ...lines, |
| 28 | + ].join("\n"); |
| 29 | + |
| 30 | +describe("deploy log notes", () => { |
| 31 | + it("repeats what the deploy printed, not the warnings its scripts could print", () => { |
| 32 | + const log = [ |
| 33 | + '2026-10-14T09:14:07.959Z Turnstile widget "diffinery diffinery.com" exists: 0x4AAAAAAFWX2OQHwh_jT9_h', |
| 34 | + "2026-10-14T09:14:08.227Z TURNSTILE_SECRET goes with site key 0x4AAAAAAFWX2OQHwh_jT9_h", |
| 35 | + step([ |
| 36 | + "2026-10-14T09:14:34.500Z /auth/access -> 302 https://team.cloudflareaccess.com/cdn-cgi/access/login", |
| 37 | + "2026-10-14T09:14:34.730Z /security/report shows Turnstile to people who aren't signed in", |
| 38 | + ]), |
| 39 | + ].join("\n"); |
| 40 | + const out = notes(log); |
| 41 | + expect(out.filter((l) => l.startsWith("::warning::"))).toEqual([]); |
| 42 | + expect(out).toEqual([ |
| 43 | + ' deploy: 2026-10-14T09:14:07.959Z Turnstile widget "diffinery diffinery.com" exists: 0x4AAAAAAFWX2OQHwh_jT9_h', |
| 44 | + " deploy: 2026-10-14T09:14:08.227Z TURNSTILE_SECRET goes with site key 0x4AAAAAAFWX2OQHwh_jT9_h", |
| 45 | + " deploy: 2026-10-14T09:14:34.500Z /auth/access -> 302 https://team.cloudflareaccess.com/cdn-cgi/access/login", |
| 46 | + " deploy: 2026-10-14T09:14:34.730Z /security/report shows Turnstile to people who aren't signed in", |
| 47 | + ]); |
| 48 | + }); |
| 49 | + |
| 50 | + it("repeats the warnings the deploy raised", () => { |
| 51 | + const out = notes( |
| 52 | + step([ |
| 53 | + "2026-10-14T09:14:34.500Z /auth/access -> 200 ", |
| 54 | + "2026-10-14T09:14:34.501Z ##[warning]/auth/access is not behind Cloudflare Access yet, so email recovery and first admin sign-in will not work", |
| 55 | + "2026-10-14T09:14:34.730Z ::warning::/security/report has no Turnstile: it answered 503 without the form", |
| 56 | + ]), |
| 57 | + ); |
| 58 | + expect(out).toEqual([ |
| 59 | + "::warning::Diffinery Deploy: /auth/access is not behind Cloudflare Access yet, so email recovery and first admin sign-in will not work", |
| 60 | + "::warning::Diffinery Deploy: /security/report has no Turnstile: it answered 503 without the form", |
| 61 | + " deploy: 2026-10-14T09:14:34.500Z /auth/access -> 200 ", |
| 62 | + ]); |
| 63 | + }); |
| 64 | +}); |