Skip to content

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

Greptile fix

Carlos Monastyrski37d0f56bd5e3
diff --git a/backend/src/services/alert/alert-channel-test-service.test.ts b/backend/src/services/alert/alert-channel-test-service.test.ts
index b7cee9368a..cecef69189 100644
--- a/backend/src/services/alert/alert-channel-test-service.test.ts
+++ b/backend/src/services/alert/alert-channel-test-service.test.ts
@@ -34,6 +34,7 @@ const buildProvider = (opts?: {
resolvedProjectId?: string;
blockedChannelTypes?: string[];
webhookSource?: boolean;
+ getResourceNames?: IResourceAlertProvider["getResourceNames"];
}) => {
const provider: IResourceAlertProvider = {
resourceType: RESOURCE_TYPE,
@@ -70,7 +71,8 @@ const buildProvider = (opts?: {
...(opts?.resolvedProjectId ? { resolveProjectId: async () => opts.resolvedProjectId as string } : {}),
...(opts?.webhookSource
? { getWebhookSource: ({ alertId, resourceId }) => `/resources/${resourceId}/alerts/${alertId}` }
- : {})
+ : {}),
+ ...(opts?.getResourceNames ? { getResourceNames: opts.getResourceNames } : {})
};
const registry = alertProviderRegistryFactory();
@@ -184,6 +186,68 @@ describe("alertChannelTestService", () => {
}
});
+ test("returns the name of the resource the test was sent for", async () => {
+ const lookups: { orgId: string; resourceIds: string[] }[] = [];
+ const restore = stubSend("slack", async () => ({ success: true }));
+
+ try {
+ const { deps } = buildDeps({
+ registry: buildProvider({
+ getResourceNames: async (input) => {
+ lookups.push(input);
+ return new Map([["resource-1", "Payments API"]]);
+ }
+ })
+ });
+ const service = alertChannelTestServiceFactory(deps);
+
+ const result = await service.testChannel({
+ ...actor,
+ resourceType: RESOURCE_TYPE,
+ resourceId: "resource-1",
+ channelType: "slack" as never,
+ config: { webhookUrl: "https://hooks.slack.com/services/T/B/x" }
+ });
+
+ expect(lookups).toEqual([{ orgId: ORG_ID, resourceIds: ["resource-1"] }]);
+ expect(result.resourceName).toBe("Payments API");
+ } finally {
+ restore();
+ }
+ });
+
+ test("sends nothing when the resource name lookup fails", async () => {
+ const sent: TAlertChannelSendContext[] = [];
+ const restore = stubSend("slack", async (ctx) => {
+ sent.push(ctx);
+ return { success: true };
+ });
+
+ try {
+ const { deps } = buildDeps({
+ registry: buildProvider({
+ getResourceNames: async () => {
+ throw new Error("lookup failed");
+ }
+ })
+ });
+ const service = alertChannelTestServiceFactory(deps);
+
+ await expect(
+ service.testChannel({
+ ...actor,
+ resourceType: RESOURCE_TYPE,
+ resourceId: "resource-1",
+ channelType: "slack" as never,
+ config: { webhookUrl: "https://hooks.slack.com/services/T/B/x" }
+ })
+ ).rejects.toThrow("lookup failed");
+ expect(sent).toHaveLength(0);
+ } finally {
+ restore();
+ }
+ });
+
test("sends a test through an undirected channel with the supplied config", async () => {
const sent: TAlertChannelSendContext[] = [];
const restore = stubSend("slack", async (ctx) => {
diff --git a/backend/src/services/alert/alert-channel-test-service.ts b/backend/src/services/alert/alert-channel-test-service.ts
index aedb53cfca..f8e10bbe5c 100644
--- a/backend/src/services/alert/alert-channel-test-service.ts
+++ b/backend/src/services/alert/alert-channel-test-service.ts
@@ -236,8 +236,8 @@ export const alertChannelTestServiceFactory = ({
}
const config = await $resolveConfig(dto, projectId);
- const result = await $sendTest(dto, projectId, provider, config);
const resourceName = await getAlertResourceName(provider, dto.actorOrgId, dto.resourceId);
+ const result = await $sendTest(dto, projectId, provider, config);
return { ...result, projectId, resourceName };
};