The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test(health): guard that test_connection authorizes on post-merge probe params
mateo-berri458a63935f55
diff --git a/tests/test_litellm/proxy/health_endpoints/test_health_endpoints.py b/tests/test_litellm/proxy/health_endpoints/test_health_endpoints.pyindex 62919200d47..72c6f77a4f7 100644--- a/tests/test_litellm/proxy/health_endpoints/test_health_endpoints.py+++ b/tests/test_litellm/proxy/health_endpoints/test_health_endpoints.py@@ -898,6 +898,62 @@ async def test_test_model_connection_uses_loaded_deployment_team_id_via_model_naassert passed_model_params.model_info.team_id == deployment_owner_team_id+async def test_test_model_connection_authorizes_on_params_after_health_check_params_merge():+ """+ Regression guard for the ordering fix: health_check_params from the request+ body are merged into the probe params BEFORE the authorization check, so a+ caller cannot smuggle a field past auth via health_check_params. Auth is+ stubbed to reject, which halts the endpoint right after it records the+ params it was handed, so the outbound probe is never reached. If the merge+ is moved back to after can_user_make_model_call, the marker is absent from+ those params and this test fails.+ """+ from fastapi import HTTPException++ from litellm.proxy.management_endpoints.model_management_endpoints import (+ ModelManagementAuthChecks,+ )+ from litellm.types.router import Deployment++ marker = "sentinel-from-health-check-params"+ mock_can_user_make_model_call = AsyncMock(+ side_effect=HTTPException(status_code=403, detail="denied")+ )++ with (+ patch( # test-quality-ok: proxy module global, no injection seam+ "litellm.proxy.proxy_server.prisma_client", MagicMock()+ ),+ patch( # test-quality-ok: proxy module global, no injection seam+ "litellm.proxy.proxy_server.llm_router", None+ ),+ patch.object( # test-quality-ok: capturing the params handed to auth is the assertion+ ModelManagementAuthChecks,+ "can_user_make_model_call",+ mock_can_user_make_model_call,+ ),+ pytest.raises(HTTPException),+ ):+ await health_test_model_connection(+ request=MagicMock(),+ mode="chat",+ litellm_params={"model": "openai/gpt-4o"},+ model_info={"health_check_params": {"probe_marker": marker}},+ user_api_key_dict=UserAPIKeyAuth(+ token="requester-token",+ user_id="admin-user",+ user_role=LitellmUserRoles.PROXY_ADMIN,+ ),+ )++ assert mock_can_user_make_model_call.called+ passed_model_params = mock_can_user_make_model_call.call_args.kwargs["model_params"]+ assert isinstance(passed_model_params, Deployment)+ authorized_params = passed_model_params.litellm_params.model_dump()+ assert authorized_params.get("probe_marker") == marker++@pytest.mark.asyncioasync def test_test_model_connection_authorized_team_admin_passes_real_auth():"""