Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix lookup
Thiago Araujo da Silvae9d8ea5c81e0
diff --git a/backend/src/services/alert/alert-event-consumer.test.ts b/backend/src/services/alert/alert-event-consumer.test.tsindex 36500b35cd..4f692dd012 100644--- a/backend/src/services/alert/alert-event-consumer.test.ts+++ b/backend/src/services/alert/alert-event-consumer.test.ts@@ -192,7 +192,7 @@ describe("alert event consumer", () => {expect(runs.map((run) => run.alertId)).toEqual(["alert-1", "alert-3"]);});- test("resolves the matching alerts once per event type within a batch", async () => {+ test("resolves the matching alerts once per resource and event type within a batch", async () => {const { consumer, getLookups } = buildConsumer();await consumer.handle([@@ -204,6 +204,20 @@ describe("alert event consumer", () => {expect(getLookups()).toBe(1);});+ // The lookup is filtered by resource, so two resources in one org must not share a result: the second+ // would otherwise be delivered to the first resource's recipients.+ test("does not reuse one resource's alerts for another resource in the same batch", async () => {+ const { consumer, getLookups } = buildConsumer();++ await consumer.handle([+ makeEvent({ id: 1, payload: makePayload({ resourceId: "policy-1", targetIds: ["req-1"] }) }),+ makeEvent({ id: 2, payload: makePayload({ resourceId: "policy-2", targetIds: ["req-2"] }) }),+ makeEvent({ id: 3, payload: makePayload({ resourceId: "policy-1", targetIds: ["req-3"] }) })+ ]);++ expect(getLookups()).toBe(2);+ });+// Handling events concurrently would fan a whole batch out at once and deliver one resource's events// out of order.test("handles events serially, in the order given", async () => {diff --git a/backend/src/services/alert/alert-event-consumer.ts b/backend/src/services/alert/alert-event-consumer.tsindex 3c78b36873..e6f8564d54 100644--- a/backend/src/services/alert/alert-event-consumer.ts+++ b/backend/src/services/alert/alert-event-consumer.ts@@ -107,13 +107,19 @@ export const alertEventConsumerFactory = ({};const handle = async (events: TEvent[]): Promise<TEventConsumerResult[]> => {- const alertsByScope = new Map<string, ReturnType<TAlertLookup>>();+ const alertsByFilter = new Map<string, ReturnType<TAlertLookup>>();const findAlerts: TAlertLookup = (filter) => {- const key = `${filter.orgId}|${filter.projectId ?? ""}|${filter.eventType}`;- let lookup = alertsByScope.get(key);+ const key = JSON.stringify([+ filter.orgId,+ filter.projectId ?? null,+ filter.resourceType,+ filter.resourceId,+ filter.eventType+ ]);+ let lookup = alertsByFilter.get(key);if (!lookup) {lookup = alertDAL.findEnabledForEvent(filter);- alertsByScope.set(key, lookup);+ alertsByFilter.set(key, lookup);}return lookup;};