litellm/tests/integration/authorization
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
..
__init__.py test: migrate tests/proxy_behavior into integration and unit tiers (#45939) 2026-10-11 08:28:42 -07:00
_guardrail_opt_out.py test(integration): stop GET /__observations from draining the upstream log (#47256) 2026-10-18 09:58:05 +00:00
_hidden_alias_budget.py fix(anthropic_endpoints)!: return Anthropic error envelopes on /v1/messages auth failures (#48466) 2026-11-03 01:53:29 +00:00
_responses_compact.py fix(proxy): check previous_response_id ownership on /v1/responses/compact (#46408) 2026-10-14 17:57:34 +00:00
test_access_group_budget.py test(integration): give each owned proxy a private database and Redis by default (#47213) 2026-10-18 03:37:41 +00:00
test_access_group_model_listing.py test(integration): stop GET /__observations from draining the upstream log (#47256) 2026-10-18 09:58:05 +00: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_agent_access.py fix(agents): show non-admin callers the proxy URL in agent cards (#49483) 2026-10-31 16:17:11 -07:00
test_agent_denial_logging.py fix(a2a): log authenticated pre-dispatch agent rejections (#49492) 2026-10-31 15:53:01 -07:00
test_agent_least_privilege.py fix(a2a): answer proxy refusals on /a2a POST routes as JSON-RPC errors (#49476) 2026-10-31 12:54:10 -07:00
test_alias_chain_budget_waiver.py fix(anthropic_endpoints)!: return Anthropic error envelopes on /v1/messages auth failures (#48466) 2026-11-03 01:53:29 +00:00
test_audio_model_access.py test(authorization): expect the sse stream_format the proxy now sends for speech billing (#52392) 2026-11-18 00:17:48 +00:00
test_audit_any_sweep_auth.py test(integration): look up owned cache keys and clean up sweep models (#47255) 2026-10-18 10:27:53 +00:00
test_auth_object_prefetch.py test: migrate tests/proxy_behavior into integration and unit tiers (#45939) 2026-10-11 08:28:42 -07:00
test_bedrock_passthrough_model_access.py
test_claude_code_gateway_oauth.py fix(anthropic_endpoints)!: return Anthropic error envelopes on /v1/messages auth failures (#48466) 2026-11-03 01:53:29 +00:00
test_cli_sso_login_ui_disabled.py fix(anthropic_endpoints)!: return Anthropic error envelopes on /v1/messages auth failures (#48466) 2026-11-03 01:53:29 +00:00
test_customer_model_allowlist.py
test_customer_org_alias_first_request_burst.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_org_alias_key_scope.py fix(proxy): refuse a key pinned to another customer org before registering an unknown org alias (#51674) 2026-11-13 11:03:43 -08:00
test_deprecated_key_lookup_cache.py
test_end_user_block.py test(integration): stop GET /__observations from draining the upstream log (#47256) 2026-10-18 09:58:05 +00:00
test_guardrail_submissions.py fix(proxy)!: label shared-handler errors the way the route catch-alls do (#39555) 2026-10-30 06:58:05 -07:00
test_hidden_alias_budget_bypass.py fix(anthropic_endpoints)!: return Anthropic error envelopes on /v1/messages auth failures (#48466) 2026-11-03 01:53:29 +00:00
test_hidden_alias_budget_bypass_chaos.py test(integration): stop GET /__observations from draining the upstream log (#47256) 2026-10-18 09:58:05 +00:00
test_jwt_auto_register_map_existing_key.py test(integration): poll for the cached JWT rejection sentinel instead of a single Redis read (#50014) 2026-11-04 11:46:38 -08:00
test_jwt_default_team_provisioning.py test(integration): give each owned proxy a private database and Redis by default (#47213) 2026-10-18 03:37:41 +00:00
test_jwt_key_mapping_lifecycle.py fix(proxy): evict issuer-scoped JWT mapping misses on global mapping writes (#52350) 2026-11-17 14:38:53 -08:00
test_jwt_mapped_key_email_backfill.py test(integration): give each owned proxy a private database and Redis by default (#47213) 2026-10-18 03:37:41 +00:00
test_key_alias_model_access.py
test_key_bound_to_unknown_user.py
test_key_budget_owner_updates.py fix(proxy)!: gate key budget_duration and budget_id updates like max_budget (#47681) 2026-10-26 16:45:35 -07:00
test_key_guardrail_opt_out.py test(integration): give each owned proxy a private database and Redis by default (#47213) 2026-10-18 03:37:41 +00:00
test_key_guardrail_opt_out_chaos.py test(integration): stop GET /__observations from draining the upstream log (#47256) 2026-10-18 09:58:05 +00:00
test_key_guardrail_opt_out_runtime.py test(integration): give each owned proxy a private database and Redis by default (#47213) 2026-10-18 03:37:41 +00:00
test_lakera_v2_on_flagged.py fix(guardrails)!: make lakera_v2 on_flagged block reject PII-only detections, add mask (#48944) 2026-10-29 11:48:37 -07:00
test_legacy_empty_models_boot_warning.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_http_client_sso_real_io.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_master_key_boot_check_real_io.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_memory_ownership.py fix(proxy)!: stop answering with the literal string "None" as error type and param on the proxy-server, auth, spend, and key health routes (#39540) 2026-10-29 18:20:52 -07:00
test_model_access_allow_lists.py test: replace 61 live logging and otel tests with offline unit and integration coverage (#45362) 2026-10-08 15:55:57 -07:00
test_object_permission_lookup.py feat(proxy): add opt-in vector_store_deny_by_default for least-privilege vector store access (#44244) 2026-10-06 12:50:25 -07:00
test_passthrough_route_denylist.py feat(proxy): add denied_passthrough_routes deny list for custom pass-through endpoints (#44924) 2026-10-07 16:19:53 -07:00
test_rag_query_vector_store_allowlist.py test(integration): stop GET /__observations from draining the upstream log (#47256) 2026-10-18 09:58:05 +00:00
test_rag_team_provider_credentials.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_realtime_client_secret_access.py test(integration): cover realtime endpoint contracts (#44689) 2026-10-14 03:49:34 +00:00
test_reject_before_body.py fix(proxy): let an exhausted key keep listing models and counting tokens (#51675) 2026-11-16 03:28:26 +08:00
test_responses_compact_id_ownership.py test(integration): assert response ids stay scoped to their minting key (#50703) 2026-11-10 00:30:01 +00:00
test_responses_compact_id_ownership_chaos.py test(integration): give each owned proxy a private database and Redis by default (#47213) 2026-10-18 03:37:41 +00:00
test_responses_id_ownership.py fix(responses)!: authorize and decode comparison response IDs (#49402) 2026-11-03 03:40:46 +00:00
test_responses_lifecycle_during_call_guardrail.py fix(types): define the responses compact call types for during_call guardrails and deployment hooks (#50274) 2026-11-05 16:09:49 -08:00
test_search_tool_allowlist.py test(integration): expect the Exa search envelope's provider_metadata after #47423 (#47572) 2026-10-20 15:29:30 +00:00
test_search_tool_deny_by_default.py feat(auth): deny search tools by default when search_tool_deny_by_default is set (#44490) 2026-10-06 12:50:26 -07:00
test_sso_blank_identity.py test(sso): reuse the provider identity across dashboard and CLI sign-in (#52062) 2026-11-16 18:28:50 +00:00
test_team_admin_gate.py fix(proxy)!: stop answering with the literal string "None" as error type and param on the proxy-server, auth, spend, and key health routes (#39540) 2026-10-29 18:20:52 -07:00
test_team_member_permissions.py test(integration): stop GET /__observations from draining the upstream log (#47256) 2026-10-18 09:58:05 +00:00
test_team_scoped_models.py test(integration): assert team model visibility follows caller scope (#50772) 2026-11-10 00:33:57 +00:00
test_tool_search_replay_allowlist.py fix(responses bridge): round-trip tool_search_call and tool_search_output items between turns (#46444) 2026-10-14 21:40:14 -07:00
test_tool_search_replay_guardrails.py test(integration): give each owned proxy a private database and Redis by default (#47213) 2026-10-18 03:37:41 +00:00
test_unknown_key_generic_401.py fix(anthropic_endpoints)!: return Anthropic error envelopes on /v1/messages auth failures (#48466) 2026-11-03 01:53:29 +00:00
test_user_api_key_auth_request_flow_real_io.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_user_self_update_guard.py fix(proxy)!: label shared-handler errors the way the route catch-alls do (#39555) 2026-10-30 06:58:05 -07:00
test_warmed_policy.py fix(scim): answer every /scim/v2 error with the RFC 7644 SCIM Error schema (#51322) 2026-11-17 19:10:33 +00:00
test_websocket_rejection_logging.py test(integration): give chaos and timing tests a harness API and gate raw signals (#46031) 2026-10-12 05:27:33 -07:00
test_wildcard_model_access.py test(integration): stop GET /__observations from draining the upstream log (#47256) 2026-10-18 09:58:05 +00:00
test_workflow_ownership.py fix(proxy)!: stop answering with the literal string "None" as error type and param on the proxy-server, auth, spend, and key health routes (#39540) 2026-10-29 18:20:52 -07:00