Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

test(e2e): cover webhook delivery via a domain-focused secrets-management spec

Calvin8ed930ac3bc0
diff --git a/backend/e2e-test/fakes/webhook-destination.ts b/backend/e2e-test/fakes/webhook-destination.ts
new file mode 100644
index 0000000000..4049c3617f
--- /dev/null
+++ b/backend/e2e-test/fakes/webhook-destination.ts
@@ -0,0 +1,122 @@
+import http from "node:http";
+import type { AddressInfo } from "node:net";
+
+export type TFakeWebhookMessage = {
+ method: string;
+ path: string;
+ headers: Record<string, string | string[] | undefined>;
+ body: unknown;
+ receivedAt: number;
+};
+
+type TMessagePredicate = (message: TFakeWebhookMessage) => boolean;
+
+export type TFakeWebhookServer = {
+ url: string;
+ messages: () => TFakeWebhookMessage[];
+ // Resolves with the first unclaimed buffered message matching `predicate` (default: any
+ // message), or waits for one to arrive. A match is claimed on return, so it is never handed to
+ // a second waiter — required once a fake is shared by more than one test in a file, since
+ // messages then arrive interleaved and out of any one test's control. Rejects if none arrives
+ // within timeoutMs.
+ waitForMessage: (predicate?: TMessagePredicate, timeoutMs?: number) => Promise<TFakeWebhookMessage>;
+ reset: () => void;
+ stop: () => Promise<void>;
+};
+
+const DEFAULT_WAIT_TIMEOUT_MS = 5_000;
+const matchAny: TMessagePredicate = () => true;
+
+// A real listener, not an in-memory stub: webhook delivery is a real outbound HTTP call to an
+// arbitrary URL (unlike, say, the AWS fakes, which replace an SDK client we control the seam
+// for), so there's no module to swap out from under it.
+export const createFakeWebhookServer = async (): Promise<TFakeWebhookServer> => {
+ const messages: TFakeWebhookMessage[] = [];
+ const claimed = new Set<TFakeWebhookMessage>();
+ const waiters: { predicate: TMessagePredicate; resolve: (message: TFakeWebhookMessage) => void }[] = [];
+
+ const server = http.createServer((req, res) => {
+ const chunks: Buffer[] = [];
+ req.on("data", (chunk: Buffer) => chunks.push(chunk));
+ req.on("end", () => {
+ const raw = Buffer.concat(chunks).toString("utf8");
+ let body: unknown = raw;
+ try {
+ body = raw ? JSON.parse(raw) : undefined;
+ } catch {
+ // Not every caller sends JSON; keep the raw text rather than failing the request.
+ }
+
+ const message: TFakeWebhookMessage = {
+ method: req.method ?? "GET",
+ path: req.url ?? "/",
+ headers: req.headers,
+ body,
+ receivedAt: Date.now()
+ };
+ messages.push(message);
+
+ // First registered waiter whose predicate matches wins, so two tests waiting on the same
+ // fake with distinct predicates each get their own message rather than racing for it.
+ const waiterIndex = waiters.findIndex((waiter) => waiter.predicate(message));
+ if (waiterIndex !== -1) {
+ const [waiter] = waiters.splice(waiterIndex, 1);
+ claimed.add(message);
+ waiter.resolve(message);
+ }
+
+ res.writeHead(200, { "Content-Type": "application/json" });
+ res.end(JSON.stringify({ ok: true }));
+ });
+ });
+
+ await new Promise<void>((resolve) => {
+ server.listen(0, "127.0.0.1", resolve);
+ });
+ const { port } = server.address() as AddressInfo;
+
+ const waitForMessage = (
+ predicate: TMessagePredicate = matchAny,
+ timeoutMs = DEFAULT_WAIT_TIMEOUT_MS
+ ): Promise<TFakeWebhookMessage> => {
+ const buffered = messages.find((message) => !claimed.has(message) && predicate(message));
+ if (buffered) {
+ claimed.add(buffered);
+ return Promise.resolve(buffered);
+ }
+
+ return new Promise<TFakeWebhookMessage>((resolve, reject) => {
+ const waiter = { predicate, resolve };
+
+ const timer = setTimeout(() => {
+ const index = waiters.indexOf(waiter);
+ if (index !== -1) waiters.splice(index, 1);
+ reject(new Error(`Timed out after ${timeoutMs}ms waiting for a matching webhook message`));
+ }, timeoutMs);
+
+ waiter.resolve = (message) => {
+ clearTimeout(timer);
+ resolve(message);
+ };
+
+ waiters.push(waiter);
+ });
+ };
+
+ return {
+ url: `http://127.0.0.1:${port}/`,
+ messages: () => messages,
+ waitForMessage,
+ reset: () => {
+ messages.length = 0;
+ claimed.clear();
+ },
+ stop: () =>
+ new Promise<void>((resolve, reject) => {
+ server.close((err) => {
+ if (err) reject(err);
+ else resolve();
+ });
+ })
+ };
+};
diff --git a/backend/e2e-test/routes/v1/secret-sync.spec.ts b/backend/e2e-test/routes/v1/secret-sync.spec.ts
index bb7f124570..4653a10d52 100644
--- a/backend/e2e-test/routes/v1/secret-sync.spec.ts
+++ b/backend/e2e-test/routes/v1/secret-sync.spec.ts
@@ -1,6 +1,7 @@
import { randomUUID } from "crypto";
import { fakeParameterStore } from "e2e-test/fakes/aws-parameter-store-sync-fns";
import { createFolder, deleteFolder } from "e2e-test/testUtils/folders";
+import { createIsolatedOrgAndProject } from "e2e-test/testUtils/fixtures";
import { createSecretImport } from "e2e-test/testUtils/secret-imports";
import {
createAwsAppConnection,
@@ -41,12 +42,14 @@ describe("Secret syncs", async () => {
vi.setConfig({ testTimeout: 30_000, hookTimeout: 30_000 });
let projectId: string;
+ let authToken: string;
+ let cleanupOrg: () => Promise<void>;
let connectionId: string;
let createdSyncIds: string[] = [];
const newFolder = (parentPath: string, name: string) =>
createFolder({
- authToken: jwtAuthToken,
+ authToken,
workspaceId: projectId,
environmentSlug: ENV,
secretPath: parentPath,
@@ -54,14 +57,14 @@ describe("Secret syncs", async () => {
});
const addSecret = (secretPath: string, key: string, value: string) =>
- createSecretV2({ authToken: jwtAuthToken, workspaceId: projectId, environmentSlug: ENV, secretPath, key, value });
+ createSecretV2({ authToken, workspaceId: projectId, environmentSlug: ENV, secretPath, key, value });
const removeSecret = (secretPath: string, key: string) =>
- deleteSecretV2({ authToken: jwtAuthToken, workspaceId: projectId, environmentSlug: ENV, secretPath, key });
+ deleteSecretV2({ authToken, workspaceId: projectId, environmentSlug: ENV, secretPath, key });
const secretKeysAt = async (secretPath: string) => {
const { secrets } = await getSecretsV2({
- authToken: jwtAuthToken,
+ authToken,
workspaceId: projectId,
environmentSlug: ENV,
secretPath
@@ -80,7 +83,7 @@ describe("Secret syncs", async () => {
environmentSlug: ENV,
region: REGION,
destinationPath: pathFor(name),
- authToken: jwtAuthToken,
+ authToken,
...overrides
});
@@ -95,25 +98,17 @@ describe("Secret syncs", async () => {
// another's writes or teardown. That matters more than usual for secret syncs: auto sync reacts
// to any write at a sync's source path, secret imports outlive the test that made them, and an
// app connection is org-scoped rather than project-scoped, so sharing one would leave a single
- // row that every test's syncs hang off.
+ // row that every test's syncs hang off. A fresh org per test (not just a fresh project) closes
+ // that off completely rather than relying on the shared seeded org staying tidy.
beforeEach(async () => {
fakeParameterStore.reset();
createdSyncIds = [];
- const suffix = randomUUID().slice(0, 8);
-
- const projectRes = await testServer.inject({
- method: "POST",
- url: "/api/v1/projects",
- headers: { authorization: `Bearer ${jwtAuthToken}` },
- body: { projectName: `secret-sync-e2e-${suffix}` }
- });
- expect(projectRes.statusCode).toBe(200);
- projectId = projectRes.json().project.id as string;
+ ({ projectId, authToken, cleanup: cleanupOrg } = await createIsolatedOrgAndProject("secret-sync-e2e"));
connectionId = await createAwsAppConnection({
- name: `secret-sync-e2e-${suffix}`,
- authToken: jwtAuthToken
+ name: `secret-sync-e2e-${randomUUID().slice(0, 8)}`,
+ authToken
});
await newFolder("/", "services");
@@ -126,15 +121,11 @@ describe("Secret syncs", async () => {
// constraint if the syncs went second.
for (const syncId of createdSyncIds) {
// eslint-disable-next-line no-await-in-loop
- await deleteSecretSync({ syncId, authToken: jwtAuthToken });
+ await deleteSecretSync({ syncId, authToken });
}
- await deleteAppConnection({ connectionId, authToken: jwtAuthToken });
- await testServer.inject({
- method: "DELETE",
- url: `/api/v1/projects/${projectId}`,
- headers: { authorization: `Bearer ${jwtAuthToken}` }
- });
+ await deleteAppConnection({ connectionId, authToken });
+ await cleanupOrg();
});
describe("A sync sends the secrets of its own source environment and secret path", () => {
@@ -146,7 +137,7 @@ describe("Secret syncs", async () => {
syncId: secretSync!.id,
region: REGION,
destinationPath: pathFor("sends-source-path"),
- authToken: jwtAuthToken
+ authToken
});
expect(sync.syncStatus).toBe(SecretSyncStatus.Succeeded);
@@ -166,7 +157,7 @@ describe("Secret syncs", async () => {
syncId: secretSync!.id,
region: REGION,
destinationPath: pathFor("excludes-child-paths"),
- authToken: jwtAuthToken
+ authToken
});
const delivered = fakeParameterStore.at(REGION, pathFor("excludes-child-paths")).read();
@@ -183,7 +174,7 @@ describe("Secret syncs", async () => {
await addSecret("/", "SHARED_KEY", "shared-value");
await addSecret("/services", "OWN_KEY", "own-value");
await createSecretImport({
- authToken: jwtAuthToken,
+ authToken,
workspaceId: projectId,
environmentSlug: ENV,
secretPath: "/services",
@@ -196,7 +187,7 @@ describe("Secret syncs", async () => {
syncId: secretSync!.id,
region: REGION,
destinationPath: pathFor("includes-imports"),
- authToken: jwtAuthToken
+ authToken
});
expect(fakeParameterStore.at(REGION, pathFor("includes-imports")).read()).toEqual({
@@ -230,7 +221,7 @@ describe("Secret syncs", async () => {
syncId: secretSync!.id,
region: REGION,
destinationPath,
- authToken: jwtAuthToken
+ authToken
});
expect(fakeParameterStore.at(REGION, destinationPath).read()).toEqual({
@@ -255,7 +246,7 @@ describe("Secret syncs", async () => {
syncId: secretSync!.id,
region: REGION,
destinationPath: pathFor("overwrite-destination"),
- authToken: jwtAuthToken
+ authToken
});
expect(fakeParameterStore.at(REGION, pathFor("overwrite-destination")).read()).toEqual({
@@ -277,7 +268,7 @@ describe("Secret syncs", async () => {
syncId: secretSync!.id,
region: REGION,
destinationPath: pathFor("prioritize-source"),
- authToken: jwtAuthToken
+ authToken
});
expect(fakeParameterStore.at(REGION, pathFor("prioritize-source")).read()).toEqual({
@@ -300,7 +291,7 @@ describe("Secret syncs", async () => {
syncId: secretSync!.id,
region: REGION,
destinationPath: pathFor("prioritize-destination"),
- authToken: jwtAuthToken
+ authToken
});
// The import writes back into the project, which is the surprising half of this option.
@@ -323,7 +314,7 @@ describe("Secret syncs", async () => {
syncId: secretSync!.id,
region: REGION,
destinationPath: pathFor("first-run-only"),
- authToken: jwtAuthToken
+ authToken
});
// Arrives at the destination outside Infisical, after the first run has happened.
@@ -333,7 +324,7 @@ describe("Secret syncs", async () => {
syncId: secretSync!.id,
region: REGION,
destinationPath: pathFor("first-run-only"),
- authToken: jwtAuthToken
+ authToken
});
expect(await secretKeysAt("/services")).toEqual({ API_KEY: "api-value" });
@@ -349,7 +340,7 @@ describe("Secret syncs", async () => {
await addSecret("/services", "OLD_KEY", "old-value");
const { secretSync } = await newSync("deletes-removed", { secretPath: "/services" });
- const address = { region: REGION, destinationPath: pathFor("deletes-removed"), authToken: jwtAuthToken };
+ const address = { region: REGION, destinationPath: pathFor("deletes-removed"), authToken };
await triggerSecretSync({ syncId: secretSync!.id, ...address });
await removeSecret("/services", "OLD_KEY");
@@ -368,7 +359,7 @@ describe("Secret syncs", async () => {
secretPath: "/services",
disableSecretDeletion: true
});
- const address = { region: REGION, destinationPath: pathFor("keeps-removed"), authToken: jwtAuthToken };
+ const address = { region: REGION, destinationPath: pathFor("keeps-removed"), authToken };
await triggerSecretSync({ syncId: secretSync!.id, ...address });
await removeSecret("/services", "OLD_KEY");
@@ -391,7 +382,7 @@ describe("Secret syncs", async () => {
const { secretSync: imported } = await importSecretsForSync({
syncId: secretSync!.id,
importBehavior: "prioritize-source",
- authToken: jwtAuthToken
+ authToken
});
expect(imported!.importStatus).toBe(SecretSyncStatus.Succeeded);
@@ -408,7 +399,7 @@ describe("Secret syncs", async () => {
await importSecretsForSync({
syncId: secretSync!.id,
importBehavior: "prioritize-destination",
- authToken: jwtAuthToken
+ authToken
});
expect(await secretKeysAt("/services")).toEqual({ API_KEY: "destination-value" });
@@ -425,7 +416,7 @@ describe("Secret syncs", async () => {
const { secretSync: imported } = await importSecretsForSync({
syncId: secretSync!.id,
importBehavior: "prioritize-source",
- authToken: jwtAuthToken
+ authToken
});
expect(imported!.importStatus).toBe(SecretSyncStatus.Failed);
@@ -443,11 +434,11 @@ describe("Secret syncs", async () => {
syncId: secretSync!.id,
region: REGION,
destinationPath: pathFor("remove-clears"),
- authToken: jwtAuthToken
+ authToken
});
expect(fakeParameterStore.at(REGION, pathFor("remove-clears")).read()).toEqual({ API_KEY: "api-value" });
- const removed = await removeSecretsForSync({ syncId: secretSync!.id, authToken: jwtAuthToken });
+ const removed = await removeSecretsForSync({ syncId: secretSync!.id, authToken });
expect(removed.removeStatus).toBe(SecretSyncStatus.Succeeded);
expect(fakeParameterStore.at(REGION, pathFor("remove-clears")).read()).toEqual({});
@@ -466,7 +457,7 @@ describe("Secret syncs", async () => {
secretPath: "/services",
isAutoSyncEnabled: false
});
- await setAutoSync({ syncId: secretSync!.id, isAutoSyncEnabled: true, authToken: jwtAuthToken });
+ await setAutoSync({ syncId: secretSync!.id, isAutoSyncEnabled: true, authToken });
// No explicit trigger: the write alone has to cause the run, which is the behaviour
// under test.
@@ -491,7 +482,7 @@ describe("Secret syncs", async () => {
await addSecret("/services", "PARENT_KEY", "parent-value");
// Enabling auto sync queues a run; wait for the parent's secret to arrive.
- await setAutoSync({ syncId: secretSync!.id, isAutoSyncEnabled: true, authToken: jwtAuthToken });
+ await setAutoSync({ syncId: secretSync!.id, isAutoSyncEnabled: true, authToken });
await waitForDestinationSecrets({
region: REGION,
destinationPath,
@@ -531,7 +522,7 @@ describe("Secret syncs", async () => {
syncId: secretSync!.id,
region: REGION,
destinationPath,
- authToken: jwtAuthToken
+ authToken
});
expect(sync.syncStatus).toBe(SecretSyncStatus.Failed);
@@ -544,7 +535,7 @@ describe("Secret syncs", async () => {
test("A sync whose source secret path no longer exists fails with a message naming the source", async () => {
const destinationPath = pathFor("source-path-gone");
const folder = await createFolder({
- authToken: jwtAuthToken,
+ authToken,
workspaceId: projectId,
environmentSlug: ENV,
secretPath: "/",
@@ -553,10 +544,10 @@ describe("Secret syncs", async () => {
await addSecret("/doomed", "API_KEY", "api-value");
const { secretSync } = await newSync("source-path-gone", { secretPath: "/doomed" });
- await triggerSecretSync({ syncId: secretSync!.id, region: REGION, destinationPath, authToken: jwtAuthToken });
+ await triggerSecretSync({ syncId: secretSync!.id, region: REGION, destinationPath, authToken });
await deleteFolder({
- authToken: jwtAuthToken,
+ authToken,
workspaceId: projectId,
environmentSlug: ENV,
secretPath: "/",
@@ -566,7 +557,7 @@ describe("Secret syncs", async () => {
const res = await testServer.inject({
method: "POST",
url: `/api/v1/secret-syncs/aws-parameter-store/${secretSync!.id}/sync-secrets`,
- headers: { authorization: `Bearer ${jwtAuthToken}` }
+ headers: { authorization: `Bearer ${authToken}` }
});
// The source folder is gone, so the trigger itself refuses rather than queueing a run
diff --git a/backend/e2e-test/routes/v3/secrets-management.spec.ts b/backend/e2e-test/routes/v3/secrets-management.spec.ts
new file mode 100644
index 0000000000..26d411ba3d
--- /dev/null
+++ b/backend/e2e-test/routes/v3/secrets-management.spec.ts
@@ -0,0 +1,67 @@
+import { createFakeWebhookServer, TFakeWebhookServer } from "e2e-test/fakes/webhook-destination";
+import { createIsolatedOrgAndProject } from "e2e-test/testUtils/fixtures";
+import { createSecretV2 } from "e2e-test/testUtils/secrets";
+import { createWebhook, waitForWebhookRun } from "e2e-test/testUtils/webhooks";
+
+const ENV = "dev";
+
+// Covers domain-level side effects of secrets management actions, as distinct from the routes'
+// own CRUD behavior (secrets.spec.ts / secrets-v2.spec.ts). A webhook is the observable signal
+// used here, but the thing under test is that the domain action fires the event, not webhook
+// delivery mechanics.
+describe("Secrets management", () => {
+ describe("Secret changes trigger webhook events", () => {
+ // A run is a queue round trip (1s debounce delay + the HTTP attempt), so it takes longer
+ // than the 5s default.
+ vi.setConfig({ testTimeout: 30_000, hookTimeout: 30_000 });
+
+ let projectId: string;
+ let authToken: string;
+ let cleanup: () => Promise<void>;
+ let fakeWebhookServer: TFakeWebhookServer;
+
+ beforeAll(async () => {
+ ({ projectId, authToken, cleanup } = await createIsolatedOrgAndProject("secrets-management-e2e"));
+ fakeWebhookServer = await createFakeWebhookServer();
+ });
+
+ afterAll(async () => {
+ await fakeWebhookServer.stop();
+ await cleanup();
+ });
+
+ test("a secret change enqueues and runs a webhook delivery", async () => {
+ const webhook = await createWebhook({
+ projectId,
+ environmentSlug: ENV,
+ webhookUrl: fakeWebhookServer.url,
+ authToken
+ });
+ expect(webhook.lastStatus).toBeNull();
+
+ await createSecretV2({
+ workspaceId: projectId,
+ environmentSlug: ENV,
+ secretPath: "/",
+ key: "WEBHOOK_TRIGGER_TEST",
+ value: "value",
+ authToken
+ });
+
+ // The fake is shared by every test in this file, so messages from other tests can arrive
+ // interleaved; matching on this test's own project is what makes waitForMessage return the
+ // right one instead of racing whichever test's delivery happens to land first.
+ const message = await fakeWebhookServer.waitForMessage(
+ (m) => (m.body as { event?: string; project?: { workspaceId?: string } })?.project?.workspaceId === projectId
+ );
+ expect(message.method).toBe("POST");
+ expect(message.body).toMatchObject({ event: "secrets.modified" });
+
+ // lastStatus is only ever written by fnTriggerWebhook, which only runs inside the
+ // SecretWebhook queue worker (secret-queue.ts). Confirming it lands on "success" is proof
+ // the whole pipeline, not just delivery, completed.
+ const ranWebhook = await waitForWebhookRun({ webhookId: webhook.id, authToken });
+ expect(ranWebhook.lastStatus).toBe("success");
+ });
+ });
+});
diff --git a/backend/e2e-test/testUtils/fixtures.ts b/backend/e2e-test/testUtils/fixtures.ts
new file mode 100644
index 0000000000..8ed20c9281
--- /dev/null
+++ b/backend/e2e-test/testUtils/fixtures.ts
@@ -0,0 +1,49 @@
+import { randomUUID } from "node:crypto";
+
+import { selectOrg } from "./auth";
+
+// Full isolation per test: a fresh org and project rather than a fresh project inside the shared
+// seeded org. Org-scoped state (roles, membership) can't leak between tests either this way, not
+// just project-scoped state. Cheaper alternatives exist (see secret-sync.spec.ts's beforeEach,
+// which only creates a fresh project under the shared seeded org) but this is the one to reach for
+// by default going forward.
+export const createIsolatedOrgAndProject = async (namePrefix: string) => {
+ const name = `${namePrefix}-${randomUUID().slice(0, 8)}`;
+
+ const orgRes = await testServer.inject({
+ method: "POST",
+ url: "/api/v2/organizations",
+ headers: { authorization: `Bearer ${jwtAuthToken}` },
+ body: { name }
+ });
+ expect(orgRes.statusCode).toBe(200);
+ const orgId = orgRes.json().organization.id as string;
+
+ // The org creation token is scoped to whatever org it already carried; project creation reads
+ // its org from the token too (project-router.ts), so a token scoped to the new org is required
+ // before anything project-shaped can be created in it.
+ const selectOrgRes = await selectOrg(jwtAuthToken, orgId);
+ expect(selectOrgRes.statusCode).toBe(200);
+ const authToken = selectOrgRes.payload.token as string;
+
+ const projectRes = await testServer.inject({
+ method: "POST",
+ url: "/api/v1/projects",
+ headers: { authorization: `Bearer ${authToken}` },
+ body: { projectName: name }
+ });
+ expect(projectRes.statusCode).toBe(200);
+ const projectId = projectRes.json().project.id as string;
+
+ // Hard-deletes the org row; every project/environment/secret/webhook underneath it is reaped by
+ // FK cascade (org-service.ts:deleteOrganizationById), so there's nothing else to tear down.
+ const cleanup = async () => {
+ await testServer.inject({
+ method: "DELETE",
+ url: `/api/v2/organizations/${orgId}`,
+ headers: { authorization: `Bearer ${authToken}` }
+ });
+ };
+
+ return { orgId, projectId, authToken, cleanup };
+};
diff --git a/backend/e2e-test/testUtils/webhooks.ts b/backend/e2e-test/testUtils/webhooks.ts
new file mode 100644
index 0000000000..b17ea5ad88
--- /dev/null
+++ b/backend/e2e-test/testUtils/webhooks.ts
@@ -0,0 +1,61 @@
+type TWebhook = {
+ id: string;
+ lastStatus: string | null;
+ lastRunErrorMessage: string | null;
+};
+
+export const createWebhook = async (dto: {
+ projectId: string;
+ environmentSlug: string;
+ secretPath?: string;
+ webhookUrl: string;
+ authToken: string;
+}) => {
+ const res = await testServer.inject({
+ method: "POST",
+ url: "/api/v1/webhooks",
+ headers: { authorization: `Bearer ${dto.authToken}` },
+ body: {
+ projectId: dto.projectId,
+ environment: dto.environmentSlug,
+ webhookUrl: dto.webhookUrl,
+ secretPath: dto.secretPath ?? "/"
+ }
+ });
+ expect(res.statusCode).toBe(200);
+ return res.json().webhook as TWebhook;
+};
+
+export const getWebhook = async (dto: { webhookId: string; authToken: string }) => {
+ const res = await testServer.inject({
+ method: "GET",
+ url: `/api/v1/webhooks/${dto.webhookId}`,
+ headers: { authorization: `Bearer ${dto.authToken}` }
+ });
+ expect(res.statusCode).toBe(200);
+ return res.json().webhook as TWebhook;
+};
+
+const POLL_TIMEOUT_MS = 3_000;
+const POLL_INTERVAL_MS = 100;
+
+// The webhook trigger job runs with a 1s debounce delay plus whatever the receiver takes to
+// respond, so lastStatus flips some time after the secret write that queued it, not immediately.
+export const waitForWebhookRun = async (dto: { webhookId: string; authToken: string }) => {
+ const deadline = Date.now() + POLL_TIMEOUT_MS;
+
+ for (;;) {
+ // eslint-disable-next-line no-await-in-loop
+ const webhook = await getWebhook(dto);
+ if (webhook.lastStatus !== null) return webhook;
+
+ if (Date.now() >= deadline) {
+ throw new Error(`Timed out after ${POLL_TIMEOUT_MS}ms waiting for webhook "${dto.webhookId}" to run`);
+ }
+
+ // eslint-disable-next-line no-await-in-loop
+ await new Promise((resolve) => {
+ setTimeout(resolve, POLL_INTERVAL_MS);
+ });
+ }
+};
diff --git a/backend/e2e-test/vitest-environment-knex.ts b/backend/e2e-test/vitest-environment-knex.ts
index 1878010a2d..fdb9054639 100644
--- a/backend/e2e-test/vitest-environment-knex.ts
+++ b/backend/e2e-test/vitest-environment-knex.ts
@@ -25,6 +25,7 @@ import { hsmServiceFactory } from "@app/ee/services/hsm/hsm-service";
import { kmsRootConfigDALFactory } from "@app/services/kms/kms-root-config-dal";
dotenv.config({ path: path.join(__dirname, "../../.env.test"), debug: true });
+process.env.ALLOW_INTERNAL_IP_CONNECTIONS = "true";
export default {
name: "knex-env",
transformMode: "ssr",