diff options
Diffstat (limited to 'test/cdp/endpoint-test.ts')
| -rw-r--r-- | test/cdp/endpoint-test.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/cdp/endpoint-test.ts b/test/cdp/endpoint-test.ts index 57d6088..ee8f692 100644 --- a/test/cdp/endpoint-test.ts +++ b/test/cdp/endpoint-test.ts @@ -13,8 +13,10 @@ import { DEFAULT_REMOTE_CDP, describeCdpTarget, isValidTargetValue, + redactWsUrl, resolveCdpTarget, } from "../../src/cdp/endpoint"; +import { getBrowserSystemPrompt } from "../../src/prompt"; let passed = 0; let failed = 0; @@ -150,6 +152,50 @@ function main(): void { check(!isValidTargetValue("default"), "E13: \"default\" is handled as clear, not stored verbatim"); } + // E14: upstream's BU_CDP_WS is read by discoverEndpoint() before anything the + // fork resolves, so it must outrank BU_CDP_HTTP and the stored choice here + // too — otherwise status, /browser-target and the prompt name a browser the + // daemon is not driving. + { + const pinned = "ws://10.0.0.7:9229/devtools/browser/0b5c-uuid"; + const t = resolveCdpTarget({ BU_CDP_WS: pinned, BU_CDP_HTTP: "10.0.0.9:9333" }, "10.0.0.8:9444"); + check(t.kind === "remote", "E14: BU_CDP_WS resolves to a remote target"); + if (t.kind === "remote") { + check(t.host === "10.0.0.7" && t.port === 9229, "E14: it wins over BU_CDP_HTTP and the stored choice"); + check(t.source === "ws", "E14: it is marked as the pinned WebSocket"); + } + const blank = resolveCdpTarget({ BU_CDP_WS: " ", BU_CDP_HTTP: "10.0.0.9:9333" }); + check(blank.kind === "remote" && blank.source === "env", "E14: a blank BU_CDP_WS is ignored, as upstream does"); + } + + // E15: only host:port is ever shown. The path carries the browser id and a + // proxied endpoint may carry a token or credentials. + { + const secret = "wss://user:hunter2@cdp.example.com/devtools/browser/abc?token=s3cr3t"; + const t = resolveCdpTarget({ BU_CDP_WS: secret }); + const shown = describeCdpTarget(t); + check(t.kind === "remote" && t.port === 443, "E15: wss without a port means 443"); + check(shown.startsWith("cdp.example.com:443 (BU_CDP_WS"), `E15: described as host:port — got ${shown}`); + check(!/hunter2|user|abc|token|s3cr3t|devtools/.test(shown), "E15: no path, query or credentials leak"); + check(redactWsUrl(secret) === "cdp.example.com:443", "E15: redactWsUrl keeps host:port only"); + check(redactWsUrl("ws://[::1]:9222/x") === "::1:9222", "E15: IPv6 hosts lose their brackets like elsewhere"); + } + + // E16: an unusable BU_CDP_WS is reported, still without echoing it. + for (const bad of ["not a url", "http://10.0.0.7:9229/devtools/browser/x"]) { + const t = resolveCdpTarget({ BU_CDP_WS: bad }); + check(t.kind === "invalid" && t.source === "ws", `E16: "${bad}" is reported as an invalid BU_CDP_WS`); + check(!describeCdpTarget(t).includes("devtools"), "E16: the invalid value is not echoed"); + } + + // E17: the system prompt names the pinned endpoint, redacted. + { + const t = resolveCdpTarget({ BU_CDP_WS: "ws://10.0.0.7:9229/devtools/browser/0b5c-uuid" }); + const prompt = getBrowserSystemPrompt(true, t); + check(prompt.includes("10.0.0.7:9229"), "E17: the prompt names the pinned host:port"); + check(!prompt.includes("0b5c-uuid"), "E17: the prompt does not carry the browser id"); + } + console.log(`\n${passed} passed, ${failed} failed`); if (failed > 0) process.exit(1); } |
