fix: allow any HTTP method for /api/auth/envoy#551
Conversation
…for non-envoy proxies
📝 WalkthroughWalkthroughConsolidated proxy routing into a single catch-all route and added runtime method validation: non-envoy proxies are limited to GET (405 + Allow header returned for other methods); envoy proxies bypass the method restriction. Tests expanded to cover the new behaviors. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #551 +/- ##
==========================================
+ Coverage 20.08% 20.34% +0.25%
==========================================
Files 37 37
Lines 2166 2173 +7
==========================================
+ Hits 435 442 +7
Misses 1701 1701
Partials 30 30 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
internal/controller/proxy_controller.go (1)
72-82: Method validation logic is correct. Consider adding Allow header for HTTP spec compliance.The implementation correctly enforces method restrictions for non-envoy proxies. The error handling and logging are appropriate.
For improved HTTP specification compliance, consider adding an
Allowheader to the 405 response indicating which methods are permitted:🔎 Proposed enhancement
if req.Proxy != "envoy" && c.Request.Method != http.MethodGet { log.Warn().Str("method", c.Request.Method).Msg("Invalid method for proxy") + c.Header("Allow", "GET") c.JSON(405, gin.H{ "status": 405, "message": "Method Not Allowed", }) return }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
internal/controller/proxy_controller.gointernal/controller/proxy_controller_test.go
🔇 Additional comments (4)
internal/controller/proxy_controller_test.go (3)
84-89: LGTM! Good test coverage for method validation.The test correctly verifies that non-envoy proxies (traefik) reject non-GET methods with a 405 status code, aligning with the new method restriction logic.
103-103: LGTM! Comment clarity improvement.The updated comment better distinguishes this test case from the new DELETE method test, improving test documentation.
115-125: LGTM! Comprehensive test coverage for envoy DELETE method.The test properly validates that envoy accepts DELETE requests and handles unauthenticated users correctly by redirecting to the login page with the appropriate redirect URI.
internal/controller/proxy_controller.go (1)
46-47: LGTM! Route consolidation improves flexibility.Using
Any()for the route registration allows for runtime method-based access control, which is cleaner than registering separate routes per method. The comment appropriately explains the design decision.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
internal/controller/proxy_controller.gointernal/controller/proxy_controller_test.go
🔇 Additional comments (4)
internal/controller/proxy_controller.go (1)
46-47: LGTM! Clean route consolidation.The switch to a single
Any()route with runtime method validation is a cleaner approach than registering separate per-method routes. The comment clearly explains the deferred validation strategy.internal/controller/proxy_controller_test.go (3)
84-90: LGTM! Proper test coverage for method validation.This test correctly verifies that non-envoy proxies reject non-GET methods with 405 and the appropriate Allow header.
104-104: Good clarification in test comments.The updated comment improves readability by explicitly noting the HTTP method being tested.
116-126: LGTM! Comprehensive envoy method coverage.This test effectively verifies that the envoy endpoint accepts multiple HTTP methods (DELETE in this case) and behaves consistently with the POST test. This confirms the "any method" allowance for envoy is working correctly.
Re-introduces changes that were reverted in #540. Envoy endpoint must respond on any standard HTTP methods. Added better code comments for clarity.
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.