Skip to content

[management] Enforce peer or peer groups requirement for network routers#5894

Merged
bcmmbaga merged 4 commits intomainfrom
fix/network-router-peer-validation
Apr 16, 2026
Merged

[management] Enforce peer or peer groups requirement for network routers#5894
bcmmbaga merged 4 commits intomainfrom
fix/network-router-peer-validation

Conversation

@bcmmbaga
Copy link
Copy Markdown
Contributor

@bcmmbaga bcmmbaga commented Apr 15, 2026

Describe your changes

Issue ticket number and link

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • Bug Fixes

    • Router creation and update now validate inputs and return Bad Request for invalid configurations. Routers must specify either a peer or peer groups (mutually exclusive) and cannot omit both; invalid requests are rejected with an error response.
  • Tests

    • Integration and unit tests updated to cover the new router validation rules and invalid-request scenarios.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cb002a27-f145-4707-b3bd-4ea2518dd05e

📥 Commits

Reviewing files that changed from the base of the PR and between 2d30c6b and ed041f6.

📒 Files selected for processing (1)
  • management/server/http/testing/integration/networks_handler_integration_test.go

📝 Walkthrough

Walkthrough

Added validation to router creation and update paths: handlers now call NetworkRouter.Validate() (after setting IDs and Enabled=true on create) and return 400 on validation errors. Validation logic was moved from the constructor into a new Validate() method enforcing mutual exclusivity and requiring at least one of Peer or PeerGroups.

Changes

Cohort / File(s) Summary
Handler Validation
management/server/http/handlers/networks/routers_handler.go
Handlers createRouter and updateRouter now call router.Validate() after populating IDs (and setting Enabled=true for create); on validation failure they write a 400 BadRequest and stop before manager calls.
Router Type Validation
management/server/networks/routers/types/router.go
Moved validation out of NewNetworkRouter into a new exported Validate() error on *NetworkRouter; enforces mutual exclusivity between Peer and PeerGroups (peer_groups) and requires at least one to be present.
Unit Tests
management/server/networks/routers/types/router_test.go
Updated TestNewNetworkRouter cases to mark missing both Peer and PeerGroups as invalid; added case for empty PeerGroups slice without Peer.
Integration Tests
management/server/http/testing/integration/networks_handler_integration_test.go
Adjusted create/update router integration tests to expect http.StatusBadRequest for requests violating the new peer/peer_groups validation; added test cases for missing peer targeting fields.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • crn4
  • pascal-fischer

Poem

🐰 I checked each route with cautious paws,
Peer or groups — now that's the laws.
Handlers listen, then I say "nope,"
Validation hops in — steady hope.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description follows the repository template with checklist items marked, but lacks detailed explanation of what changes were made and why they were necessary. Add a detailed description of the validation changes, explain why peer or peer-groups requirement is needed, and clarify why tests were not created despite this being marked as both a bug fix and refactor.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: enforcing a peer or peer groups requirement for network routers, which aligns with the file changes and validation logic added.

✏️ 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 fix/network-router-peer-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.

@sonarqubecloud
Copy link
Copy Markdown

@bcmmbaga bcmmbaga merged commit 08f6245 into main Apr 16, 2026
63 of 64 checks passed
@bcmmbaga bcmmbaga deleted the fix/network-router-peer-validation branch April 16, 2026 10:12
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.

3 participants