mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
test(gateway): provide control UI request hosts
This commit is contained in:
@@ -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) } },
|
||||
);
|
||||
|
||||
@@ -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 } : {}),
|
||||
|
||||
@@ -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 } },
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user