mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 00:00:23 +00:00
test: slim shared plugin runtime mock
This commit is contained in:
committed by
Peter Steinberger
parent
e9e7033ea1
commit
71b5a7c35b
@@ -31,6 +31,7 @@ import {
|
||||
const { TEST_WEBHOOK_RATE_LIMIT_MAX_REQUESTS } = vi.hoisted(() => ({
|
||||
TEST_WEBHOOK_RATE_LIMIT_MAX_REQUESTS: 3,
|
||||
}));
|
||||
const TEST_WEBHOOK_BODY_TIMEOUT_MS = 1;
|
||||
|
||||
// Mock dependencies
|
||||
vi.mock("./send.js", () => ({
|
||||
@@ -70,6 +71,11 @@ vi.mock("./webhook-ingress.js", async () => {
|
||||
...actual.WEBHOOK_RATE_LIMIT_DEFAULTS,
|
||||
maxRequests: TEST_WEBHOOK_RATE_LIMIT_MAX_REQUESTS,
|
||||
},
|
||||
readWebhookBodyOrReject: (params: Parameters<typeof actual.readWebhookBodyOrReject>[0]) =>
|
||||
actual.readWebhookBodyOrReject({
|
||||
...params,
|
||||
timeoutMs: TEST_WEBHOOK_BODY_TIMEOUT_MS,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -368,25 +374,17 @@ describe("BlueBubbles webhook monitor", () => {
|
||||
});
|
||||
|
||||
it("returns 408 when request body times out (Slow-Loris protection)", async () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
setupWebhookTarget();
|
||||
setupWebhookTarget();
|
||||
|
||||
// Create a request that never sends data or ends (simulates slow-loris)
|
||||
const { req, destroyMock } = createHangingWebhookRequestForTest();
|
||||
// Create a request that never sends data or ends (simulates slow-loris).
|
||||
const { req, destroyMock } = createHangingWebhookRequestForTest();
|
||||
|
||||
const { res, handledPromise } = createWebhookDispatchForTest(req);
|
||||
const { res, handledPromise } = createWebhookDispatchForTest(req);
|
||||
|
||||
// Advance past the 30s timeout
|
||||
await vi.advanceTimersByTimeAsync(31_000);
|
||||
|
||||
const handled = await handledPromise;
|
||||
expect(handled).toBe(true);
|
||||
expect(res.statusCode).toBe(408);
|
||||
expect(destroyMock).toHaveBeenCalled();
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
const handled = await handledPromise;
|
||||
expect(handled).toBe(true);
|
||||
expect(res.statusCode).toBe(408);
|
||||
expect(destroyMock).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("rejects unauthorized requests before reading the body", async () => {
|
||||
|
||||
Reference in New Issue
Block a user