test(gateway): provide control UI request hosts

This commit is contained in:
Peter Steinberger
2026-08-12 03:41:55 -07:00
parent 1b18bd7f5b
commit 4d7514c60b
3 changed files with 37 additions and 15 deletions
@@ -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) } },
);
+27 -13
View File
@@ -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 } : {}),
+5 -1
View File
@@ -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 } },
);