pytest-socket icon indicating copy to clipboard operation
pytest-socket copied to clipboard

Feature request: Also block DNS lookups (socket.getaddrinfo)

Open felixc opened this issue 5 years ago • 3 comments

Thank you for this plugin, which helps keep our tests fast and safe! One piece of information that can still leak out even when using it, though, is DNS lookups. It would be great if we could also block calls to socket.getaddrinfo in the same way.

I believe this can be done in a basic way by adding socket.getaddrinfo = guarded to the disable_socket() method here: https://github.com/miketheman/pytest-socket/blob/cb5e7c51f3bff343d3899af26b112894138de988/pytest_socket.py#L73-L80

...and perhaps updating the exception message to not specifically reference socket.socket.

I have not sent a PR for this because I don't know the pytest API well enough to understand how and when disable_socket is getting called, or how this should interact with socket_allow_hosts() further down — but if that's not a concern, I'd be happy to submit that change for consideration.

Thanks again!

felixc avatar Jul 16 '20 16:07 felixc

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] avatar Jan 24 '22 02:01 github-actions[bot]

This issue was closed because it has been inactive for 30 days since being marked as stale.

github-actions[bot] avatar Feb 24 '22 01:02 github-actions[bot]

I think this is still a valid feature request? There's even been a PR for it (#64).

felixc avatar Feb 24 '22 02:02 felixc

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] avatar Dec 06 '24 02:12 github-actions[bot]

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] avatar Mar 07 '25 02:03 github-actions[bot]

This issue was closed because it has been inactive for 30 days since being marked as stale.

github-actions[bot] avatar Apr 06 '25 02:04 github-actions[bot]

I found this issue when trying to get a good working session in during a flight.

This is for sure still an issue, IMHO, since the whole idea is to make tests run without any external dependencies - and that includes DNS servers (i.e. any reliance on the internet).

tomage avatar Oct 17 '25 10:10 tomage