fix(secrets): block duplicate secret names to prevent value loss#8750
fix(secrets): block duplicate secret names to prevent value loss#8750pooja-bruno wants to merge 4 commits into
Conversation
WalkthroughDuplicate secret names are now validated in environment editors and save flows. Inline errors target the edited row, duplicate saves show a dedicated toast, and environment tabs display enabled-variable counts with unsaved styling. Tests and locators cover both collection and global environments. ChangesEnvironment validation and indicators
Estimated code review effort: 3 (Moderate) | ~25 minutes Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant EnvironmentEditor
participant SaveFlow
participant RequestTab
participant Toast
EnvironmentEditor->>SaveFlow: submit environment variables
SaveFlow->>SaveFlow: detect duplicate secret names
SaveFlow-->>RequestTab: reject duplicate save
RequestTab->>Toast: show duplicate-name error
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/bruno-app/src/components/RequestTabs/RequestTab/index.js (1)
257-281: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winUse
showSaveErrorin both Save & Close flows.The handlers at Lines 443-446 and 494-497 still replace the duplicate-secret rejection with generic errors, so closing a tab after creating duplicate secrets does not show the new actionable message.
Proposed fix
- .catch((err) => { - console.log('err', err); - toast.error('Failed to save environment'); - }); + .catch(showSaveError);Apply the equivalent change to the global-environment Save & Close handler.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/bruno-app/src/components/RequestTabs/RequestTab/index.js` around lines 257 - 281, Update both Save & Close handlers, including the global-environment handler, to use the existing showSaveError callback when their save promises reject. Replace the generic error toast handling while preserving the current success behavior and duplicate-secret message.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/environments/environment-tabs/environment-tabs.spec.ts`:
- Around line 181-207: Update the environment-tab scenarios at
tests/environments/environment-tabs/environment-tabs.spec.ts:181-207 and
:579-605 to assert the visible Variables and Secrets tab-count text after each
row is added and again after saving, using the expected enabled-item counts.
Retain the existing unsaved-class assertions, and apply the same count-text
coverage to the global-environments scenario.
In `@tests/utils/page/actions.ts`:
- Around line 844-855: Update addDuplicateRow so its CodeMirror editor click
targets the left edge, matching addRowToActiveTab, before typing the duplicate
value. Preserve the existing duplicate-row selection and keyboard typing flow.
---
Outside diff comments:
In `@packages/bruno-app/src/components/RequestTabs/RequestTab/index.js`:
- Around line 257-281: Update both Save & Close handlers, including the
global-environment handler, to use the existing showSaveError callback when
their save promises reject. Replace the generic error toast handling while
preserving the current success behavior and duplicate-secret message.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: b84263fd-cecb-42a7-8215-f1a973fd1c07
📒 Files selected for processing (14)
packages/bruno-app/src/components/EnvironmentVariablesTable/index.jspackages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/StyledWrapper.jspackages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/index.jspackages/bruno-app/src/components/RequestTabs/RequestTab/index.jspackages/bruno-app/src/components/WorkspaceHome/WorkspaceEnvironments/EnvironmentList/EnvironmentDetails/StyledWrapper.jspackages/bruno-app/src/components/WorkspaceHome/WorkspaceEnvironments/EnvironmentList/EnvironmentDetails/index.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/actions.jspackages/bruno-app/src/providers/ReduxStore/slices/global-environments.jspackages/bruno-app/src/utils/environments.jspackages/bruno-app/src/utils/environments.spec.jstests/environments/environment-tabs/environment-tabs.spec.tstests/utils/page/actions.tstests/utils/page/locators.tstests/utils/page/toast.ts
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
tests/environments/environment-tabs/environment-tabs.spec.ts (1)
13-13: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winKeep selectors in shared page locators.
tests/environments/environment-tabs/environment-tabs.spec.ts#L13-L13: move the row-name-input locator totests/utils/page/locators.ts.tests/environments/environment-tabs/environment-tabs.spec.ts#L203-L211: usetoastByMessage()for success-toast assertions.tests/environments/environment-tabs/environment-tabs.spec.ts#L654-L662: usetoastByMessage()for success-toast assertions.As per path instructions, specs should consume page-module locators and reusable toast locator builders.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/environments/environment-tabs/environment-tabs.spec.ts` at line 13, The environment-tabs spec should use shared locators instead of defining or asserting UI selectors locally: move varNameInput into tests/utils/page/locators.ts, update its usages to consume the shared page locator, and replace the success-toast assertions at tests/environments/environment-tabs/environment-tabs.spec.ts lines 203-211 and 654-662 with toastByMessage().Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/environments/environment-tabs/environment-tabs.spec.ts`:
- Around line 444-448: Remove the negative success-toast assertions from both
affected test steps in
tests/environments/environment-tabs/environment-tabs.spec.ts at lines 444-448
and 892-896. Keep the saveEnvironment call and positive DUPLICATE_SECRET_TOAST
visibility assertion, and do not add other negative toast assertions.
- Around line 873-904: The existing global-environment coverage only verifies
duplicate secret rejection; add a Variables-tab case that creates duplicate
variable names and confirms saving succeeds. Anchor the test near “blocks saving
two secrets that share a name,” use the global environment setup and Variables
tab, and assert the successful-save toast without expecting duplicate-variable
errors.
---
Nitpick comments:
In `@tests/environments/environment-tabs/environment-tabs.spec.ts`:
- Line 13: The environment-tabs spec should use shared locators instead of
defining or asserting UI selectors locally: move varNameInput into
tests/utils/page/locators.ts, update its usages to consume the shared page
locator, and replace the success-toast assertions at
tests/environments/environment-tabs/environment-tabs.spec.ts lines 203-211 and
654-662 with toastByMessage().
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 71b6a738-033d-463b-bcf4-824e6c18486f
📒 Files selected for processing (1)
tests/environments/environment-tabs/environment-tabs.spec.ts
Description
Fixes a data-loss bug in the Secrets tab (collection and global environments).
Adding two secrets with the same name and saving silently dropped the first one's value. Secret values are persisted in a separate name-keyed store and re-hydrated by first-match on read, so a second secret with a duplicate name overwrote the first on save. (The Variables tab is unaffected those values live inline in the .bru/env file, so duplicates are allowed there and lose nothing.
JIRA
Contribution Checklist:
Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.
Publishing to New Package Managers
Please see here for more information.
Summary by CodeRabbit
<sup>counts for enabled variables/secrets with non-empty names.Screen.Recording.2026-07-23.at.6.16.36.PM.mov