Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110import assert from "node:assert/strict";import { test } from "node:test";import { unstable_dev } from "wrangler";import { customerBindings } from "./fixtures/config.mjs";
test( "production Worker renders the shell, assets, and missing routes", { timeout: 60_000 }, async () => { const worker = await unstable_dev("dist/release/worker/index.js", { config: "dist/release/deployment.json", vars: customerBindings, local: true, ip: "127.0.0.1", port: 0, inspectorPort: 0, persist: false, logLevel: "error", experimental: { disableExperimentalWarning: true, watch: false }, });
try { const response = await worker.fetch("/"); assert.equal(response.status, 200); assert.match(response.headers.get("content-type"), /text\/html/); const html = await response.text(); assert.match(html, /class="[^"]*\bshell-brand\b[^"]*"/); assert.match(html, /href="\/tasks"/); assert.doesNotMatch(html, /Something went wrong!/); assert.ok(!html.includes(customerBindings.FLAREBOT_SESSION_SECRET));
// Public assets can render on the local test host, but that does not // approve it as a login or private API origin. for (const path of ["/auth/login", "/api/domain", "/api"]) assert.equal((await worker.fetch(path)).status, 403, path);
const assets = [ ...html.matchAll(/(?:src|href)="(\/assets\/[^"\s]+\.(?:js|css))"/g), ]; assert.ok( assets.some(([, path]) => path.endsWith(".js")), "client JavaScript is linked", ); assert.ok( assets.some(([, path]) => path.endsWith(".css")), "Kumo styles are linked", ); for (const [, path] of assets) { const asset = await worker.fetch(path); assert.equal(asset.status, 200, path); assert.match( asset.headers.get("content-type"), path.endsWith(".css") ? /text\/css/ : /javascript/, ); assert.ok( !(await asset.text()).includes( customerBindings.FLAREBOT_SESSION_SECRET, ), ); }
const legacy = await worker.fetch("/agents", { redirect: "manual" }); assert.ok(legacy.status >= 300 && legacy.status < 400); assert.equal( new URL(legacy.headers.get("location"), "https://example.test") .pathname, "/", );
const missing = await worker.fetch("/not-a-flarebot-route"); assert.equal(missing.status, 404); assert.match(await missing.text(), /There is nothing at this address/); } finally { await worker.stop(); } },);
test( "unconfigured packaged Worker fails before serving the application", { timeout: 60_000 }, async () => { const worker = await unstable_dev("dist/release/worker/index.js", { config: "dist/release/deployment.json", vars: { ...customerBindings, FLAREBOT_INSTALLATION: "invalid-secret-sentinel", }, local: true, ip: "127.0.0.1", port: 0, inspectorPort: 0, persist: false, logLevel: "error", experimental: { disableExperimentalWarning: true, watch: false }, }); try { const response = await worker.fetch("/"); assert.equal(response.status, 503); assert.equal(response.headers.get("cache-control"), "no-store"); assert.doesNotMatch( await response.text(), /invalid-secret-sentinel|shell-brand/, ); } finally { await worker.stop(); } },);