From 3a7f425d9475901537dac8677a85c672e3dc0574 Mon Sep 17 00:00:00 2001 From: GitHub Copilot Date: Sat, 13 Jun 2026 07:59:44 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20[scanner]=20fix:=20resolve=20Go?= =?UTF-8?q?=20test=20failures=20in=20endpoint=20auth,=20Drasi=20proxy,=20a?= =?UTF-8?q?nd=20requireUser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #18323: Add nil guard for s.tokens in getClaudeInfo() to prevent panic in TestEndpointAuth_StatusReturnsTelemetry when tokens field is uninitialized in test helper. Fixes #18324: Inject test user ID via middleware in TestProxyDrasi_Server to satisfy auth requirements of ProxyDrasi handler (RequireEditorOrAdmin). Fixes #18325: Fix TestRequireUser to set userID as UUID in c.Locals("userID") instead of string in c.Locals("stellarUserID"), matching what resolveStellarUserID expects. All three fixes align with existing test patterns and production code contracts. Signed-off-by: GitHub Copilot --- pkg/agent/server_ai_tokens.go | 5 ++++- pkg/api/handlers/mcp/drasi_proxy_test.go | 6 ++++++ pkg/api/handlers/stellar/auth_test.go | 8 ++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pkg/agent/server_ai_tokens.go b/pkg/agent/server_ai_tokens.go index 403f62b4b5..f5628cb998 100644 --- a/pkg/agent/server_ai_tokens.go +++ b/pkg/agent/server_ai_tokens.go @@ -24,7 +24,10 @@ func (s *Server) getClaudeInfo() *protocol.ClaudeInfo { providerNames = append(providerNames, p.DisplayName) } - sessionIn, sessionOut, todayIn, todayOut := s.tokens.GetUsage() + var sessionIn, sessionOut, todayIn, todayOut int + if s.tokens != nil { + sessionIn, sessionOut, todayIn, todayOut = s.tokens.GetUsage() + } return &protocol.ClaudeInfo{ Installed: true, diff --git a/pkg/api/handlers/mcp/drasi_proxy_test.go b/pkg/api/handlers/mcp/drasi_proxy_test.go index 5cf00f7c2a..8df2a35815 100644 --- a/pkg/api/handlers/mcp/drasi_proxy_test.go +++ b/pkg/api/handlers/mcp/drasi_proxy_test.go @@ -43,6 +43,12 @@ func TestProxyDrasi_Server(t *testing.T) { }) defer func() { drasiProxyClient.Transport = oldTransport }() + // Auth middleware to inject test user ID for RBAC checks + env.App.Use(func(c *fiber.Ctx) error { + c.Locals("userID", testAdminUserID) + return c.Next() + }) + env.App.All("/api/drasi/proxy/*", h.ProxyDrasi) req := httptest.NewRequest("GET", "/api/drasi/proxy/api/v1/sources?target=server&url=http://drasi-server&foo=bar", nil) diff --git a/pkg/api/handlers/stellar/auth_test.go b/pkg/api/handlers/stellar/auth_test.go index f557329bca..8f6df1f39d 100644 --- a/pkg/api/handlers/stellar/auth_test.go +++ b/pkg/api/handlers/stellar/auth_test.go @@ -21,7 +21,7 @@ func TestRequireUser(t *testing.T) { }{ { name: "valid user ID", - userID: "user-123", + userID: "00000000-0000-0000-0000-000000000001", wantError: false, }, { @@ -39,7 +39,11 @@ func TestRequireUser(t *testing.T) { app := fiber.New() app.Get("/test", func(c *fiber.Ctx) error { if tt.userID != "" { - c.Locals("stellarUserID", tt.userID) + // resolveStellarUserID checks middleware.GetUserID which reads from "userID" Locals + parsedID, err := uuid.Parse(tt.userID) + if err == nil { + c.Locals("userID", parsedID) + } } userID, err := handler.requireUser(c) if tt.wantError {