-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
fix: populate identity fields in proxy admin JWT early-return path #21169
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
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 |
|---|---|---|
|
|
@@ -422,3 +422,77 @@ async def test_return_user_api_key_auth_obj_user_spend_and_budget(): | |
| assert result.user_tpm_limit == 1000 | ||
| assert result.user_rpm_limit == 100 | ||
| assert result.user_email == "test@example.com" | ||
|
|
||
|
|
||
| def test_proxy_admin_jwt_auth_includes_identity_fields(): | ||
| """ | ||
| Test that the proxy admin early-return path in JWT auth populates | ||
| user_id, team_id, team_alias, team_metadata, org_id, and end_user_id. | ||
|
|
||
| Regression test: previously the is_proxy_admin branch only set user_role | ||
| and parent_otel_span, discarding all identity fields resolved from the JWT. | ||
| This caused blank Team Name and Internal User in Request Logs UI. | ||
| """ | ||
| from litellm.proxy._types import LiteLLM_TeamTable, LitellmUserRoles, UserAPIKeyAuth | ||
|
|
||
| team_object = LiteLLM_TeamTable( | ||
| team_id="team-123", | ||
| team_alias="my-team", | ||
| metadata={"tags": ["prod"], "env": "production"}, | ||
| ) | ||
|
|
||
| # Simulate the proxy admin early-return path (user_api_key_auth.py ~line 586) | ||
| result = UserAPIKeyAuth( | ||
| api_key=None, | ||
| user_role=LitellmUserRoles.PROXY_ADMIN, | ||
| user_id="user-abc", | ||
| team_id="team-123", | ||
| team_alias=( | ||
| team_object.team_alias if team_object is not None else None | ||
| ), | ||
| team_metadata=team_object.metadata if team_object is not None else None, | ||
| org_id="org-456", | ||
| end_user_id="end-user-789", | ||
| parent_otel_span=None, | ||
| ) | ||
|
|
||
| assert result.user_role == LitellmUserRoles.PROXY_ADMIN | ||
| assert result.user_id == "user-abc" | ||
| assert result.team_id == "team-123" | ||
| assert result.team_alias == "my-team" | ||
| assert result.team_metadata == {"tags": ["prod"], "env": "production"} | ||
| assert result.org_id == "org-456" | ||
| assert result.end_user_id == "end-user-789" | ||
| assert result.api_key is None | ||
|
Comment on lines
+427
to
+466
Contributor
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. Tests don't exercise the actual auth code path Both new tests construct a Consider adding a test that mocks the JWT auth flow (similar to |
||
|
|
||
|
|
||
| def test_proxy_admin_jwt_auth_handles_no_team_object(): | ||
| """ | ||
| Test that the proxy admin early-return path works correctly when | ||
| team_object is None (user has admin role but no team association). | ||
| """ | ||
| from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth | ||
|
|
||
| team_object = None | ||
|
|
||
| result = UserAPIKeyAuth( | ||
| api_key=None, | ||
| user_role=LitellmUserRoles.PROXY_ADMIN, | ||
| user_id="admin-user", | ||
| team_id=None, | ||
| team_alias=( | ||
| team_object.team_alias if team_object is not None else None | ||
| ), | ||
| team_metadata=team_object.metadata if team_object is not None else None, | ||
| org_id=None, | ||
| end_user_id=None, | ||
| parent_otel_span=None, | ||
| ) | ||
|
|
||
| assert result.user_role == LitellmUserRoles.PROXY_ADMIN | ||
| assert result.user_id == "admin-user" | ||
| assert result.team_id is None | ||
| assert result.team_alias is None | ||
| assert result.team_metadata is None | ||
| assert result.org_id is None | ||
| assert result.end_user_id is None | ||
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.
Inconsistent parenthesization with
team_aliasThe
team_metadataternary expression lacks the explicit parentheses thatteam_alias(line 592-596) uses. While this works correctly due to operator precedence, the inconsistent style reduces readability within the same block.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!