@devries-cameron20 / composio-1 / commits / 9ba11dd24
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

test(py): isolate DNS-pinning tests from inherited proxies (#5290)

This PR: - closes https://github.com/ComposioHQ/composio/issues/5249 - makes `no_inherited_proxy` patch `get_environ_proxies` in both `requests.utils` and `requests.sessions` (which imports it by name), using the real `(url, no_proxy=None)` signature, so the session no longer routes the pinned request through a system, registry, or environment proxy - adds `test_pinning_ignores_an_inherited_proxy`, a real-socket test that runs the rebinding fetch under an unreachable inherited proxy, so Linux CI now catches a regression of the fixture - test-only: `composio/utils/url_safety.py` and the rebinding assertions are unchanged, so no changeset - credits @Siddharth-Dangi (co-author), whose branch identified the session-level lookup; this keeps that part and leaves out the extra `requests.compat`/`urllib.request` patches and the tests that only assert the mocks return `{}`, since the two `get_environ_proxies` names cover every lookup Requests makes ## Verification - `next`, `HTTP_PROXY=http://127.0.0.1:9` exported: 3 pinning tests fail with `ProxyError`; with this PR: 7 passed - Simulated macOS system proxy (patched `urllib.request.getproxies_macosx_sysconf`, no env proxy, no real settings touched): `next` 3 failed, this PR 7 passed - New test fails on the old fixture (`ProxyError ... Unable to connect to proxy`) and passes with the fix - Locked Python 3.12 env: full `python/tests` suite 2488 passed, 215 skipped; ruff check and format pass Co-authored-by: Siddharth-Dangi <mr.siddharthdangi@gmail.com>

Alberto Schiabel committed Nov 9, 2026 at 23:31 UTC 9ba11dd2481f0f5efd08c9078ac5e6cc93c839ba
1 file changed +35 -4
python/tests/test_url_safety_pinning.py
+35 -4
@@ -96,11 +96,16 @@ def no_inherited_proxy(monkeypatch: pytest.MonkeyPatch) -> None:
96 ``getproxies`` also reads) would disable the pinning adapter, and the
97 request would dial the proxy's answer to the hostname instead of the
98 validated address — failing these tests on machines that carry one.
99 +
100 + ``requests.sessions`` imports ``get_environ_proxies`` by name, so the
101 + session's own proxy lookup needs its own patch: without it the SDK sees no
102 + proxy and pins, while the session still routes through the inherited one.
103 """
100 - monkeypatch.setattr(
101 - "requests.utils.get_environ_proxies",
102 - lambda url: {},
103 - )
104 + for module in ("requests.utils", "requests.sessions"):
105 + monkeypatch.setattr(
106 + f"{module}.get_environ_proxies",
107 + lambda url, no_proxy=None: {},
108 + )
109
110
111 @pytest.fixture
@@ -195,6 +200,32 @@ def test_fetch_connects_to_the_address_it_validated(
200 assert rebound_server.hits == []
201
202
203 +@pytest.mark.usefixtures("rebinding_dns")
204 +def test_pinning_ignores_an_inherited_proxy(
205 + monkeypatch: pytest.MonkeyPatch,
206 + validated_server: _RecordingServer,
207 + rebound_server: _RecordingServer,
208 +) -> None:
209 + """``no_inherited_proxy`` must hold on machines that carry a proxy (#5249).
210 +
211 + A Windows registry or macOS system proxy reaches Requests through the same
212 + ``getproxies`` lookup as these variables, so an unreachable proxy here
213 + stands in for one this suite would otherwise inherit on those machines.
214 + """
215 + for name in ("HTTP_PROXY", "HTTPS_PROXY", "http_proxy", "https_proxy"):
216 + monkeypatch.setenv(name, "http://127.0.0.1:9")
217 + for name in ("NO_PROXY", "no_proxy"):
218 + monkeypatch.setenv(name, "")
219 +
220 + response = safe_get(
221 + f"http://{HOSTNAME}:{validated_server.port}/payload", timeout=(5, 5)
222 + )
223 +
224 + assert response.content == b"public payload"
225 + assert len(validated_server.hits) == 1
226 + assert rebound_server.hits == []
227 +
228 +
229 @pytest.mark.usefixtures("rebinding_dns")
230 def test_pinning_keeps_the_hostname_on_the_wire(
231 validated_server: _RecordingServer,