Skip to content

Remove front end name validation for add certificate modal - #47242

Merged
ksykulev merged 1 commit into
mainfrom
44821-name-validation
Jun 10, 2026
Merged

Remove front end name validation for add certificate modal#47242
ksykulev merged 1 commit into
mainfrom
44821-name-validation

Conversation

@ksykulev

@ksykulev ksykulev commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Related issue: Resolves #44821
Related PR: #46414

key to note that the server side validation is now the only validation that will happen to detect duplicate names.

Testing

  • Added/updated automated tests
  • QA'd all new/changed functionality manually

For unreleased bug fixes in a release candidate, one of:

  • Confirmed that the fix is not expected to adversely impact load test results

Summary by CodeRabbit

  • Refactor

    • Removed client-side duplicate certificate name validation; certificate name uniqueness is now validated server-side.
  • Tests

    • Updated certificate validation tests to reflect server-side validation approach.

Copilot AI review requested due to automatic review settings June 9, 2026 22:29
@ksykulev
ksykulev requested a review from a team as a code owner June 9, 2026 22:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the Add certificate modal’s client-side “duplicate name” validation (which only worked for certificates in the current paginated page) so that duplicate detection relies on server-side validation and the server error is surfaced inline.

Changes:

  • Removed existingCerts/ICertificate plumbing and the client-side “unique name” validation rule from the modal.
  • Updated the modal to build validations without needing the certificates list.
  • Updated tests and certificates card wiring to match the new modal API.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
frontend/pages/ManageControlsPage/OSSettings/cards/Certificates/components/AddCertificateModal/helpers.ts Removes client-side uniqueness validation and the existingCerts dependency from validation generation.
frontend/pages/ManageControlsPage/OSSettings/cards/Certificates/components/AddCertificateModal/AddCertificateModal.tsx Removes existingCerts prop usage and updates memoized validation generation accordingly.
frontend/pages/ManageControlsPage/OSSettings/cards/Certificates/components/AddCertificateModal/AddCertificateModal.tests.tsx Removes the “duplicate name as you type” test and updates rendering helper to the new modal props.
frontend/pages/ManageControlsPage/OSSettings/cards/Certificates/Certificates.tsx Stops passing existingCerts into the Add certificate modal.
Comments suppressed due to low confidence (1)

frontend/pages/ManageControlsPage/OSSettings/cards/Certificates/components/AddCertificateModal/AddCertificateModal.tests.tsx:146

  • Now that client-side uniqueness validation was removed, the name-conflict path is only exercised on submit via server response parsing. There’s no test asserting that a 409/"already exists" error is surfaced inline on the Name field (and cleared on edit), so regressions would likely reintroduce the original UX (generic flash only).
  it("shows inline error for Name longer than 255 characters as user types", async () => {
    const { user } = await renderModal();

    // Paste rather than type to keep the test fast (256 simulated keypresses is slow).
    await user.click(screen.getByPlaceholderText(NAME_PLACEHOLDER));

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.14%. Comparing base (416f974) to head (93680c2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #47242      +/-   ##
==========================================
- Coverage   67.14%   67.14%   -0.01%     
==========================================
  Files        3045     3045              
  Lines      226606   226600       -6     
  Branches    11831    11830       -1     
==========================================
- Hits       152150   152144       -6     
  Misses      60717    60717              
  Partials    13739    13739              
Flag Coverage Δ
frontend 57.83% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR removes client-side duplicate certificate name validation from the AddCertificateModal component. The existingCerts prop is removed from the modal's props interface, the generateFormValidations function no longer accepts or checks against existing certificates, and the USED_NAME_MSG constant is deleted. The parent component stops passing the existingCerts prop, and tests are updated to remove validation of duplicate name errors. This shifts duplicate name detection from client-side (which was incomplete, checking only against visible page items) to server-side validation.

Possibly related PRs

  • fleetdm/fleet#46414: Adds server-side handling to surface duplicate name 422 conflicts inline in AddCertificateModal, complementing this PR's removal of incomplete client-side duplicate checking.
  • fleetdm/fleet#44809: Modifies AddCertificateModal validation logic; overlaps with this PR's removal of the existingCerts-driven props interface and duplicate-name validation contract.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning PR description is incomplete; missing several required sections and detailed explanations of changes and testing scope. Add: detailed description of what was changed and why, comprehensive explanation of testing approach, checklist items for changes files, input validation, compatibility checks, and database/configuration sections as applicable.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: removal of frontend name validation for the Add Certificate modal, which is directly supported by all file changes.
Linked Issues check ✅ Passed The changes fully address issue #44821 by removing the client-side duplicate-name validation that only checked the current paginated page, shifting all duplicate detection to server-side validation where all certificates are checked.
Out of Scope Changes check ✅ Passed All changes are narrowly scoped to removing frontend name validation: the existingCerts prop was removed, USED_NAME_MSG was deleted, generateFormValidations no longer accepts or checks for duplicates, and tests were updated accordingly.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 44821-name-validation

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
frontend/pages/ManageControlsPage/OSSettings/cards/Certificates/components/AddCertificateModal/AddCertificateModal.tests.tsx (1)

201-243: ⚡ Quick win

Consider adding a test for server-side duplicate name error handling.

The existing test verifies that server-side SAN validation errors are properly surfaced inline. Since this PR shifts duplicate name detection to server-side validation (the core fix for issue #44821), adding a similar test for duplicate name errors would document the expected behavior and prevent regression.

The test would follow the same pattern: mock a 422 response with an "already exists" error, submit the form, verify the error appears inline against the Name field, then verify that editing the Name field clears the error.

🧪 Example test to add
it("surfaces a 422 duplicate name error against the Name input inline", async () => {
  const DUPLICATE_NAME_ERR = "Certificate name already exists";
  mockServer.use(
    http.post(baseUrl("/certificates"), () => {
      return HttpResponse.json(
        {
          message: "Validation Failed",
          errors: [
            { name: "name", reason: `Certificate with name "Test Cert" already exists` },
          ],
        },
        { status: 422 }
      );
    })
  );

  const { user } = await renderModal();

  const nameInput = screen.getByPlaceholderText(NAME_PLACEHOLDER);
  await user.type(nameInput, "Test Cert");
  await user.type(
    screen.getByPlaceholderText(SUBJECT_NAME_PLACEHOLDER),
    "/CN=test/O=Org"
  );
  await selectScepCa(user);
  await user.click(screen.getByRole("button", { name: /Add/i }));

  await waitFor(() => {
    expect(screen.getByText("Name is already used by another certificate.")).toBeInTheDocument();
  });
  expect(mockOnSuccess).not.toHaveBeenCalled();

  // Editing the Name clears the server error.
  await user.type(nameInput, " Modified");
  await waitFor(() => {
    expect(screen.queryByText("Name is already used by another certificate.")).not.toBeInTheDocument();
  });
});
🤖 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
`@frontend/pages/ManageControlsPage/OSSettings/cards/Certificates/components/AddCertificateModal/AddCertificateModal.tests.tsx`
around lines 201 - 243, Add a new test in AddCertificateModal.tests.tsx
mirroring the SAN test: mockServer.post to return a 422 JSON with errors: [{
name: "name", reason: 'Certificate with name "Test Cert" already exists' }],
then use renderModal(), fill the NAME_PLACEHOLDER input (use NAME_PLACEHOLDER to
locate the field), fill SUBJECT_NAME_PLACEHOLDER and selectScepCa(user), click
the Add button, waitFor the inline message "Name is already used by another
certificate." to appear and assert mockOnSuccess was not called, then type into
the name input (e.g. " Modified") and waitFor the server error to be cleared
(queryByText returns null).
🤖 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.

Nitpick comments:
In
`@frontend/pages/ManageControlsPage/OSSettings/cards/Certificates/components/AddCertificateModal/AddCertificateModal.tests.tsx`:
- Around line 201-243: Add a new test in AddCertificateModal.tests.tsx mirroring
the SAN test: mockServer.post to return a 422 JSON with errors: [{ name: "name",
reason: 'Certificate with name "Test Cert" already exists' }], then use
renderModal(), fill the NAME_PLACEHOLDER input (use NAME_PLACEHOLDER to locate
the field), fill SUBJECT_NAME_PLACEHOLDER and selectScepCa(user), click the Add
button, waitFor the inline message "Name is already used by another
certificate." to appear and assert mockOnSuccess was not called, then type into
the name input (e.g. " Modified") and waitFor the server error to be cleared
(queryByText returns null).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 917c78cd-388a-4cae-9799-07027eb1e0c0

📥 Commits

Reviewing files that changed from the base of the PR and between 416f974 and 93680c2.

📒 Files selected for processing (4)
  • frontend/pages/ManageControlsPage/OSSettings/cards/Certificates/Certificates.tsx
  • frontend/pages/ManageControlsPage/OSSettings/cards/Certificates/components/AddCertificateModal/AddCertificateModal.tests.tsx
  • frontend/pages/ManageControlsPage/OSSettings/cards/Certificates/components/AddCertificateModal/AddCertificateModal.tsx
  • frontend/pages/ManageControlsPage/OSSettings/cards/Certificates/components/AddCertificateModal/helpers.ts
💤 Files with no reviewable changes (1)
  • frontend/pages/ManageControlsPage/OSSettings/cards/Certificates/Certificates.tsx

@ksykulev
ksykulev merged commit 52bd0bc into main Jun 10, 2026
25 checks passed
@ksykulev
ksykulev deleted the 44821-name-validation branch June 10, 2026 15:39
ksykulev added a commit that referenced this pull request Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android: Add certificate modal misses cross-page name conflicts

3 participants