console: person-only scan matches bare principalFrom calls
assertBodyResolvesOnlyPersons matched selectors only, so a plain handler calling the package function principalFrom (a bare identifier) passed. It now matches identifiers, which covers selectors' names too. Found by the plan's mutation 8.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+6
−4
internal/console/svcroutes_test.go+6 −4
diff --git a/internal/console/svcroutes_test.go b/internal/console/svcroutes_test.go| index b849698c9..f22b2da09 100644 |
| --- a/internal/console/svcroutes_test.go |
| +++ b/internal/console/svcroutes_test.go |
| @@ -1312,21 +1312,23 @@ func assertResolvesOnlyPersons(t *testing.T, src *cliSource, what string, fd *as |
| // a bearer by any route other than cliUser. CLIPrincipal answers for a |
| // SERVICE credential and CLITokenAddress is the raw resolver cliUser wraps; |
| // a handler over here calling either one has stopped being person-only, and |
| -// that is precisely the drift this catches. |
| +// that is precisely the drift this catches. It matches identifiers, not |
| +// only selectors: principalFrom is a package function, so a call of it is |
| +// a bare name that a selector-only match would never see. |
| func assertBodyResolvesOnlyPersons(t *testing.T, src *cliSource, what string, body *ast.BlockStmt) { |
| t.Helper() |
| if body == nil { |
| return |
| } |
| ast.Inspect(body, func(n ast.Node) bool { |
| - sel, ok := n.(*ast.SelectorExpr) |
| + id, ok := n.(*ast.Ident) |
| if !ok { |
| return true |
| } |
| - switch sel.Sel.Name { |
| + switch id.Name { |
| case "CLIPrincipal", "CLITokenAddress", "principalFrom": |
| t.Errorf("%s: resolves a bearer through %s at %s — the /auth/cli/ family must go through cliUser, which answers only for a person", |
| - what, sel.Sel.Name, src.fset.Position(sel.Pos())) |
| + what, id.Name, src.fset.Position(id.Pos())) |
| } |
| return true |
| }) |