refactor(api): require permission key in create and update requests - #1885
refactor(api): require permission key in create and update requests#1885AmanGIT07 wants to merge 2 commits into
Conversation
CreatePermission and UpdatePermission read the permission identity only from the key field and return InvalidArgument when it is missing or malformed. The deprecated namespace/name request fields are no longer read. The seed command and e2e tests send keys. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe permission model now uses a consolidated ChangesPermission key migration
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The PR enforces key-only permission requests and updates the relevant callers and tests; no actionable merge-blocking risk remains. Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
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: 1
🧹 Nitpick comments (1)
internal/api/v1beta1connect/permission_test.go (1)
84-102: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winProve that deprecated fields are ignored.
The missing-key cases leave
NameandNamespaceempty. A future fallback to populated deprecated fields could pass these cases. Add CreatePermission and UpdatePermission cases withKeyempty,NameandNamespacepopulated, and expectCodeInvalidArgument.This follows the PR objective that deprecated request fields are no longer read.
Also applies to: 268-286
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 9a841b60-53d3-4101-b77a-15ff9171c906
📒 Files selected for processing (5)
cmd/seed.gocmd/seed/permissions.jsoninternal/api/v1beta1connect/permission.gointernal/api/v1beta1connect/permission_test.gotest/e2e/regression/service_registration_test.go
Coverage Report for CI Build 31793240068Coverage increased (+0.003%) to 48.701%Details
Uncovered Changes
Coverage Regressions1 previously-covered line in 1 file lost coverage.
Coverage Stats
💛 - Coveralls |
Missing or malformed keys now fail with a format-hint error instead of a generic bad request. Create validates the namespace form and Update applies the same name and namespace checks as Create. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/api/v1beta1connect/permission_test.go (1)
275-315: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winAdd an invalid-namespace case for
UpdatePermission.
internal/api/v1beta1connect/permission.goLine 120 has a separate namespace-validation branch.TestHandler_UpdatePermissioncovers missing keys, malformed keys, and invalid permission names, but it does not cover a three-part key with an invalid namespace. Add anapp..getcase and expectconnect.CodeInvalidArgumentwithErrPermissionKeyNotation.Based on the changed handler branch and the supplied test cases, this is the only new validation path without a direct regression case.
Proposed test case
+ { + name: "should return bad request error if key namespace is invalid", + setup: func(as *mocks.PermissionService) {}, + request: connect.NewRequest(&frontierv1beta1.UpdatePermissionRequest{ + Id: testPermissions[testPermissionIdx].ID, + Body: &frontierv1beta1.PermissionRequestBody{ + Key: "app..get", + }, + }), + want: nil, + wantErr: connect.NewError(connect.CodeInvalidArgument, ErrPermissionKeyNotation), + },
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: d7469106-ebfb-4b52-94ba-265fdc69e424
📒 Files selected for processing (3)
internal/api/v1beta1connect/errors.gointernal/api/v1beta1connect/permission.gointernal/api/v1beta1connect/permission_test.go
Summary
CreatePermission and UpdatePermission accept the permission identity only via the
keyfield (service.resource.verb). The deprecatednamespace/namerequest body fields are no longer read; requests sending only those fields now receive InvalidArgument. Part of #1782.Changes
internal/api/v1beta1connect/permission.go: remove the namespace/name fallback; reject a missing or malformed key in both CreatePermission and UpdatePermissioncmd/seed/permissions.json+cmd/seed.go: seed data sendskeytest/e2e/regression/service_registration_test.go: request bodies sendkeyinternal/api/v1beta1connect/permission_test.go: request bodies sendkey; add missing-key and malformed-key cases for both handlersTest Plan
go test ./internal/api/v1beta1connect/passesmake lintpasses (0 issues)🤖 Generated with Claude Code