Archived
fix: log all webhook host requests
This commit is contained in:
@@ -6,7 +6,11 @@ import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import test from "node:test";
|
||||
import { AgentStore } from "../../adapters/database/store.js";
|
||||
import { handleHttp } from "../../application/controller/server.js";
|
||||
import {
|
||||
type HttpRequestLog,
|
||||
handleHttp,
|
||||
observeHttpRequest,
|
||||
} from "../../application/controller/server.js";
|
||||
|
||||
test("signed webhooks are durably admitted before acknowledgment", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "agent-http-"));
|
||||
@@ -62,7 +66,9 @@ test("signed webhooks are durably admitted before acknowledgment", async () => {
|
||||
test("invalid webhook signatures are rejected without persistence", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "agent-http-auth-"));
|
||||
const store = new AgentStore(join(root, "agent.db"));
|
||||
const requests: HttpRequestLog[] = [];
|
||||
const server = createServer((request, response) => {
|
||||
observeHttpRequest(request, response, (entry) => requests.push(entry));
|
||||
handleHttp(request, response, {
|
||||
store,
|
||||
webhookSecret: "test-secret",
|
||||
@@ -97,6 +103,22 @@ test("invalid webhook signatures are rejected without persistence", async () =>
|
||||
);
|
||||
assert.equal(response.status, 401);
|
||||
assert.equal(store.leaseDelivery(), undefined);
|
||||
assert.equal(requests.length, 1);
|
||||
assert.deepEqual(
|
||||
{
|
||||
method: requests[0]?.method,
|
||||
path: requests[0]?.path,
|
||||
statusCode: requests[0]?.statusCode,
|
||||
completed: requests[0]?.completed,
|
||||
},
|
||||
{
|
||||
method: "POST",
|
||||
path: "/webhooks/gitea",
|
||||
statusCode: 401,
|
||||
completed: true,
|
||||
},
|
||||
);
|
||||
assert.ok((requests[0]?.durationMs ?? -1) >= 0);
|
||||
} finally {
|
||||
await new Promise<void>((resolve) => server.close(() => resolve()));
|
||||
store.close();
|
||||
|
||||
Reference in New Issue
Block a user