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]

test(proxy): align favicon remote asset expectations

userb67a81da4738
diff --git a/tests/proxy_unit_tests/test_get_favicon.py b/tests/proxy_unit_tests/test_get_favicon.py
index f17787e740d..ddc8b1230a7 100644
--- a/tests/proxy_unit_tests/test_get_favicon.py
+++ b/tests/proxy_unit_tests/test_get_favicon.py
@@ -1,6 +1,5 @@
import os
import sys
-from unittest import mock
sys.path.insert(0, os.path.abspath("../.."))
@@ -26,50 +25,30 @@ async def test_get_favicon_default():
@pytest.mark.asyncio
-async def test_get_favicon_with_custom_url():
- """Test that get_favicon fetches from a custom URL."""
- os.environ["LITELLM_FAVICON_URL"] = "https://example.com/favicon.ico"
+async def test_get_favicon_with_custom_url(monkeypatch):
+ """Test that get_favicon redirects browser-loaded custom URLs."""
+ monkeypatch.setenv("LITELLM_FAVICON_URL", "https://example.com/favicon.ico")
- mock_response = mock.Mock()
- mock_response.status_code = 200
- mock_response.content = b"\x00\x00\x01\x00"
- mock_response.headers = {"content-type": "image/x-icon"}
-
- try:
- with mock.patch(
- "litellm.llms.custom_httpx.http_handler.AsyncHTTPHandler.get"
- ) as mock_get:
- mock_get.return_value = mock_response
-
- async with httpx.AsyncClient(
- transport=httpx.ASGITransport(app=app),
- base_url="http://testserver",
- ) as ac:
- response = await ac.get("/get_favicon")
+ async with httpx.AsyncClient(
+ transport=httpx.ASGITransport(app=app),
+ base_url="http://testserver",
+ ) as ac:
+ response = await ac.get("/get_favicon")
- assert response.status_code == 200
- assert response.headers["content-type"] == "image/x-icon"
- finally:
- os.environ.pop("LITELLM_FAVICON_URL", None)
+ assert response.status_code == 307
+ assert response.headers["location"] == "https://example.com/favicon.ico"
@pytest.mark.asyncio
-async def test_get_favicon_url_error_fallback():
- """Test that get_favicon falls back to default on error."""
- os.environ["LITELLM_FAVICON_URL"] = "https://invalid.com/favicon.ico"
+async def test_get_favicon_remote_url_is_not_server_fetched(monkeypatch):
+ """Test that get_favicon does not validate remote URLs server-side."""
+ monkeypatch.setenv("LITELLM_FAVICON_URL", "https://invalid.com/favicon.ico")
- try:
- with mock.patch(
- "litellm.llms.custom_httpx.http_handler.AsyncHTTPHandler.get"
- ) as mock_get:
- mock_get.side_effect = httpx.ConnectError("unreachable")
-
- async with httpx.AsyncClient(
- transport=httpx.ASGITransport(app=app),
- base_url="http://testserver",
- ) as ac:
- response = await ac.get("/get_favicon")
+ async with httpx.AsyncClient(
+ transport=httpx.ASGITransport(app=app),
+ base_url="http://testserver",
+ ) as ac:
+ response = await ac.get("/get_favicon")
- assert response.status_code in [200, 404]
- finally:
- os.environ.pop("LITELLM_FAVICON_URL", None)
+ assert response.status_code == 307
+ assert response.headers["location"] == "https://invalid.com/favicon.ico"