Skip to content

Commit d5e1159

Browse files
committed
test openziti.monkeypatch() bypass connections
1 parent 75666a6 commit d5e1159

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/openziti/zitilib.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ def ziti_socket(type):
229229

230230

231231
def ziti_close(fd):
232-
_ziti_close(fd)
232+
if fd:
233+
_ziti_close(fd)
233234

234235

235236
def shutdown():

tests/ziti_tests.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_monkeypatch(self):
3939
with self.assertRaises(ConnectionError):
4040
get_httpbin('http://httpbin.ziti/json')
4141

42-
def test_resolve(selfs):
42+
def test_resolve(self):
4343
with openziti.monkeypatch():
4444
import socket
4545
addrlist = socket.getaddrinfo(host='httpbin.ziti', port=80, type=socket.SOCK_STREAM)
@@ -54,3 +54,12 @@ def test_resolve(selfs):
5454
assert addr[1] == 80
5555
assert addr[0].startswith('100.64.0.')
5656

57+
def test_monkeypatch_bypass(self):
58+
with openziti.monkeypatch():
59+
from json import dumps
60+
r = get_httpbin('http://httpbin.org/anything')
61+
assert r.status_code == 200
62+
body = r.json()
63+
print(dumps(body, indent=2))
64+
self.assertRegex(body['headers']['User-Agent'], r'python-requests/.*')
65+

0 commit comments

Comments
 (0)