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
test(secrets): cover rejected batch changes leaving the store untouched
Claude82cd3793322c
diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/SecretMainPage.store.test.ts b/frontend/src/pages/secret-manager/SecretDashboardPage/SecretMainPage.store.test.tsindex bdd2562188..fceed4b237 100644--- a/frontend/src/pages/secret-manager/SecretDashboardPage/SecretMainPage.store.test.ts+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/SecretMainPage.store.test.ts@@ -1,16 +1,20 @@import assert from "node:assert/strict";-import { describe, it } from "vitest";+import { describe, it, vi } from "vitest";import { createStore } from "zustand";+import { createNotification } from "@app/components/notifications";import { PendingAction } from "@app/hooks/api/secretFolders/types";import {BatchContext,BatchModeState,createBatchModeStore,+ PendingFolderCreate,PendingSecretCreate} from "./SecretMainPage.store";+vi.mock("@app/components/notifications", () => ({ createNotification: vi.fn() }));+const createTestStore = () =>createStore<BatchModeState>()((...args) =>createBatchModeStore(...(args as unknown as Parameters<typeof createBatchModeStore>))@@ -22,15 +26,24 @@ const contextFor = (environment: string): BatchContext => ({secretPath: "/test"});-const makeCreate = (id: string): PendingSecretCreate => ({+const makeCreate = (id: string, secretKey = "NEW_SECRET"): PendingSecretCreate => ({id,resourceType: "secret",type: PendingAction.Create,- secretKey: "NEW_SECRET",+ secretKey,secretValue: "value",timestamp: 1});+const makeFolderCreate = (id: string, folderName: string): PendingFolderCreate => ({+ id,+ resourceType: "folder",+ type: PendingAction.Create,+ folderName,+ parentPath: "/test",+ timestamp: 1+});+describe("batch mode store", () => {it("keeps the viewed environment when staging a create across several environments", () => {const store = createTestStore();@@ -57,4 +70,37 @@ describe("batch mode store", () => {["create-dev"]);});++ it("leaves the store untouched when a change for any environment is rejected", () => {+ const store = createTestStore();+ const { batchActions } = store.getState();++ batchActions.loadPendingChanges(contextFor("prod"));+ batchActions.setExistingKeys(["EXISTING_SECRET"], ["existing-folder"]);+ batchActions.addPendingChange(makeCreate("create-prod"), contextFor("prod"));+ batchActions.addPendingChange(makeCreate("create-dev"), contextFor("dev"));++ const before = store.getState();+ const rejectedChanges = [+ { change: makeCreate("dup-prod", "EXISTING_SECRET"), env: "prod" },+ { change: makeCreate("dup-dev", "EXISTING_SECRET"), env: "dev" },+ { change: makeFolderCreate("dup-folder-dev", "existing-folder"), env: "dev" }+ ];++ rejectedChanges.forEach(({ change, env }) => {+ batchActions.addPendingChange(change, contextFor(env));++ const after = store.getState();+ assert.equal(after.currentContext, before.currentContext);+ assert.equal(after.pendingChanges, before.pendingChanges);+ assert.equal(after.pendingChangesByContext, before.pendingChangesByContext);+ });++ assert.equal(vi.mocked(createNotification).mock.calls.length, rejectedChanges.length);+ assert.equal(store.getState().currentContext?.environment, "prod");+ assert.deepEqual(+ store.getState().pendingChanges.secrets.map((s) => s.id),+ ["create-prod"]+ );+ });});