litellm/tests/test_litellm/proxy
Cole McIntosh 8826e02a98
feat: Add dot notation support for all JWT fields (#13013)
* feat: Add dot notation support for all JWT fields

- Updated all JWT field access methods to use get_nested_value for dot notation support
- Enhanced get_team_id to properly handle team_id_default fallback with nested fields
- Added comprehensive unit tests for nested JWT field access and edge cases
- Updated documentation to reflect dot notation support across all JWT fields
- Maintains full backward compatibility with existing flat field configurations

Supported fields with dot notation:
- team_id_jwt_field, team_ids_jwt_field, user_id_jwt_field
- user_email_jwt_field, org_id_jwt_field, object_id_jwt_field
- end_user_id_jwt_field (roles_jwt_field was already supported)

Example: user_id_jwt_field: 'user.sub' accesses token['user']['sub']

* fix: Add type annotations to resolve mypy errors

- Add explicit type annotation for team_ids variable in get_team_ids_from_jwt
- Add type ignore comment for sentinel object return in get_team_id
- Resolves mypy errors while maintaining functionality

* fix: Resolve mypy type error in get_team_ids_from_jwt

- Remove explicit List[str] type annotation that conflicts with get_nested_value return type
- Simplify return logic to use 'team_ids or []' ensuring always returns List[str]
- Fixes: Incompatible types in assignment (expression has type 'list[str] | None', variable has type 'list[str]')

* fix: Add proper type annotation for team_ids variable

- Use Optional[List[str]] type annotation to satisfy mypy requirements
- Resolves: Need type annotation for 'team_ids' [var-annotated]
- Maintains functionality while ensuring type safety

* refactor: remove outdated JWT unit tests and consolidate JWT-related functionality

- Deleted the test_jwt.py file as it contained outdated and redundant tests.
- Consolidated JWT-related tests into test_handle_jwt.py for better organization and maintainability.
- Updated tests to ensure proper functionality of JWT handling, including token validation and role mapping.
- Enhanced test coverage for JWT field access and nested claims handling.

* test: add comprehensive unit tests for JWT authentication

- Introduced a new test file `test_jwt.py` containing unit tests for JWT authentication.
- Implemented tests for loading configuration with custom role names, validating tokens, and handling team tokens.
- Enhanced coverage for JWT field access, nested claims, and role-based access control.
- Added fixtures for Prisma client and public JWT key generation to support testing.
- Ensured proper handling of valid and invalid tokens, including user and team scenarios.

* revert test_handle_jwt.py

* rename file

* test: remove outdated JWT nesting tests and add new nested field access tests

- Deleted the `test_jwt_nesting.py` file as it contained outdated tests.
- Introduced new tests in `test_handle_jwt.py` to verify nested JWT field access.
- Enhanced coverage for accessing nested values using dot notation and ensured backward compatibility with flat field names.
- Added tests for handling missing nested paths and appropriate default values.
- Improved handling of metadata prefixes in nested field access.

* restore file
2025-07-29 16:51:17 -07:00
..
_experimental/mcp_server [MCP Gateway] Add protocol headers (#13062) 2025-07-29 16:03:23 -07:00
anthropic_endpoints test fixes 2025-06-25 18:42:06 -07:00
auth feat: Add dot notation support for all JWT fields (#13013) 2025-07-29 16:51:17 -07:00
client Add "keys import" command to CLI (#12620) 2025-07-15 20:14:43 -07:00
common_utils [Bug Fix] Add swagger docs for LiteLLM /chat/completions, /embeddings, /responses (#12618) 2025-07-15 13:37:22 -07:00
db build(VLLM-Passthrough-with-loadbalancing-support-(enables-using-model-list-for-VLLM-/classify-endpoint)): Closes #11205 2025-05-31 09:00:04 -07:00
experimental/mcp_server
guardrails GuardrailsAI: use validatedOutput to allow usage of "fix" guards. Previously "fix" guards had no effect in llmOutput mode. (#12891) 2025-07-24 22:07:06 -07:00
health_endpoints
hooks test_pre_call_hook_team_rpm_limits 2025-07-11 15:52:21 -07:00
image_endpoints Feat: add add azure endpoint for image endpoints (#11482) 2025-06-06 10:38:37 -07:00
management_endpoints Fix list team v2 security check (#13094) 2025-07-29 10:29:40 -07:00
management_helpers [MCP Gateway] access group UI object permission fix (#12523) 2025-07-11 18:25:40 -07:00
middleware
openai_files_endpoint fix(proxy): Add managed_files hook to test_mock_create_audio_file 2025-06-26 10:42:25 -06:00
pass_through_endpoints Azure api_version="preview" support + Bedrock cost tracking via Anthropic /v1/messages (#13072) 2025-07-29 08:13:55 -07:00
spend_tracking fix: Handle circular references in spend tracking metadata JSON serialization (#12643) 2025-07-16 07:24:41 -07:00
test_configs
ui_crud_endpoints Litellm encrypt admin UI values (#12675) 2025-07-17 22:24:58 -07:00
vector_store_endpoints [Feat] LLM API Endpoint - Expose OpenAI Compatible /vector_stores/{vector_store_id}/search endpoint (#12749) 2025-07-18 18:18:53 -07:00
test_caching_routes.py [Bug Fix] Ensure /redis/info works on GCP Redis (#11732) 2025-06-14 15:35:09 -07:00
test_common_request_processing.py [Feat] DD Trace - Add instrumentation for streaming chunks (#11338) 2025-06-02 16:48:39 -07:00
test_custom_proxy.py Custom Root Path Improvements: don't require reserving /litellm route (#11460) 2025-06-05 16:36:47 -07:00
test_health_check_functions.py Implement health check backend API and storage functionality - fix ci/cd (#11852) 2025-06-18 06:57:08 -07:00
test_litellm_pre_call_utils.py Revert "fix: Set user from token user_id for OpenMeter integration (#13029)" (#13107) 2025-07-29 15:49:20 -07:00
test_proxy_cli.py Health check app on separate port (#12718) 2025-07-18 11:17:15 -07:00
test_proxy_server.py [FEAT] Model-Guardrails: Add on UI (#13006) 2025-07-26 11:42:03 -07:00
test_proxy_types.py Litellm dev 06 06 2025 p1 (#11496) 2025-06-07 09:12:16 -07:00
test_proxy_utils.py [Security Bug Fix] Ensure only LLM API route fails get logged on Langfuse (and other loggers) (#12308) 2025-07-04 14:42:42 -07:00
test_route_llm_request.py Update mistral 'supports_response_schema' field + Fix ollama embedding (#12024) 2025-06-25 07:20:13 -07:00
test_spend_log_cleanup.py Fix/gemini api key environment variable support (#12507) 2025-07-29 15:56:01 -07:00
test_team_member_update.py fix mapped tests (#12320) 2025-07-04 10:04:43 -07:00