From 53ddcb1d27e68b7489194d33f03ace2334a683c4 Mon Sep 17 00:00:00 2001 From: bbassie <17990055+bbassie@users.noreply.github.com> Date: Sat, 21 Nov 2026 23:57:09 +0000 Subject: [PATCH] Test cluster name escaping and favicon_url in serveWeb Co-Authored-By: Claude Opus 5.5 --- test/controller/Controller.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/test/controller/Controller.js b/test/controller/Controller.js index d63d0605..7ee5915a 100644 --- a/test/controller/Controller.js +++ b/test/controller/Controller.js @@ -369,9 +369,10 @@ describe("controller/src/Controller", function() { describe(".serveWeb()", function() { let server, port; + const config = new Map([["controller.name", "Test Cluster"], ["controller.favicon_url", null]]); before(async function() { const app = express(); - app.locals.controller = { config: { get: () => "Test Cluster" } }; + app.locals.controller = { config: { get: field => config.get(field) } }; app.locals.webBundle = { main: "static/main.abc.js", imports: { "react": "static/shared-react.abc.js" }, @@ -405,6 +406,33 @@ describe("controller/src/Controller", function() { assert(html.includes("src=\"../../../static/main.abc.js\"")); assert(html.includes("new URL(\"../../../static/\", document.location)")); }); + it("should escape the cluster name", async function() { + config.set("controller.name", "A&B \"\""); + try { + const html = await (await fetch(`http://localhost:${port}/`)).text(); + assert(html.includes("A&B "<x>"")); + assert(html.includes('')); + } finally { + config.set("controller.name", "Test Cluster"); + } + }); + it("should link favicon_url relative to the web root", async function() { + let html = await (await fetch(`http://localhost:${port}/`)).text(); + assert(!html.includes("rel=\"icon\"")); + try { + config.set("controller.favicon_url", "static/icon.png"); + html = await (await fetch(`http://localhost:${port}/instances/1/view`)).text(); + assert(html.includes('')); + config.set("controller.favicon_url", "https://example.com/icon.png?a=1&b=2"); + html = await (await fetch(`http://localhost:${port}/instances/1/view`)).text(); + assert(html.includes('')); + config.set("controller.favicon_url", "/icon.png"); + html = await (await fetch(`http://localhost:${port}/instances/1/view`)).text(); + assert(html.includes('')); + } finally { + config.set("controller.favicon_url", null); + } + }); }); describe(".parseTrustedProxies()", function() { it("should parse addresses", function() {