test: cover too-many-redirects path in async_safe_request

This commit is contained in:
Devin AI 2026-07-11 11:21:56 +00:00
parent 7e5e5d424f
commit d9292e129b

View file

@ -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)