test(security): keep proxy-clearing fixtures hermetic on hosts with OS-level proxies
This commit is contained in:
1 parent
ddd6b302c9
commit
524e96ff68
4 files changed
+16
No files matched your search
@@ -5,6 +5,7 @@ from __future__ import annotations
|
|||||||
import ipaddress
|
import ipaddress
|
||||||
import socket
|
import socket
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
from urllib.request import getproxies_environment
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@@ -42,6 +43,9 @@ def test_is_loopback_host_rejects_network_targets(host: str) -> None:
|
|||||||
def _clear_proxy_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
def _clear_proxy_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
for name in (*_PROXY_ENV_VARS, "NO_PROXY", "no_proxy"):
|
for name in (*_PROXY_ENV_VARS, "NO_PROXY", "no_proxy"):
|
||||||
monkeypatch.delenv(name, raising=False)
|
monkeypatch.delenv(name, raising=False)
|
||||||
|
# getproxies() falls back to OS-level proxy settings (e.g. the Windows
|
||||||
|
# registry) when no environment variables are set; keep tests hermetic.
|
||||||
|
monkeypatch.setattr("nanobot.security.network.getproxies", getproxies_environment)
|
||||||
|
|
||||||
|
|
||||||
def _fake_resolve(host: str, results: list[str]):
|
def _fake_resolve(host: str, results: list[str]):
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from __future__ import annotations
|
|||||||
import asyncio
|
import asyncio
|
||||||
import socket
|
import socket
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
from urllib.request import getproxies_environment
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
import pytest
|
import pytest
|
||||||
@@ -21,6 +22,9 @@ _PROXY_ENV_VARS = ("HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY", "http_proxy", "http
|
|||||||
def _clear_proxy_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
def _clear_proxy_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
for name in (*_PROXY_ENV_VARS, "NO_PROXY", "no_proxy"):
|
for name in (*_PROXY_ENV_VARS, "NO_PROXY", "no_proxy"):
|
||||||
monkeypatch.delenv(name, raising=False)
|
monkeypatch.delenv(name, raising=False)
|
||||||
|
# getproxies() falls back to OS-level proxy settings (e.g. the Windows
|
||||||
|
# registry) when no environment variables are set; keep tests hermetic.
|
||||||
|
monkeypatch.setattr("nanobot.security.network.getproxies", getproxies_environment)
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import sys
|
|||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from types import ModuleType, SimpleNamespace
|
from types import ModuleType, SimpleNamespace
|
||||||
|
from urllib.request import getproxies_environment
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
import pytest
|
import pytest
|
||||||
@@ -65,6 +66,9 @@ def fake_mcp_runtime() -> dict[str, object | None]:
|
|||||||
def _clear_proxy_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
def _clear_proxy_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
for name in (*_PROXY_ENV_VARS, "NO_PROXY", "no_proxy"):
|
for name in (*_PROXY_ENV_VARS, "NO_PROXY", "no_proxy"):
|
||||||
monkeypatch.delenv(name, raising=False)
|
monkeypatch.delenv(name, raising=False)
|
||||||
|
# getproxies() falls back to OS-level proxy settings (e.g. the Windows
|
||||||
|
# registry) when no environment variables are set; keep tests hermetic.
|
||||||
|
monkeypatch.setattr("nanobot.security.network.getproxies", getproxies_environment)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import asyncio
|
|||||||
import json
|
import json
|
||||||
import socket
|
import socket
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
from urllib.request import getproxies_environment
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
import pytest
|
import pytest
|
||||||
@@ -28,6 +29,9 @@ _PROXY_ENV_VARS = ("HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY", "http_proxy", "http
|
|||||||
def _clear_proxy_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
def _clear_proxy_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
for name in (*_PROXY_ENV_VARS, "NO_PROXY", "no_proxy"):
|
for name in (*_PROXY_ENV_VARS, "NO_PROXY", "no_proxy"):
|
||||||
monkeypatch.delenv(name, raising=False)
|
monkeypatch.delenv(name, raising=False)
|
||||||
|
# getproxies() falls back to OS-level proxy settings (e.g. the Windows
|
||||||
|
# registry) when no environment variables are set; keep tests hermetic.
|
||||||
|
monkeypatch.setattr("nanobot.security.network.getproxies", getproxies_environment)
|
||||||
|
|
||||||
|
|
||||||
def _fake_resolve_private(hostname, port, family=0, type_=0):
|
def _fake_resolve_private(hostname, port, family=0, type_=0):
|
||||||
|
|||||||
Reference in new issue
Block a user