import socket import pytest @pytest.fixture(autouse=True) def _fake_public_dns(monkeypatch): """apps.feeds.services.ssrf_guard resolves a feed's real hostname via socket.getaddrinfo before every fetch. Tests use made-up hostnames like example.com/a.example.com purely as fixture data — they must not depend on real DNS/network access to pass that check, and must resolve deterministically regardless of this sandbox's network access. Every lookup here resolves to a fixed, definitely-public IP; tests that specifically exercise the "resolves to a non-public address" rejection path patch socket.getaddrinfo themselves instead. """ def _fake_getaddrinfo(host, *args, **kwargs): return [(socket.AF_INET, socket.SOCK_STREAM, 6, "", ("93.184.216.34", 0))] monkeypatch.setattr(socket, "getaddrinfo", _fake_getaddrinfo)