From 4d7514c60bdf1fa0706732134dd04b9672308a2f Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 12 Aug 2026 03:41:55 -0700 Subject: [PATCH] test(gateway): provide control UI request hosts --- src/gateway/control-ui.auto-root.http.test.ts | 6 ++- src/gateway/control-ui.http.test.ts | 40 +++++++++++++------ src/gateway/gateway-misc.test.ts | 6 ++- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/gateway/control-ui.auto-root.http.test.ts b/src/gateway/control-ui.auto-root.http.test.ts index 617feef2e804..d0c7270176f6 100644 --- a/src/gateway/control-ui.auto-root.http.test.ts +++ b/src/gateway/control-ui.auto-root.http.test.ts @@ -53,7 +53,11 @@ describe("handleControlUiHttpRequest prepared root lifecycle", () => { await fs.link(sourceIndex, indexPath); const { res, end } = makeMockHttpResponse(); const handled = await handleControlUiHttpRequest( - { url: "/dashboard", method: "GET" } as IncomingMessage, + { + url: "/dashboard", + method: "GET", + headers: { host: "gateway.example.test" }, + } as IncomingMessage, res, { root: { kind: "bundled", path: tmp, realPath: await fs.realpath(tmp) } }, ); diff --git a/src/gateway/control-ui.http.test.ts b/src/gateway/control-ui.http.test.ts index ce875306c7d6..9c36b382b0c6 100644 --- a/src/gateway/control-ui.http.test.ts +++ b/src/gateway/control-ui.http.test.ts @@ -529,7 +529,7 @@ describe("handleControlUiHttpRequest", () => { fn: async (tmp) => { const { res, end, setHeader } = makeMockHttpResponse(); const handled = await handleControlUiHttpRequest( - { url: "/", method: "GET" } as IncomingMessage, + { url: "/", method: "GET", headers: { host: "gateway.example.test" } } as IncomingMessage, res, { root: { kind: "resolved", path: tmp }, @@ -563,7 +563,7 @@ describe("handleControlUiHttpRequest", () => { fn: async (tmp) => { const { res, end, setHeader } = makeMockHttpResponse(); const handled = await handleControlUiHttpRequest( - { url: "/", method: "GET" } as IncomingMessage, + { url: "/", method: "GET", headers: { host: "gateway.example.test" } } as IncomingMessage, res, { root: { kind: "resolved", path: tmp }, @@ -584,11 +584,15 @@ describe("handleControlUiHttpRequest", () => { await withControlUiRoot({ fn: async (tmp) => { const { res, end, setHeader } = makeMockHttpResponse(); - await handleControlUiHttpRequest({ url: "/", method: "GET" } as IncomingMessage, res, { - root: { kind: "resolved", path: tmp }, - config: { gateway: { terminal: { enabled: true } } }, - terminalEnabled: false, - }); + await handleControlUiHttpRequest( + { url: "/", method: "GET", headers: { host: "gateway.example.test" } } as IncomingMessage, + res, + { + root: { kind: "resolved", path: tmp }, + config: { gateway: { terminal: { enabled: true } } }, + terminalEnabled: false, + }, + ); const csp = setHeader.mock.calls.findLast( (call) => call[0] === "Content-Security-Policy", )?.[1]; @@ -1484,9 +1488,11 @@ describe("handleControlUiHttpRequest", () => { indexHtml: html, fn: async (tmp) => { const { res, setHeader } = makeMockHttpResponse(); - await handleControlUiHttpRequest({ url: "/", method: "GET" } as IncomingMessage, res, { - root: { kind: "resolved", path: tmp }, - }); + await handleControlUiHttpRequest( + { url: "/", method: "GET", headers: { host: "gateway.example.test" } } as IncomingMessage, + res, + { root: { kind: "resolved", path: tmp } }, + ); const cspCalls = setHeader.mock.calls.filter( (call) => call[0] === "Content-Security-Policy", ); @@ -1504,7 +1510,7 @@ describe("handleControlUiHttpRequest", () => { fn: async (tmp) => { const { res, end } = makeMockHttpResponse(); const handled = await handleControlUiHttpRequest( - { url: "/", method: "GET" } as IncomingMessage, + { url: "/", method: "GET", headers: { host: "gateway.example.test" } } as IncomingMessage, res, { root: { kind: "resolved", path: tmp }, @@ -1530,7 +1536,11 @@ describe("handleControlUiHttpRequest", () => { fn: async (tmp) => { const { res, end } = makeMockHttpResponse(); const handled = await handleControlUiHttpRequest( - { url: "/openclaw/chat", method: "GET" } as IncomingMessage, + { + url: "/openclaw/chat", + method: "GET", + headers: { host: "gateway.example.test" }, + } as IncomingMessage, res, { basePath: "/openclaw", @@ -1578,7 +1588,11 @@ describe("handleControlUiHttpRequest", () => { fn: async (tmp) => { const { res, end } = makeMockHttpResponse(); const handled = await handleControlUiHttpRequest( - { url: requestPath, method: "GET" } as IncomingMessage, + { + url: requestPath, + method: "GET", + headers: { host: "gateway.example.test" }, + } as IncomingMessage, res, { ...(basePath ? { basePath } : {}), diff --git a/src/gateway/gateway-misc.test.ts b/src/gateway/gateway-misc.test.ts index 322141ed7315..8dc265a6183f 100644 --- a/src/gateway/gateway-misc.test.ts +++ b/src/gateway/gateway-misc.test.ts @@ -110,7 +110,11 @@ describe("GatewayClient", () => { ) { const { res } = makeControlUiResponse(); const handled = await handleControlUiHttpRequest( - { url: params.url, method: params.method ?? "GET" } as IncomingMessage, + { + url: params.url, + method: params.method ?? "GET", + headers: { host: "gateway.example.test" }, + } as IncomingMessage, res, { root: { kind: "resolved", path: tmp } }, );