mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
refactor: share plugin http auth request assertions
This commit is contained in:
@@ -158,6 +158,16 @@ function createRuntimeScopeRecorderHandler(params: {
|
||||
});
|
||||
}
|
||||
|
||||
async function expectPluginRequestOk(
|
||||
server: Parameters<typeof dispatchRequest>[0],
|
||||
request: Parameters<typeof createRequest>[0],
|
||||
): Promise<void> {
|
||||
const response = createResponse();
|
||||
await dispatchRequest(server, createRequest(request), response.res);
|
||||
expect(response.res.statusCode).toBe(200);
|
||||
expect(response.getBody()).toBe("ok");
|
||||
}
|
||||
|
||||
describe("gateway plugin HTTP auth boundary", () => {
|
||||
test("applies default security headers and optional strict transport security", async () => {
|
||||
await withGatewayTempConfig("openclaw-plugin-http-security-headers-test-", async () => {
|
||||
@@ -319,23 +329,15 @@ describe("gateway plugin HTTP auth boundary", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const response = createResponse();
|
||||
await dispatchRequest(
|
||||
server,
|
||||
createRequest({
|
||||
path: "/secure-hook",
|
||||
remoteAddress: "203.0.113.10",
|
||||
headers: {
|
||||
"x-forwarded-user": "operator",
|
||||
"x-forwarded-for": "198.51.100.20",
|
||||
"x-openclaw-scopes": "operator.read",
|
||||
},
|
||||
}),
|
||||
response.res,
|
||||
);
|
||||
|
||||
expect(response.res.statusCode).toBe(200);
|
||||
expect(response.getBody()).toBe("ok");
|
||||
await expectPluginRequestOk(server, {
|
||||
path: "/secure-hook",
|
||||
remoteAddress: "203.0.113.10",
|
||||
headers: {
|
||||
"x-forwarded-user": "operator",
|
||||
"x-forwarded-for": "198.51.100.20",
|
||||
"x-openclaw-scopes": "operator.read",
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -362,21 +364,13 @@ describe("gateway plugin HTTP auth boundary", () => {
|
||||
shouldEnforcePluginGatewayAuth: (pathContext) => pathContext.pathname === "/secure-hook",
|
||||
},
|
||||
run: async (server) => {
|
||||
const response = createResponse();
|
||||
await dispatchRequest(
|
||||
server,
|
||||
createRequest({
|
||||
path: "/secure-hook",
|
||||
authorization: "Bearer test-token",
|
||||
headers: {
|
||||
"x-openclaw-scopes": "operator.read",
|
||||
},
|
||||
}),
|
||||
response.res,
|
||||
);
|
||||
|
||||
expect(response.res.statusCode).toBe(200);
|
||||
expect(response.getBody()).toBe("ok");
|
||||
await expectPluginRequestOk(server, {
|
||||
path: "/secure-hook",
|
||||
authorization: "Bearer test-token",
|
||||
headers: {
|
||||
"x-openclaw-scopes": "operator.read",
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -405,18 +399,10 @@ describe("gateway plugin HTTP auth boundary", () => {
|
||||
pathContext.pathname === "/secure-admin-hook",
|
||||
},
|
||||
run: async (server) => {
|
||||
const response = createResponse();
|
||||
await dispatchRequest(
|
||||
server,
|
||||
createRequest({
|
||||
path: "/secure-admin-hook",
|
||||
authorization: "Bearer test-token",
|
||||
}),
|
||||
response.res,
|
||||
);
|
||||
|
||||
expect(response.res.statusCode).toBe(200);
|
||||
expect(response.getBody()).toBe("ok");
|
||||
await expectPluginRequestOk(server, {
|
||||
path: "/secure-admin-hook",
|
||||
authorization: "Bearer test-token",
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user