litellm/tests/test_litellm/proxy
yuneng-jiang 94a043efb2
refactor(proxy/auth): normalize Bearer prefix in safe-hash helper (#29343)
* refactor(proxy/auth): normalize Bearer prefix in safe-hash helper

UserAPIKeyAuth._safe_hash_litellm_api_key now strips a leading
"Bearer "/"bearer " prefix before its existing sk-/JWT classification, so
the helper produces the same hashed output regardless of whether the
caller stripped the Authorization header prefix or passed the header
value through unchanged.

* refactor(proxy/auth): make Bearer-prefix strip case-insensitive

Per RFC 7235 the HTTP authorization scheme token is case-insensitive.
Replace the two-prefix loop with a single case-insensitive check so the
helper normalizes "Bearer ", "bearer ", "BEARER ", and any mixed-case
variant before classifying the remainder as sk- or JWT. The contract
test gains coverage of "BEARER " and "BeArEr ".

* test(mcp): align auth-handler test expectations with safe-hash helper

The two MCP auth tests asserted that UserAPIKeyAuth(api_key="Bearer ...")
retained the raw header bytes on the api_key field. _safe_hash_litellm_api_key
now normalizes that input — stripping the Bearer prefix and hashing the
resulting sk- key — so the expectations move to the normalized form:
the bare token in the parametrize case, and hash_token("sk-...") in the
backward-compat assertion. This matches what the real auth flow produces
(the builder strips Bearer and the DB stores the hashed token), so the
mocks now line up with production rather than with the un-normalized
validator output.
2026-05-30 14:04:22 -07:00
..
_experimental/mcp_server refactor(proxy/auth): normalize Bearer prefix in safe-hash helper (#29343) 2026-05-30 14:04:22 -07:00
a2a
agent_endpoints
anthropic_endpoints
auth
client
common_utils
db
discovery_endpoints
experimental/mcp_server
google_endpoints
guardrails
health_endpoints
hooks
image_endpoints
management_endpoints
management_helpers
memory
middleware
openai_files_endpoint
pass_through_endpoints
policy_engine
prompts
proxy_server
public_endpoints
rag_endpoints
realtime_endpoints
response_api_endpoints
spend_tracking
test_configs
types_utils
ui_crud_endpoints
vector_store_endpoints
__init__.py
conftest.py
test_aiohttp_cleanup_closed.py
test_aiohttp_session_recovery.py
test_api_key_masking_in_errors.py
test_audio_speech_prometheus_hooks.py
test_batch_expiry.py
test_batch_metadata_none_fix.py
test_batch_retrieve_bedrock.py
test_budget_reservation.py
test_caching_routes.py
test_chat_completion_metadata.py
test_common_request_processing.py
test_component_allowlists.py
test_cors_config.py
test_custom_proxy.py
test_dynamic_mcp_route.py
test_empty_model_list.py
test_enforce_user_param.py
test_fallback_management_endpoints.py
test_fastapi_offline_routes.py
test_filter_models_by_team_access_group.py
test_health_check_functions.py
test_health_check_max_tokens.py
test_langfuse_passthrough_security.py
test_lazy_openapi_snapshot.py
test_litellm_pre_call_utils.py
test_max_budget_env_var.py
test_mcp_asgi_response.py
test_model_dump_with_preserved_fields.py
test_model_id_header_propagation.py
test_model_info_default_limits.py
test_model_level_guardrails.py
test_openapi_schema_validation.py
test_pricing_field_strip.py
test_prometheus_cleanup.py
test_provider_url_destination_guard.py
test_proxy_cli.py
test_proxy_logging_hook_detection.py
test_proxy_server.py
test_proxy_types.py refactor(proxy/auth): normalize Bearer prefix in safe-hash helper (#29343) 2026-05-30 14:04:22 -07:00
test_proxy_utils.py
test_pyroscope.py
test_redis_auth_cache_flag.py
test_response_model_sanitization.py
test_route_a2a_models.py
test_route_llm_request.py
test_sensitive_route_auth.py
test_shared_health_check.py
test_spend_log_cleanup.py
test_swagger_chat_completions.py
test_team_member_update.py
test_team_org_move.py
test_tools_allowlist_enforcement.py
test_update_llm_router_resilience.py
test_utils.py