mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-02 01:20:20 +00:00
fix(line): synthesize media/auth/routing webhook regressions (openclaw#32546) thanks @Takhoffman
Verified: - pnpm build - pnpm check - pnpm test:macmini Co-authored-by: Takhoffman <781889+Takhoffman@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
@@ -69,6 +69,23 @@ describe("createLineNodeWebhookHandler", () => {
|
||||
expect(res.body).toBe("OK");
|
||||
});
|
||||
|
||||
it("returns 204 for HEAD", async () => {
|
||||
const bot = { handleWebhook: vi.fn(async () => {}) };
|
||||
const runtime = { log: vi.fn(), error: vi.fn(), exit: vi.fn() };
|
||||
const handler = createLineNodeWebhookHandler({
|
||||
channelSecret: "secret",
|
||||
bot,
|
||||
runtime,
|
||||
readBody: async () => "",
|
||||
});
|
||||
|
||||
const { res } = createRes();
|
||||
await handler({ method: "HEAD", headers: {} } as unknown as IncomingMessage, res);
|
||||
|
||||
expect(res.statusCode).toBe(204);
|
||||
expect(res.body).toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns 200 for verification request (empty events, no signature)", async () => {
|
||||
const rawBody = JSON.stringify({ events: [] });
|
||||
const { bot, handler } = createPostWebhookTestHarness(rawBody);
|
||||
@@ -82,14 +99,14 @@ describe("createLineNodeWebhookHandler", () => {
|
||||
expect(bot.handleWebhook).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("returns 405 for non-GET/non-POST methods", async () => {
|
||||
it("returns 405 for non-GET/HEAD/POST methods", async () => {
|
||||
const { bot, handler } = createPostWebhookTestHarness(JSON.stringify({ events: [] }));
|
||||
|
||||
const { res, headers } = createRes();
|
||||
await handler({ method: "PUT", headers: {} } as unknown as IncomingMessage, res);
|
||||
|
||||
expect(res.statusCode).toBe(405);
|
||||
expect(headers.allow).toBe("GET, POST");
|
||||
expect(headers.allow).toBe("GET, HEAD, POST");
|
||||
expect(bot.handleWebhook).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -178,6 +195,32 @@ describe("createLineNodeWebhookHandler", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("returns 200 immediately and logs when event processing fails", async () => {
|
||||
const rawBody = JSON.stringify({ events: [{ type: "message" }] });
|
||||
const { secret } = createPostWebhookTestHarness(rawBody);
|
||||
const failingBot = {
|
||||
handleWebhook: vi.fn(async () => {
|
||||
throw new Error("transient failure");
|
||||
}),
|
||||
};
|
||||
const runtime = { log: vi.fn(), error: vi.fn(), exit: vi.fn() };
|
||||
const failingHandler = createLineNodeWebhookHandler({
|
||||
channelSecret: secret,
|
||||
bot: failingBot,
|
||||
runtime,
|
||||
readBody: async () => rawBody,
|
||||
});
|
||||
|
||||
const { res } = createRes();
|
||||
await runSignedPost({ handler: failingHandler, rawBody, secret, res });
|
||||
await Promise.resolve();
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.body).toBe(JSON.stringify({ status: "ok" }));
|
||||
expect(failingBot.handleWebhook).toHaveBeenCalledTimes(1);
|
||||
expect(runtime.error).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("returns 400 for invalid JSON payload even when signature is valid", async () => {
|
||||
const rawBody = "not json";
|
||||
const { bot, handler, secret } = createPostWebhookTestHarness(rawBody);
|
||||
|
||||
Reference in New Issue
Block a user