litellm/tests/unit/proxy/auth
yujonglee 983c7ef20d
fix(auth): check a mapped JWT's end-user claim and keep the error classes of refused keys and JWTs (#52397)
* fix(auth): check a mapped JWT's end-user claim and keep the typed unknown-key error

Two regressions from moving key and JWT auth into gateway-auth-core, both
failing tests/integration/authorization on main.

A JWT mapped to a virtual key carried its end-user claim beside the key, in
MappedJwt, while the key path read the end user from KeyRecord.end_user_id.
That field came from the stored key row, which never names an end user, so the
key path validated, read and budget-checked the request body's end user, and
an over-budget body user refused a request the claim should have decided.
Credential::Resolved now carries the end user the JWT names, the key path
reads it before the request's, and KeyRecord.end_user_id is gone.

An unknown virtual key came back from the core as a plain ProxyException, so
the failure spend row recorded error_class ProxyException and the auth failure
log line lost "key=<hash>, not found in db". KeyDenial::NotFound now carries
the hash the host looked up and renders as PublicDenial::KeyNotFound, which
Python constructs as KeyNotFoundError.

The team header integration test asserted Python's list repr in the 403
message. The core formats lists as JSON by design, so the test now reads the
allowed team ids as JSON.

* fix(auth): keep the JWT error classes failure rows record and test path handoffs at the entry point

An unknown signing key and an ID-JAG sent as a bearer token were raised as
NoMatchingJWTPublicKeyError and IdJagIsNotABearerTokenError before the core
moved to Rust, and as a bare Exception after it, so the failure spend row's
error_class lost the name. Each is its own PublicDenial variant again.

test_denial.py now pins the exact class of every RustDenial variant and fails
when a variant has none.

lib.rs gains entry-point tests for a JWT that continues on the key path: a
linked existing key reads the claim's end user, and a blocked mapped key is
refused with that key. AGENTS.md records the three rules behind these fixes.

* test(auth): pin auth outcomes for a production-shaped JWT deployment

86 requests run through user_api_key_auth against settings shaped like a
production install: teams from a JWT roles claim, users created on first
sight, team-based model access, a team route allowlist, pass-through endpoints
registered with auth, a master key, virtual keys, and requests let through a
database outage. A second JWT configuration maps a client claim to a virtual
key and names the end user by a claim.

Each case pins who the request is served as or how it is refused: the user,
team and end user on the token, the status, type and opening of the error, the
exception class the failure spend row records, and the users and team members
auth wrote.

Every expected value was observed on the commit before key and JWT auth moved
to gateway-auth-core, where the same requests gave the same outcomes apart
from message wording. Putting either of the two regressions back fails this
file: the unknown-key case when the typed error is lost, and three mapped-JWT
cases when the end-user claim does not reach the key path.

* test(auth): build the profile test's empty tables in one expression

* fix(auth): select a JWT team for pass-through subpaths and report a failed team read as an outage

Two bugs that predate the Rust auth core and that the production-shaped
profile test surfaced.

A JWT caller whose team grants a pass-through endpoint registered with
include_subpath was refused on every path under it, unless the user's own row
listed exactly one team. Team selection asked whether team_allowed_routes
lists the route, and a subpath is only listed inside the openai_routes group
as "path/*", which a group entry never matches as a wildcard. Selection now
asks whether the team may use the route, which is true for every auth
pass-through route, and leaves the decision to the team's own grants, as the
header, RBAC and database fallback sources already did.

A database outage during a JWT team read was reported as 403 "No team has
access to the requested model". get_team_object turns every failure into a 404
HTTPException, so the host answered Unreadable, and the core dropped any
failure it did get. get_team_object now keeps the original error as the cause,
the JWT host re-raises it when it is a database connection error, and team
selection ends with that host failure. The request then gets the fallback
identity under allow_requests_on_db_unavailable, or the 503.

A team the host fails to read now ends the selection even when
team_claim_fallback is on or a later team would qualify.

* test(auth): cut auth tests that kill no mutant and simplify the claimed team read

The deployment profile test goes from 87 cases to 12. Line coverage showed 36 cases ran no
proxy line the rest of tests/unit/proxy/auth misses, and the others reached the same few
host answers, so one case per answer stays.

check_team now reads the team with ?, like every other team read in the file. The guard it
replaces left a mutant no test could kill, since a host only fails a read as HostFailed.

Core and host tests that repeated another test's assertion are removed, and two cases cover
mutants that survived next to the changed key path code.

* test(auth): cover the claimed team and entry point mutants left in the touched files

A singular team claim is a team the header may name and wins over an alias claim, a
delegated agent is scoped to the teams its token names, and the two public entry points
that only delegate to the planner are now called from a test.

cargo mutants over the 8 changed core files now reports 114 caught and none missed.

* test(auth): drop the wall-clock expiry from the refused JWT class test

Both refusals happen before the expiry is read, so the token needs no exp claim.

* test(auth): mark the new entry point tests with rstest and name helpers over commenting them

* refactor(auth): return a failed team read with its real error and read it in the JWT host

get_team_object reports every database failure as a 404, so the JWT host had to
recover an outage from the exception's cause. read_team now holds the read and
returns a failed one as a value, get_team_object keeps its 404 on top of it for
its other callers, and the host decides from the real error.

* test(mcp): stub the team reader the JWT host now calls
2026-11-18 03:36:46 +00:00
..
host 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
__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 fix(proxy)!: match the sign-in email fallback to the right user (#51897) 2026-11-15 19:13:38 -08:00
conftest.py feat(auth): decide key and JWT authentication in a Rust core (#51374) 2026-11-17 14:07:47 +09:00
test_access_group_rules.py feat(auth): grant access groups through principal attribute rules (#50455) 2026-11-09 13:59:40 -08: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_auth_checks.py feat(proxy): support Cursor CLI subscriptions (#52205) 2026-11-16 21:49:12 -08:00
test_auth_checks_object_access_and_lookup.py fix(auth): index restricted end-user registry refreshes (#51772) 2026-11-17 15:15:46 -08:00
test_auth_exception_handler.py fix(proxy): preserve caller metadata on auth failures (#51745) 2026-11-13 16:13:50 -08:00
test_auth_hot_path_network_requests.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_auth_object_prefetch.py feat(redis): serve the proxy's common Redis call with Rust stores (#50170) 2026-11-06 06:01:11 +00:00
test_auth_utils.py feat(proxy): accept request token prices in a declared currency (#51971) 2026-11-16 15:16:24 -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 fix(proxy/auth): return 401 for a non-master key when no database is configured (#52349) 2026-11-17 14:19:09 -08:00
test_custom_auth_end_user_budget.py fix(auth): index restricted end-user registry refreshes (#51772) 2026-11-17 15:15:46 -08:00
test_customer_hierarchy_auth.py feat(customer-portal): add free tier limits with Enterprise upgrade path (#51687) 2026-11-13 14:43:15 -05: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_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(proxy): expose public names for private proxy helpers (#45170) 2026-10-07 18:59:27 -07: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): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07: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(control_plane): dataplane registry, credential strategies and client (#49655) 2026-11-16 17:36:23 +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 feat(auth): decide key and JWT authentication in a Rust core (#51374) 2026-11-17 14:07:47 +09:00
test_legacy_empty_models_check.py feat(proxy): log keys and teams still on the deprecated empty models defaults at boot (#50720) 2026-11-10 04:05:25 +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 feat(proxy): hash UI passwords with PBKDF2 in FIPS mode (#49874) 2026-11-06 01:31:59 -08: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 feat(proxy): customer budget rollup, reset on the budget row's window, named templates, team overrides, multi-window limits and pause_allow_increase (#51582) 2026-11-13 16:05:35 +00:00
test_model_checks.py fix(proxy): stop wildcard aliases over unknown orgs listing every catalog id (#51805) 2026-11-14 16:34:59 -05: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(proxy): expose public names for private proxy helpers (#45170) 2026-10-07 18:59:27 -07: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 fix(auth): let dashboard sessions use the user's team models (#51663) 2026-11-13 17:13:06 -05:00
test_proxy_routes.py refactor(proxy): expose public names for private proxy helpers (#45170) 2026-10-07 18:59:27 -07: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 fix(proxy): recheck missing users when resolving session grants (#51030) 2026-11-10 21:55:53 +00: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 fix(auth): return a generic 401 for an unknown key (#39787) 2026-10-15 01:05:25 -07:00
test_route_checks.py feat(auth): decide key and JWT authentication in a Rust core (#51374) 2026-11-17 14:07:47 +09: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(proxy): customer budget rollup, reset on the budget row's window, named templates, team overrides, multi-window limits and pause_allow_increase (#51582) 2026-11-13 16:05:35 +00:00
test_search_tool_deny_by_default.py fix(proxy): scope dashboard search grants to user (#48464) 2026-10-26 15:01:40 -07: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 feat(model_capacity): replace the python dynamic rate limiter v3 with a rust callback (#51540) 2026-11-17 22:20:54 +00:00
test_user_api_key_auth_deployment_profile.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_user_api_key_auth_request_flow.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_vector_store_access_groups.py feat(access-groups): grant vector stores through access groups (#50290) 2026-11-12 14:59:17 -08:00