From d9292e129b6166b0ad6885a44f600c16902d0e1c Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Sat, 11 Jul 2026 11:21:56 +0000 Subject: [PATCH] test: cover too-many-redirects path in async_safe_request --- .../litellm_core_utils/test_url_utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_litellm/litellm_core_utils/test_url_utils.py b/tests/test_litellm/litellm_core_utils/test_url_utils.py index 92da6c50d9a..5b672a17c9a 100644 --- a/tests/test_litellm/litellm_core_utils/test_url_utils.py +++ b/tests/test_litellm/litellm_core_utils/test_url_utils.py @@ -628,6 +628,20 @@ class TestAsyncSafeRequest: with pytest.raises(SSRFError): await async_safe_request(FakeClient(), "POST", "http://example.com/start") + async def test_too_many_redirects_raises(self, monkeypatch): + def fake(host, port, *a, **kw): + return [(socket.AF_INET, socket.SOCK_STREAM, 6, "", ("93.184.216.34", port))] + + monkeypatch.setattr(url_utils.socket, "getaddrinfo", fake) + monkeypatch.setattr(litellm, "user_url_validation", True) + + class FakeClient: + async def request(self, method, url, headers=None, follow_redirects=False, **kw): + return _FakeResponse(302, location="http://example.com/next") + + with pytest.raises(SSRFError, match="Too many redirects"): + await async_safe_request(FakeClient(), "POST", "http://example.com/start") + async def test_master_switch_disabled_bypasses_validation(self, monkeypatch): monkeypatch.setattr(litellm, "user_url_validation", False)