Skip to content

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

fixed sample payload

Thiago Araujo da Silva8ba63253f9d1
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 53593e5151..019a783517 100644
--- a/backend/src/services/alert/alert-channel-test-service.test.ts
+++ b/backend/src/services/alert/alert-channel-test-service.test.ts
@@ -13,6 +13,11 @@ vi.mock("@app/lib/logger", () => ({
initLogger: () => {}
}));
+// The generic test payload reads SITE_URL, and initEnvConfig() doesn't run in unit tests.
+vi.mock("@app/lib/config/env", () => ({
+ getConfig: () => ({ SITE_URL: "https://app.infisical.com" })
+}));
+
const RESOURCE_TYPE = "test.resource";
const ORG_ID = "org-1";
const ACTOR_ID = "actor-1";
@@ -44,7 +49,6 @@ const buildProvider = (opts?: { assertPermission?: (input: TAlertPermissionInput
items: (targets as { id: string }[]).map((target) => ({ id: target.id, title: "sample" }))
}) as TAlertPayload,
targetId: () => "t",
- buildTestTargets: () => [{ id: "sample-target" }],
assertPermission: async (input) => {
if (opts?.assertPermission) await opts.assertPermission(input);
},
@@ -145,7 +149,11 @@ describe("alertChannelTestService", () => {
expect(sent[0].config).toEqual({ webhookUrl: "https://hooks.slack.com/services/T/B/x" });
// A test must never page an on-call rotation at the severity a real firing would carry.
expect(sent[0].payload.severity).toBe("info");
- expect(sent[0].payload.summary).toContain("Test alert from Infisical");
+ expect(sent[0].payload.summary).toContain("test notification from Infisical");
+ // The payload is generic mock data: it must not carry the provider's resource type, and it
+ // must always carry at least one item (PagerDuty sends one event per item).
+ expect(sent[0].payload.alert.resourceType).not.toBe(RESOURCE_TYPE);
+ expect(sent[0].payload.items.length).toBeGreaterThan(0);
} finally {
restore();
}
diff --git a/backend/src/services/alert/alert-channel-test-service.ts b/backend/src/services/alert/alert-channel-test-service.ts
index 02aad5aea2..dc5286dff0 100644
--- a/backend/src/services/alert/alert-channel-test-service.ts
+++ b/backend/src/services/alert/alert-channel-test-service.ts
@@ -1,5 +1,3 @@
-import crypto from "node:crypto";
-
import { KeyStorePrefixes, KeyStoreTtls, TKeyStoreFactory } from "@app/keystore/keystore";
import { BadRequestError, NotFoundError, RateLimitError } from "@app/lib/errors";
import { logger } from "@app/lib/logger";
@@ -13,12 +11,13 @@ import {
} from "./alert-channel-config-fns";
import { decryptChannelConfig, getAlertChannelCipher } from "./alert-channel-crypto-fns";
import { TAlertChannelDALFactory } from "./alert-channel-dal";
-import { TAlertChannelDeps, TAlertPayload, TAlertRecipient } from "./alert-channel-types";
+import { TAlertChannelDeps, TAlertRecipient } from "./alert-channel-types";
import { TAlertDALFactory } from "./alert-dal";
import { TAlertProviderRegistry } from "./alert-provider-registry";
import { TAlertRecipientResolver } from "./alert-recipient-resolver";
import { TTestAlertChannelDTO, TTestAlertChannelResponse } from "./alert-service-types";
-import { AlertPermissionAction, IResourceAlertProvider, TAlertContext, toAlertActor } from "./alert-types";
+import { buildTestAlertPayload } from "./alert-test-payload-fns";
+import { AlertPermissionAction, toAlertActor } from "./alert-types";
export type TAlertChannelTestServiceFactoryDep = {
alertChannelDAL: Pick<TAlertChannelDALFactory, "findById">;
@@ -132,32 +131,6 @@ export const alertChannelTestServiceFactory = ({
return (resolved.get(TEST_CHANNEL_ID) ?? []).slice(0, MAX_TEST_RECIPIENTS);
};
- const $buildTestPayload = async (
- provider: IResourceAlertProvider,
- dto: TTestAlertChannelDTO,
- projectId: string | null
- ): Promise<TAlertPayload> => {
- const alertContext: TAlertContext = {
- id: crypto.randomUUID(),
- name: "Test alert",
- orgId: dto.actorOrgId,
- projectId,
- resourceType: provider.resourceType,
- resourceId: dto.resourceId ?? null,
- eventType: provider.eventTypes[0],
- condition: null
- };
-
- const viewUrl = await provider.buildViewUrl(alertContext);
- const payload = provider.buildPayload(alertContext, provider.buildTestTargets(), viewUrl);
-
- return {
- ...payload,
- severity: "info",
- summary: `Test alert from Infisical. A real ${payload.resourceKind} ${payload.eventLabel.toLowerCase()} alert would look like this. No action is needed.`
- };
- };
-
const $toError = (err: unknown): string => {
const message = err instanceof Error ? err.message : String(err);
return message.slice(0, MAX_ERROR_LENGTH);
@@ -194,7 +167,7 @@ export const alertChannelTestServiceFactory = ({
await $assertCooldown(dto.actorOrgId, dto.actorId, dto.channelType);
const deps: TAlertChannelDeps = { smtpService };
- const payload = await $buildTestPayload(provider, dto, projectId);
+ const payload = buildTestAlertPayload({ orgId: dto.actorOrgId, projectId });
try {
if (!definition.directed) {
diff --git a/backend/src/services/alert/alert-engine.test.ts b/backend/src/services/alert/alert-engine.test.ts
index 149c49a8c1..7fb99166c0 100644
--- a/backend/src/services/alert/alert-engine.test.ts
+++ b/backend/src/services/alert/alert-engine.test.ts
@@ -57,7 +57,6 @@ const makeProvider = (targets: TTarget[], onFindDueTargets?: () => void): IResou
resourceType: RESOURCE_TYPE,
eventTypes: ["test.resource.expiration"],
conditionSchema: z.any(),
- buildTestTargets: () => [],
findDueTargets: async () => {
onFindDueTargets?.();
return targets;
diff --git a/backend/src/services/alert/alert-service.test.ts b/backend/src/services/alert/alert-service.test.ts
index af2c9d6a44..91ff01e42e 100644
--- a/backend/src/services/alert/alert-service.test.ts
+++ b/backend/src/services/alert/alert-service.test.ts
@@ -34,7 +34,6 @@ const buildService = (opts?: {
buildViewUrl: async () => "https://app.infisical.com/x",
buildPayload: () => ({}) as TAlertPayload,
targetId: () => "t",
- buildTestTargets: () => [],
assertPermission: async (input) => {
permissionCalls.push(input);
if (opts?.assertPermission) await opts.assertPermission(input);
diff --git a/backend/src/services/alert/alert-test-payload-fns.ts b/backend/src/services/alert/alert-test-payload-fns.ts
new file mode 100644
index 0000000000..eb3cb4815c
--- /dev/null
+++ b/backend/src/services/alert/alert-test-payload-fns.ts
@@ -0,0 +1,47 @@
+import crypto from "node:crypto";
+
+import { getConfig } from "@app/lib/config/env";
+
+import { TAlertPayload } from "./alert-channel-types";
+
+const TEST_ALERT_NAME = "Sample alert";
+
+const TEST_ITEMS = [
+ {
+ id: "sample",
+ title: "Sample credential",
+ fields: [
+ { label: "Type", value: "Sample" },
+ { label: "Expires", value: "7 days from now" }
+ ]
+ }
+];
+
+export const buildTestAlertPayload = ({
+ orgId,
+ projectId
+}: {
+ orgId: string;
+ projectId?: string | null;
+}): TAlertPayload => {
+ const appCfg = getConfig();
+
+ return {
+ alert: {
+ id: crypto.randomUUID(),
+ name: TEST_ALERT_NAME,
+ orgId,
+ ...(projectId ? { projectId } : {}),
+ resourceType: "alert.channel.test",
+ viewUrl: appCfg.SITE_URL ?? ""
+ },
+ eventKey: "alert.channel.test",
+ eventLabel: "Expiry",
+ webhookType: "com.infisical.alert.channel.test",
+ resourceKind: "Sample Credential",
+ resourceOwnerKind: "resource",
+ severity: "info",
+ summary: "This is a test notification from Infisical, showing how a real alert will look",
+ items: TEST_ITEMS
+ };
+};
diff --git a/backend/src/services/alert/alert-types.ts b/backend/src/services/alert/alert-types.ts
index bfda0340e6..6c5f29a594 100644
--- a/backend/src/services/alert/alert-types.ts
+++ b/backend/src/services/alert/alert-types.ts
@@ -101,11 +101,6 @@ export interface IResourceAlertProvider<TTarget = unknown> {
// Stable id per target, used for dedup and history. Must be stable across cron runs.
targetId(target: TTarget): string;
- // Representative targets used to render a "send test" delivery, so what a user sees when testing a
- // channel is the same shape a real firing produces. Purely synthetic: never queried, stored, or
- // deduped against history, so the ids need not correspond to real rows.
- buildTestTargets(): TTarget[];
-
// Optional per-condition dedup window override (hours). Defaults to DEFAULT_DEDUP_WINDOW_HOURS.
dedupWindowHours?(condition: unknown): number;
diff --git a/backend/src/services/alert/providers/identity-credential-alert-provider.ts b/backend/src/services/alert/providers/identity-credential-alert-provider.ts
index 2daa451711..401b7885a0 100644
--- a/backend/src/services/alert/providers/identity-credential-alert-provider.ts
+++ b/backend/src/services/alert/providers/identity-credential-alert-provider.ts
@@ -83,9 +83,6 @@ const CREDENTIAL_TYPE_LABEL: Record<TIdentityCredentialTarget["credentialType"],
"ua-client-secret": "Universal Auth Client Secret"
};
-const TEST_TARGET_ID = "00000000-0000-0000-0000-000000000000";
-const TEST_TARGET_EXPIRES_IN_DAYS = 7;
-
export type TIdentityCredentialAlertProviderDep = {
identityCredentialAlertDAL: TIdentityCredentialAlertDALFactory;
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission" | "getProjectPermission">;
@@ -181,18 +178,6 @@ export const identityCredentialAlertProviderFactory = ({
};
};
- const buildTestTargets = (): TIdentityCredentialTarget[] => [
- {
- credentialType: "ua-client-secret",
- id: TEST_TARGET_ID,
- identityId: TEST_TARGET_ID,
- identityName: "Sample Machine Identity",
- description: "Sample Client Secret",
- clientSecretPrefix: "abcd",
- expiresAt: new Date(Date.now() + TEST_TARGET_EXPIRES_IN_DAYS * 24 * 60 * 60 * 1000)
- }
- ];
-
const assertResourceInScope = async (input: {
orgId: string;
projectId?: string | null;
@@ -286,7 +271,6 @@ export const identityCredentialAlertProviderFactory = ({
buildViewUrl,
buildPayload,
targetId,
- buildTestTargets,
dedupWindowHours: (condition) => {
const parsed = IdentityCredentialConditionSchema.safeParse(condition);
if (!parsed.success) return DEFAULT_DEDUP_WINDOW_HOURS;