Skip to content

Commit 1a35f58

Browse files
committed
test: 新增有效簽名請求的測試案例
1 parent 3ec2045 commit 1a35f58

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

test/router.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { beforeEach, describe, expect, it, vi } from "vitest";
22
import { router } from "../src/router";
3+
import { hmacSHA256Base64 } from "../src/utils/hmacSHA256Base64";
34

45
const mockEnv = {
56
LINE_CHANNEL_SECRET: { get: vi.fn() },
@@ -49,4 +50,19 @@ describe("router", () => {
4950
expect(response.status).toBe(500);
5051
expect(await response.text()).toBe("Server misconfigured");
5152
});
53+
54+
it("returns 200 for a valid signed request", async () => {
55+
const rawBody = JSON.stringify({ destination: "", events: [] });
56+
const signature = await hmacSHA256Base64("secret", rawBody);
57+
const request = new Request("https://example.com", {
58+
method: "POST",
59+
headers: { "x-line-signature": signature },
60+
body: rawBody,
61+
});
62+
63+
const response = await router(request, mockEnv as any, {} as any);
64+
65+
expect(response.status).toBe(200);
66+
expect(await response.text()).toBe("OK");
67+
});
5268
});

0 commit comments

Comments
 (0)