mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 16:13:12 +09:00
Test cluster name escaping and favicon_url in serveWeb
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
555f444447
commit
53ddcb1d27
1 file changed
+29
-1
@@ -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 \"<x>\"");
|
||||
try {
|
||||
const html = await (await fetch(`http://localhost:${port}/`)).text();
|
||||
assert(html.includes("<title>A&B "<x>"</title>"));
|
||||
assert(html.includes('<meta name="application-name" content="A&B "<x>"" />'));
|
||||
} 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('<link rel="icon" href="../../static/icon.png" />'));
|
||||
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('<link rel="icon" href="https://example.com/icon.png?a=1&b=2" />'));
|
||||
config.set("controller.favicon_url", "/icon.png");
|
||||
html = await (await fetch(`http://localhost:${port}/instances/1/view`)).text();
|
||||
assert(html.includes('<link rel="icon" href="/icon.png" />'));
|
||||
} finally {
|
||||
config.set("controller.favicon_url", null);
|
||||
}
|
||||
});
|
||||
});
|
||||
describe(".parseTrustedProxies()", function() {
|
||||
it("should parse addresses", function() {
|
||||
|
||||
Reference in new issue
Block a user