Initial git webhooks service
All checks were successful
check / check (push) Successful in 14s

This commit is contained in:
matamune 2026-05-12 21:06:22 +00:00
commit 0ba9b9f95c
Signed by: matamune
GPG key ID: 3BB8E7D3B968A324
17 changed files with 705 additions and 0 deletions

21
test/signatures.test.ts Normal file
View file

@ -0,0 +1,21 @@
import { describe, expect, test } from "bun:test";
import { hmacSha256Hex, verifyGithubSignature, verifyJojoSignature } from "../src/signatures";
describe("webhook signatures", () => {
test("verifies GitHub sha256 signatures", async () => {
const body = JSON.stringify({ ok: true });
const digest = await hmacSha256Hex("secret", body);
expect(await verifyGithubSignature("secret", body, `sha256=${digest}`)).toBe(true);
expect(await verifyGithubSignature("wrong", body, `sha256=${digest}`)).toBe(false);
});
test("verifies jojo Forgejo/Gitea signature headers", async () => {
const body = JSON.stringify({ ok: true });
const digest = await hmacSha256Hex("secret", body);
const headers = new Headers({ "x-forgejo-signature-256": `sha256=${digest}` });
expect(await verifyJojoSignature("secret", body, headers)).toBe(true);
expect(await verifyJojoSignature("wrong", body, headers)).toBe(false);
});
});