Skip to content

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

Closed as not planned
@felixc

Description

@felixc

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:

def disable_socket():
""" disable socket.socket to disable the Internet. useful in testing.
"""
def guarded(*args, **kwargs):
raise SocketBlockedError()
socket.socket = guarded

...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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is neededstaleMarked stale due to inactivity

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions