-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(base): classify Base resource permission denials as typed errors #2125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,6 +118,38 @@ func TestHandleBaseAPIResultClassifiesKnownPermissionCode(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestHandleBaseAPIResultClassifiesBaseResourcePermission(t *testing.T) { | ||
| result := map[string]interface{}{ | ||
| "code": 91403, | ||
| "msg": "you don't have permission", | ||
| "data": map[string]interface{}{}, | ||
| } | ||
|
|
||
| _, err := handleBaseAPIResultAny(result, nil, "list dashboards") | ||
| p, ok := errs.ProblemOf(err) | ||
| if !ok { | ||
| t.Fatalf("expected typed error, got %T %v", err, err) | ||
| } | ||
| if p.Code != 91403 { | ||
| t.Fatalf("code=%d", p.Code) | ||
| } | ||
| if p.Category != errs.CategoryAuthorization || p.Subtype != errs.SubtypePermissionDenied { | ||
| t.Fatalf("category/subtype=%s/%s", p.Category, p.Subtype) | ||
| } | ||
| perm, ok := err.(*errs.PermissionError) | ||
| if !ok { | ||
| t.Fatalf("err=%T, want *errs.PermissionError", err) | ||
| } | ||
| if perm.Identity != "current identity" { | ||
| t.Fatalf("identity=%q", perm.Identity) | ||
| } | ||
| for _, want := range []string{"resource access denied", "Base owner", "Do not run auth login"} { | ||
| if !strings.Contains(p.Hint, want) { | ||
| t.Fatalf("hint=%q missing %q", p.Hint, want) | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+121
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Cover the new metadata branches directly. Add a As per coding guidelines, “Every behavior change must have an accompanying test, and contract tests must assert the changed field or behavior directly.” 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
| func TestAttachBaseResponseLogIDFromHeader(t *testing.T) { | ||
| result := map[string]interface{}{ | ||
| "code": 91402, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Keep
PermissionError.Identitywithin the classifier contract."current identity"is display text, butClassifyContext.Identityis defined as"user","bot", or empty. Preserve an emptyerr.Identitywhen unresolved; use a separate fallback only in the hint. Otherwise downstream identity-based handling receives an undocumented value.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents