Skip to content

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]

fix(tests): keep a host PROXY_BASE_URL out of request-derived URL tests

mateo-berri69133f6baad7
diff --git a/tests/test_litellm/conftest.py b/tests/test_litellm/conftest.py
index 0dc8f56f3ce..0e561301058 100644
--- a/tests/test_litellm/conftest.py
+++ b/tests/test_litellm/conftest.py
@@ -100,6 +100,18 @@ def isolate_host_aws_config(monkeypatch, isolated_aws_credentials_dir):
monkeypatch.delenv("AWS_DEFAULT_REGION", raising=False)
[email protected](scope="function", autouse=True)
+def isolate_host_proxy_base_url(monkeypatch):
+ """Prevent a host PROXY_BASE_URL from outranking request-derived URLs during unit tests.
+
+ It is the first thing the proxy consults when it resolves its own public origin, so a value
+ left in the developer's shell or .env silently replaces the base_url every OAuth discovery,
+ redirect_uri, and registration assertion is written against. Tests that exercise a configured
+ public origin set it within their own body, which still wins over this.
+ """
+ monkeypatch.delenv("PROXY_BASE_URL", raising=False)
+
+
def _run_coroutine_if_needed(result):
if not asyncio.iscoroutine(result):
return
diff --git a/tests/test_litellm/test_conftest.py b/tests/test_litellm/test_conftest.py
new file mode 100644
index 00000000000..c813f59c7e4
--- /dev/null
+++ b/tests/test_litellm/test_conftest.py
@@ -0,0 +1,49 @@
+import os
+import subprocess
+import sys
+from pathlib import Path
+from typing import Final
+
+REPO_ROOT: Final = Path(__file__).resolve().parents[2]
+
+PROXY_BASE_URL_SENSITIVE_NODE: Final = (
+ "tests/test_litellm/proxy/management_endpoints/test_mcp_management_endpoints.py"
+ "::TestTemporaryMCPSessionEndpoints"
+ "::test_mcp_token_opens_sealed_passthrough_code_and_exchanges_with_minted_client"
+)
+
+COVERAGE_SUBPROCESS_VARS: Final = frozenset(
+ {"COV_CORE_SOURCE", "COV_CORE_CONFIG", "COV_CORE_DATAFILE", "COV_CORE_CONTEXT", "COVERAGE_PROCESS_START"}
+)
+
+
+def test_host_proxy_base_url_cannot_reach_request_derived_url_tests():
+ """A PROXY_BASE_URL in the host environment must not reach tests that assert on request-derived URLs.
+
+ The proxy resolves its public origin from that variable before anything else, so a developer
+ who has one set for their own deployment used to watch dozens of OAuth discovery, redirect_uri,
+ and client registration cases fail on an origin no test ever asked for.
+ """
+ child_env: Final = {
+ key: value for key, value in os.environ.items() if key not in COVERAGE_SUBPROCESS_VARS
+ } | {"PROXY_BASE_URL": "https://leaked-host-origin.example.com"}
+
+ completed: Final = subprocess.run(
+ [
+ sys.executable,
+ "-m",
+ "pytest",
+ PROXY_BASE_URL_SENSITIVE_NODE,
+ "-q",
+ "--no-header",
+ "-p",
+ "no:cacheprovider",
+ ],
+ cwd=REPO_ROOT,
+ env=child_env,
+ capture_output=True,
+ text=True,
+ check=False,
+ )
+
+ assert completed.returncode == 0, completed.stdout + completed.stderr