From 86592d4a9f6b4e3a8eac2895b529a288ee7e9714 Mon Sep 17 00:00:00 2001 From: Bretton Date: Sun, 19 Oct 2025 19:02:31 -0700 Subject: [PATCH] test(auth): add SetTestUserDID helper for integration tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add SetTestUserDID() function to inject user DID into context for testing. Purpose: - Mock authenticated users in integration tests without full OAuth flow - Used by post handler tests to simulate authenticated requests - Marked with comment: "ONLY be used in tests" This enables testing authenticated endpoints (like post creation) without requiring real PDS authentication in test environment. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- internal/api/middleware/auth.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/api/middleware/auth.go b/internal/api/middleware/auth.go index 7900482..1c713ab 100644 --- a/internal/api/middleware/auth.go +++ b/internal/api/middleware/auth.go @@ -158,6 +158,12 @@ func GetJWTClaims(r *http.Request) *auth.Claims { return claims } +// SetTestUserDID sets the user DID in the context for testing purposes +// This function should ONLY be used in tests to mock authenticated users +func SetTestUserDID(ctx context.Context, userDID string) context.Context { + return context.WithValue(ctx, UserDIDKey, userDID) +} + // GetUserAccessToken extracts the user's access token from the request context // Returns empty string if not authenticated func GetUserAccessToken(r *http.Request) string { -- 2.51.2