2026-07-19 20:36:56 +05:00
|
|
|
import socket
|
|
|
|
|
|
2026-07-19 20:42:43 +05:00
|
|
|
from savdoh.patch import patch_socket, unpatch_socket
|
2026-07-19 20:36:56 +05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_patch_and_unpatch_restores_original():
|
|
|
|
|
original = socket.getaddrinfo
|
|
|
|
|
patch_socket()
|
|
|
|
|
assert socket.getaddrinfo is not original
|
|
|
|
|
unpatch_socket()
|
|
|
|
|
assert socket.getaddrinfo is original
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_patch_is_idempotent():
|
|
|
|
|
patch_socket()
|
|
|
|
|
patched = socket.getaddrinfo
|
|
|
|
|
patch_socket()
|
|
|
|
|
assert socket.getaddrinfo is patched
|
|
|
|
|
unpatch_socket()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_ip_literal_bypasses_doh():
|
|
|
|
|
patch_socket()
|
|
|
|
|
try:
|
|
|
|
|
result = socket.getaddrinfo("127.0.0.1", 80)
|
|
|
|
|
assert result
|
|
|
|
|
finally:
|
|
|
|
|
unpatch_socket()
|