fix(notify): open configured web run pages from ntfy
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// Real authenticated proxy, private fixture credentials, no live server/ntfy.
|
||||
import assert from "node:assert/strict";
|
||||
import { spawn } from "node:child_process";
|
||||
import { mkdtemp, writeFile, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join, resolve } from "node:path";
|
||||
import net from "node:net";
|
||||
import { eventually } from "./browser.mjs";
|
||||
|
||||
const scratch = await mkdtemp(join(process.argv[2] ?? tmpdir(), "notification-web-link-"));
|
||||
const auth = join(scratch, "auth.json");
|
||||
await writeFile(auth, JSON.stringify({ password: "fixture-password-only", secret: "fixture-secret-not-real-credentials-123456789" }), { mode: 0o600 });
|
||||
const port = await new Promise(resolve => { const s = net.createServer(); s.listen(0, "127.0.0.1", () => { const p = s.address().port; s.close(() => resolve(p)); }); });
|
||||
const child = spawn(process.execPath, ["web/serve.mjs", "--host", "127.0.0.1", "--port", String(port), "--pipelines", "127.0.0.1:1"], {
|
||||
cwd: resolve(import.meta.dirname, "../.."), env: { ...process.env, PIPELINES_WEB_AUTH: "required", PIPELINES_WEB_AUTH_FILE: auth }, stdio: "ignore",
|
||||
});
|
||||
const origin = `http://127.0.0.1:${port}`;
|
||||
try {
|
||||
await eventually(async () => { try { return (await fetch(origin + "/login")).ok; } catch { return false; } }, { timeout: 8000 });
|
||||
const target = "/runs/20";
|
||||
const gated = await fetch(origin + target, { headers: { Accept: "text/html" }, redirect: "manual" });
|
||||
assert.equal(gated.status, 302);
|
||||
const login = new URL(gated.headers.get("location"), origin);
|
||||
assert.equal(login.pathname, "/login"); assert.equal(login.searchParams.get("next"), target);
|
||||
assert.match(await (await fetch(login)).text(), /name="next" value="\/runs\/20"/);
|
||||
const denied = await fetch(origin + "/login", { method: "POST", body: new URLSearchParams({ password: "wrong", next: target }), redirect: "manual" });
|
||||
assert.equal(denied.status, 401);
|
||||
const signed = await fetch(origin + "/login", { method: "POST", body: new URLSearchParams({ password: "fixture-password-only", next: target }), redirect: "manual" });
|
||||
assert.equal(signed.status, 303); assert.equal(signed.headers.get("location"), target);
|
||||
const cookie = signed.headers.get("set-cookie").split(";")[0];
|
||||
const run = await fetch(origin + target, { headers: { cookie }, redirect: "manual" });
|
||||
assert.equal(run.status, 200); assert.match(run.headers.get("content-type"), /text\/html/);
|
||||
console.log("PASS: notification web run link remains authenticated and returns to the exact run after login; no notification or provider calls.");
|
||||
} finally {
|
||||
if (child.exitCode === null && child.signalCode === null) {
|
||||
const exited = new Promise(resolve => child.once("exit", resolve)); child.kill("SIGTERM"); await exited;
|
||||
}
|
||||
await rm(scratch, { recursive: true, force: true });
|
||||
}
|
||||
Reference in New Issue
Block a user