Skip to content

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

use only one key

Thiago Araujo da Silva5eecf8ed7eb5
diff --git a/backend/src/keystore/keystore.ts b/backend/src/keystore/keystore.ts
index 28177eb152..bebf99885e 100644
--- a/backend/src/keystore/keystore.ts
+++ b/backend/src/keystore/keystore.ts
@@ -86,10 +86,8 @@ export const KeyStorePrefixes = {
`sse-connections:${projectId}:${identityId}:${connectionId}` as const,
RecentAnnouncements: "announcements:recent" as const,
- AlertChannelTestOrgCooldown: (orgId: string, channelType: string) =>
- `alert-channel-test-cooldown:org:${orgId}:${channelType}` as const,
- AlertChannelTestActorCooldown: (actorId: string, channelType: string) =>
- `alert-channel-test-cooldown:actor:${actorId}:${channelType}` as const,
+ AlertChannelTestCooldown: (orgId: string, actorId: string, channelType: string) =>
+ `alert-channel-test-cooldown:${orgId}:${actorId}:${channelType}` as const,
ProjectPermissionMarker: (projectId: string, actorType: string, actorId: string, actionProjectType: string) =>
`project-permission-marker:${projectId}:${actorType}:${actorId}:${actionProjectType}` as const,
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 d97cb105f9..bc2dc1cdd7 100644
--- a/backend/src/services/alert/alert-channel-test-service.test.ts
+++ b/backend/src/services/alert/alert-channel-test-service.test.ts
@@ -60,7 +60,8 @@ const buildKeyStore = () => {
const keys = new Map<string, number>();
return {
acquired: [] as string[],
- setItemWithExpiryNX: async (key: string, expiryInSeconds: number | string) => {
+ setItemWithExpiryNX: async (key: string, expiryInSeconds: number | string, ...rest: string[]) => {
+ void rest;
if (keys.has(key)) return null;
keys.set(key, Number(expiryInSeconds));
return "OK" as const;
@@ -210,7 +211,7 @@ describe("alertChannelTestService", () => {
// The window is still free, so a corrected config can be tested immediately.
await expect(
- keyStore.setItemWithExpiryNX(`alert-channel-test-cooldown:org:${ORG_ID}:slack`, 60, "1")
+ keyStore.setItemWithExpiryNX(`alert-channel-test-cooldown:${ORG_ID}:${ACTOR_ID}:slack`, 60, "1")
).resolves.toBe("OK");
});
@@ -301,7 +302,7 @@ describe("alertChannelTestService", () => {
expect(result.success).toBe(false);
expect(result.error).toMatch(/recipients could be resolved/);
await expect(
- keyStore.setItemWithExpiryNX(`alert-channel-test-cooldown:org:${ORG_ID}:email`, 60, "1")
+ keyStore.setItemWithExpiryNX(`alert-channel-test-cooldown:${ORG_ID}:${ACTOR_ID}:email`, 60, "1")
).resolves.toBe("OK");
});
diff --git a/backend/src/services/alert/alert-channel-test-service.ts b/backend/src/services/alert/alert-channel-test-service.ts
index 2ecdc6be7d..2b53dd2283 100644
--- a/backend/src/services/alert/alert-channel-test-service.ts
+++ b/backend/src/services/alert/alert-channel-test-service.ts
@@ -43,23 +43,15 @@ export const alertChannelTestServiceFactory = ({
keyStore
}: TAlertChannelTestServiceFactoryDep) => {
const $assertCooldown = async (orgId: string, actorId: string, channelType: string) => {
- const windows = [
- { key: KeyStorePrefixes.AlertChannelTestOrgCooldown(orgId, channelType), scope: "organization" },
- { key: KeyStorePrefixes.AlertChannelTestActorCooldown(actorId, channelType), scope: "you" }
- ];
-
- for (const { key, scope } of windows) {
- // eslint-disable-next-line no-await-in-loop -- the org window must settle before the actor's is spent
- const acquired = await keyStore.setItemWithExpiryNX(key, KeyStoreTtls.AlertChannelTestCooldownInSeconds, "1");
- if (!acquired) {
- // eslint-disable-next-line no-await-in-loop
- const remaining = await keyStore.ttl(key);
- const seconds = remaining > 0 ? remaining : KeyStoreTtls.AlertChannelTestCooldownInSeconds;
- throw new RateLimitError({
- message: `A ${channelType} test was already sent by ${scope} in the last minute. Try again in ${seconds}s.`
- });
- }
- }
+ const key = KeyStorePrefixes.AlertChannelTestCooldown(orgId, actorId, channelType);
+ const acquired = await keyStore.setItemWithExpiryNX(key, KeyStoreTtls.AlertChannelTestCooldownInSeconds, "1");
+ if (acquired) return;
+
+ const remaining = await keyStore.ttl(key);
+ const seconds = remaining > 0 ? remaining : KeyStoreTtls.AlertChannelTestCooldownInSeconds;
+ throw new RateLimitError({
+ message: `You already sent a ${channelType} test in the last minute. Try again in ${seconds}s.`
+ });
};
const $resolveConfig = async (dto: TTestAlertChannelDTO, projectId: string | null) => {
@@ -128,7 +120,7 @@ export const alertChannelTestServiceFactory = ({
return {
...payload,
severity: "info",
- summary: `Test notification from Infisical. A real ${payload.resourceKind} ${payload.eventLabel.toLowerCase()} alert would look like this. No action is needed.`
+ summary: `Test alert from Infisical. A real ${payload.resourceKind} ${payload.eventLabel.toLowerCase()} alert would look like this. No action is needed.`
};
};
diff --git a/backend/src/services/alert/alert-engine.test.ts b/backend/src/services/alert/alert-engine.test.ts
index 7fb99166c0..149c49a8c1 100644
--- a/backend/src/services/alert/alert-engine.test.ts
+++ b/backend/src/services/alert/alert-engine.test.ts
@@ -57,6 +57,7 @@ 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/frontend/src/views/Alerts/ChannelCard.tsx b/frontend/src/views/Alerts/ChannelCard.tsx
index a89d1c5af7..4400c6f979 100644
--- a/frontend/src/views/Alerts/ChannelCard.tsx
+++ b/frontend/src/views/Alerts/ChannelCard.tsx
@@ -78,8 +78,10 @@ export const ChannelCard = ({
if (result.success) {
createNotification({
- text: `Test ${channelLabel} notification sent${
- result.deliveredTo && result.deliveredTo > 1 ? ` to ${result.deliveredTo} recipients` : ""
+ text: `Test ${channelLabel} alert sent${
+ result.deliveredTo && result.deliveredTo > 1
+ ? ` to ${result.deliveredTo} recipients`
+ : ""
}`,
type: "success"
});