litellm/tests/test_litellm/proxy/auth
Shivam Rawat 7e57b15de2
fix(guardrails): team-level guardrails and global policy guardrails can run together (#26466)
* fix(guardrails): apply team-level guardrails alongside global policy guardrails

Two bugs prevented team-direct guardrails from being automatically applied
when using a team-scoped API key:

1. Auth caching: `valid_token.team_metadata` was never refreshed from the
   freshly-fetched team object at the "Check 6" step in
   `_user_api_key_auth_builder`. Guardrails added to a team after the key
   was first cached were therefore invisible to `move_guardrails_to_metadata`.
   Fix: propagate `_team_obj.metadata` → `valid_token.team_metadata` after
   every "Check 6" team fetch (user_api_key_auth.py).

2. Guardrail execution: `get_guardrail_from_metadata` checked
   `data["litellm_metadata"]` before `data["metadata"]`. When a request
   carried a non-empty `litellm_metadata` without a "guardrails" key, the
   merged guardrail list written to `data["metadata"]` by
   `move_guardrails_to_metadata` was shadowed and the guardrail received an
   empty requested-guardrails list (custom_guardrail.py).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix merge conflict

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-25 14:45:06 -07:00
..
test_auth_checks.py
test_auth_exception_handler.py
test_auth_hot_path_network_requests.py
test_auth_utils.py
test_cli_auth.py
test_custom_auth_end_user_budget.py
test_handle_jwt.py
test_info_routes.py
test_litellm_license.py
test_login_utils.py
test_mcp_ip_filtering.py
test_model_checks_fallbacks.py
test_model_checks.py
test_multi_budget_windows.py
test_object_permission_loading.py
test_onboarding.py
test_organization_budget_enforcement.py
test_password_hashing.py
test_route_checks.py
test_team_member_budget.py
test_unmapped_model_budget_enforcement.py
test_user_api_key_auth.py