Skip to content

Commit f1ad47e

Browse files
committed
feat(webhook): check installation id against known integrations
1 parent f91987b commit f1ad47e

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

apps/dashboard/server/lib/github-webhook-auth.test.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { describe, test, expect } from "bun:test"
2-
import { checkBodySize, MAX_WEBHOOK_BODY_BYTES, recordDelivery } from "./github-webhook-auth"
2+
import {
3+
checkBodySize,
4+
MAX_WEBHOOK_BODY_BYTES,
5+
recordDelivery,
6+
isKnownInstallation,
7+
} from "./github-webhook-auth"
38
import { db } from "../db"
49
import { githubWebhookDeliveries } from "../db/schema/github-webhook-deliveries"
10+
import { githubIntegrations } from "../db/schema/github-integrations"
11+
import { projects } from "../db/schema/projects"
512
import { eq } from "drizzle-orm"
613

714
describe("checkBodySize", () => {
@@ -37,3 +44,27 @@ describe("recordDelivery", () => {
3744
await db.delete(githubWebhookDeliveries).where(eq(githubWebhookDeliveries.deliveryId, id))
3845
})
3946
})
47+
48+
describe("isKnownInstallation", () => {
49+
test("returns false when no row matches", async () => {
50+
expect(await isKnownInstallation(999_999_999)).toBe(false)
51+
})
52+
53+
test("returns true when a github_integrations row has the installation id", async () => {
54+
const [project] = await db
55+
.insert(projects)
56+
.values({ name: "wh-auth-test", createdBy: "test-user" })
57+
.returning()
58+
const installationId = 42_000_000 + Math.floor(Math.random() * 1_000_000)
59+
await db.insert(githubIntegrations).values({
60+
projectId: project.id,
61+
installationId,
62+
repoOwner: "",
63+
repoName: "",
64+
status: "connected",
65+
})
66+
expect(await isKnownInstallation(installationId)).toBe(true)
67+
await db.delete(githubIntegrations).where(eq(githubIntegrations.projectId, project.id))
68+
await db.delete(projects).where(eq(projects.id, project.id))
69+
})
70+
})

0 commit comments

Comments
 (0)