From f748b8cb39194a72416de88259e5a912e7ca8f66 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 7 Mar 2026 02:50:17 +0000 Subject: [PATCH] fix: initialize jwt_handler.litellm_jwtauth in JWT test The test_jwt_non_admin_team_route_access test was failing because user_api_key_auth now accesses jwt_handler.litellm_jwtauth.virtual_key_claim_field before reaching the mocked JWTAuthManager.auth_builder. Initialize the jwt_handler with a default LiteLLM_JWTAuth object. Co-authored-by: Ishaan Jaff --- tests/proxy_unit_tests/test_user_api_key_auth.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/proxy_unit_tests/test_user_api_key_auth.py b/tests/proxy_unit_tests/test_user_api_key_auth.py index 89543e42956..1a6e2eda9a1 100644 --- a/tests/proxy_unit_tests/test_user_api_key_auth.py +++ b/tests/proxy_unit_tests/test_user_api_key_auth.py @@ -1044,6 +1044,18 @@ async def test_jwt_non_admin_team_route_access(monkeypatch): litellm.proxy.proxy_server, "general_settings", {"enable_jwt_auth": True} ) + # Initialize jwt_handler with a default LiteLLM_JWTAuth so that the + # virtual_key_claim_field check in user_api_key_auth doesn't fail with + # "JWTHandler has no attribute 'litellm_jwtauth'" + from litellm.proxy._types import LiteLLM_JWTAuth + from litellm.caching.dual_cache import DualCache + + litellm.proxy.proxy_server.jwt_handler.update_environment( + prisma_client=None, + user_api_key_cache=DualCache(), + litellm_jwtauth=LiteLLM_JWTAuth(), + ) + # Mock enterprise license check and JWTAuthManager.auth_builder # License check must be mocked to avoid environment variable pollution # in parallel test execution