litellm/tests/unit/proxy/auth
izzybn 098d8ef822
fix(proxy): make litellm --test pick a served model, and send the master key only to a local proxy (#53866)
* fix(proxy): make litellm --test pick a served model and send the master key

litellm --test raised ValueError on every run since the flag became a plain switch, defaulted to the retired gpt-3.5-turbo, and sent a hardcoded key. It now reads GET /v1/models with LITELLM_MASTER_KEY and picks the first chat model not past its deprecation date. litellm --health sends the same key, and the startup banner curl carries the Authorization header and a model placeholder

* fix(proxy): pick only named chat models for litellm --test and drop its max_tokens

GET /v1/models on a wildcard proxy lists every id the wildcard expands to,
in a random order per worker, and many of them cannot answer a plain text
chat (fine-tune bases, audio-only, access-gated, or ones that reject
max_tokens). --test now asks for return_wildcard_routes and keeps only the
model names listed before the first wildcard route, so it picks a model the
config names, and a wildcard-only proxy is asked to pass --model.

The test chat request no longer sends max_tokens=256, which OpenAI reasoning
models that LiteLLM does not map yet reject with a 400.

* fix(proxy): send the master key only to a local host and fail --health on an error status

litellm --test and --health now send LITELLM_MASTER_KEY only when --host is local, name that rule when the proxy answers 401 or 403, and --health exits non-zero on an error status. The local-host check moves from the lens adapter to url_utils so both share it

* fix(proxy): let litellm --health wait on slow model checks and pick past prefixed retired models

--health now waits on the proxy's own per-model health check timeout instead of
httpx's 5 second read default, so a model slower than 5 seconds no longer makes it
exit with httpx.ReadTimeout

The --test model pick checks a provider-prefixed name like openai/gpt-3.5-turbo
against the cost map row for the name after the prefix too, and counts responses
mode models as chat, since the proxy serves them on chat completions

* fix(proxy): keep --test and --health off env proxies for a local host

Requests to a local --host now skip HTTP_PROXY and ALL_PROXY, so the master
key never reaches a forward proxy. IPv6 hosts such as :: get a bracketed URL,
a 401 or 403 on the --test requests names LITELLM_MASTER_KEY like the model
list does, and a provider-prefixed model is checked under its bare name only
when the cost map has no entry for the full name

* fix(proxy): bound --health at 10 minutes and keep the key off *.localhost names

--health read with no timeout, so a proxy that accepted the connection and never answered hung the command forever. It now uses the OpenAI SDK's default timeout, 5 seconds to connect and 10 minutes to read, the same bound --test's client has, which outlasts a model check at the proxy's 60 second default

--test and --health sent LITELLM_MASTER_KEY to any *.localhost name, which the system resolver may send off the machine. The CLI now sends it only to localhost and loopback or unspecified addresses through url_utils.is_loopback_host, and the lens adapter keeps is_local_host

The startup banner now says to export LITELLM_MASTER_KEY in the new terminal tab it sends you to

* fix(proxy): keep the banner curl's master key off env proxies

The startup banner's sample curl sends LITELLM_MASTER_KEY to http://0.0.0.0, and curl routes that through http_proxy or ALL_PROXY when the shell sets one. It now passes --noproxy '*', the same way --test and --health skip env proxies for a local host

* test(proxy): expect --noproxy in the gunicorn banner curl

* fix(proxy): name LITELLM_MASTER_KEY when no HTTP header can carry it

A key with a newline, a trailing space or a non-ASCII character crashed --health and --test with an httpx traceback. Both now stop before any request with an error naming the variable

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-24 04:17:02 +00:00
..
host perf(proxy): read only the needed team fields from the auth cache (#53909) 2026-11-23 12:53:14 -08:00
__init__.py ci: move tests/proxy_unit_tests to tests/unit/proxy and run the proxy-db shards from litellm-tests (#42903) 2026-09-24 22:59:11 +00:00
_user_table.py feat(db): rust repositories for user, end user and budget auth objects (#52170) 2026-11-18 22:32:05 +00:00
conftest.py refactor(proxy): move non-auth writers out of the auth cache (#51599) 2026-11-20 17:57:38 +09:00
test_access_group_rules.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_admin_viewer_handler_access.py test(proxy): move auth, hooks, policy_engine and client tests into tests/unit/proxy (#43998) 2026-10-01 10:11:45 -07:00
test_app_auth.py feat(proxy): add app groups with shared budgets and usage (#53232) 2026-11-21 12:50:58 -08:00
test_auth_checks.py feat(proxy): require customer headers by gateway, team, or key (#53045) 2026-11-21 20:20:26 +00:00
test_auth_checks_object_access_and_lookup.py fix(auth): retry a team read that loses its database connection and answer 503 when the database is down (#53260) 2026-11-21 12:18:19 -08:00
test_auth_exception_handler.py fix(auth): retry a team read that loses its database connection and answer 503 when the database is down (#53260) 2026-11-21 12:18:19 -08:00
test_auth_hot_path_network_requests.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_auth_object_prefetch.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_auth_utils.py fix(proxy): only relay Azure passthrough model groups that are served by Azure (#53904) 2026-11-23 13:30:28 -08:00
test_authorization.py fix(proxy): share ownership permissions for spend logs and traces (#44239) 2026-10-03 01:38:54 +00:00
test_banned_params_extra_body.py test(proxy): move auth, hooks, policy_engine and client tests into tests/unit/proxy (#43998) 2026-10-01 10:11:45 -07:00
test_cli_auth.py test(proxy): move auth, hooks, policy_engine and client tests into tests/unit/proxy (#43998) 2026-10-01 10:11:45 -07:00
test_core.py refactor(proxy): move non-auth writers out of the auth cache (#51599) 2026-11-20 17:57:38 +09:00
test_custom_auth_end_user_budget.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_customer_hierarchy_auth.py fix(proxy): name configured customer headers in authorization errors (#53043) 2026-11-20 16:33:39 -08:00
test_customer_member_auto_create.py fix(proxy): register new customer org aliases one at a time per worker so a burst of first requests is served (#52080) 2026-11-16 14:00:04 -08:00
test_customer_provisioning.py feat(proxy): require customer headers by gateway, team, or key (#53045) 2026-11-21 20:20:26 +00:00
test_customer_spend.py fix(proxy): enforce settled customer budgets across workers (#51568) 2026-11-13 07:33:24 -08:00
test_default_end_user_budget_simple.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_denial.py fix(auth): check a mapped JWT's end-user claim and keep the error classes of refused keys and JWTs (#52397) 2026-11-18 03:36:46 +00:00
test_fallback_budget.py refactor(router): delete router code nothing calls (#52516) 2026-11-19 06:11:10 +09:00
test_fallback_model_access.py feat(customer-portal): complete hierarchy management (#51521) 2026-11-13 17:58:34 +00:00
test_fallback_rate_limit.py feat(callbacks-parallel-request-limiter): port parallel request limiter v3 to a rust callback (#51537) 2026-11-16 22:56:38 -08:00
test_fallback_rate_limit_rust.py feat(callbacks-parallel-request-limiter): port parallel request limiter v3 to a rust callback (#51537) 2026-11-16 22:56:38 -08:00
test_impersonation.py feat(proxy)!: let every key read its own spend logs and return 403 for filters outside the caller's scope (#52449) 2026-11-19 03:14:35 +00:00
test_info_routes.py test(proxy): move auth, hooks, policy_engine and client tests into tests/unit/proxy (#43998) 2026-10-01 10:11:45 -07:00
test_jwt.py fix(proxy): accept audience and public_key_url in litellm_jwtauth (#53288) 2026-11-21 10:51:37 -08:00
test_legacy_empty_models_check.py Serialize legacy empty model boot counts (#52378) 2026-11-18 04:31:46 +00:00
test_litellm_license.py fix(proxy): stop logging license values during verification (#44956) 2026-10-06 17:05:07 -07:00
test_login_utils.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_master_key_boot_check.py ci(unit): cut unit check time with cheaper per-test resets and fewer non-unit tests (#51864) 2026-11-14 15:41:30 -08:00
test_mcp_ip_filtering.py refactor(mcp): drop the experimental label from the MCP server and client paths (#48513) 2026-10-27 17:47:50 +00:00
test_model_access_group_budgets.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_model_checks.py fix(proxy): make litellm --test pick a served model, and send the master key only to a local proxy (#53866) 2026-11-24 04:17:02 +00:00
test_model_checks_fallbacks.py refactor(router): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07:00
test_models_fallback_endpoint.py refactor(router): move router callers onto the entry points and invert the proxy imports (#48847) 2026-10-29 17:26:33 +00:00
test_multi_budget_windows.py feat(proxy): support budget_limits windows on internal users (#51763) 2026-11-14 07:44:35 -05:00
test_multipart_bypass_repro.py ci: move tests/proxy_unit_tests to tests/unit/proxy and run the proxy-db shards from litellm-tests (#42903) 2026-09-24 22:59:11 +00:00
test_network.py test(proxy): move auth, hooks, policy_engine and client tests into tests/unit/proxy (#43998) 2026-10-01 10:11:45 -07:00
test_oauth2_proxy_hook.py test(proxy): move auth, hooks, policy_engine and client tests into tests/unit/proxy (#43998) 2026-10-01 10:11:45 -07:00
test_object_permission_loading.py refactor(auth-store): shape the cached virtual key in Rust and load it through one Python path (#53325) 2026-11-21 22:06:13 +09:00
test_onboarding.py feat(proxy): hash UI passwords with PBKDF2 in FIPS mode (#49874) 2026-11-06 01:31:59 -08:00
test_organization_budget_enforcement.py test(proxy): move auth, hooks, policy_engine and client tests into tests/unit/proxy (#43998) 2026-10-01 10:11:45 -07:00
test_password_hashing.py test(proxy): move auth, hooks, policy_engine and client tests into tests/unit/proxy (#43998) 2026-10-01 10:11:45 -07:00
test_password_policy.py feat(proxy): hash UI passwords with PBKDF2 in FIPS mode (#49874) 2026-11-06 01:31:59 -08:00
test_personal_key_team_model_access.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_proxy_routes.py test(realtime): fix three unit tests left red by the GPT-Live attach routes (#53574) 2026-11-22 17:49:14 +00:00
test_rds_iam_token.py fix(proxy): preserve AWS session tokens for RDS IAM auth (#46559) 2026-10-15 22:51:39 +00:00
test_resolvers_exceptions.py fix(auth): return a generic 401 for an unknown key (#39787) 2026-10-15 01:05:25 -07:00
test_resolvers_grants.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_resolvers_models.py test(proxy): move auth, hooks, policy_engine and client tests into tests/unit/proxy (#43998) 2026-10-01 10:11:45 -07:00
test_resolvers_seam.py test(proxy): move auth, hooks, policy_engine and client tests into tests/unit/proxy (#43998) 2026-10-01 10:11:45 -07:00
test_resolvers_store.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_route_checks.py feat(lens): add key and team tracing controls (#53191) 2026-11-23 17:59:37 +00:00
test_router_override_fallback_auth.py refactor(proxy): expose public names for private proxy helpers (#45170) 2026-10-07 18:59:27 -07:00
test_scalar_budget_windows.py feat(db): rust repositories for user, end user and budget auth objects (#52170) 2026-11-18 22:32:05 +00:00
test_search_tool_deny_by_default.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_team_grants.py test(proxy): move auth, hooks, policy_engine and client tests into tests/unit/proxy (#43998) 2026-10-01 10:11:45 -07:00
test_team_member_budget.py feat(teams): show caller member spend and budget on Your Teams (#45674) 2026-10-24 17:09:55 -07:00
test_unmapped_model_budget_enforcement.py refactor(router): delete the python router core, the rust core is the only core (#50178) 2026-11-05 10:40:46 -08:00
test_user_api_key_auth.py fix(proxy): accept any case of the bearer scheme on realtime auth (#53259) 2026-11-21 16:32:32 -08:00
test_user_api_key_auth_deployment_profile.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_user_api_key_auth_request_flow.py perf(proxy): read only the needed team fields from the auth cache (#53909) 2026-11-23 12:53:14 -08:00
test_vector_store_access_groups.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00