Skip to content

Commit 3428820

Browse files
committed
Don't intercept TLS connections in tests.
This avoids mixing TLS termination by mitmproxy and by websockets.
1 parent 02feb6d commit 3428820

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

tests/proxy.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
import pathlib
32
import threading
43
import warnings
54

@@ -21,7 +20,7 @@ def __init__(self, on_running):
2120
self.running = on_running
2221
self.flows = []
2322

24-
def websocket_start(self, flow):
23+
def tcp_start(self, flow):
2524
self.flows.append(flow)
2625

2726
def get_flows(self):
@@ -48,7 +47,13 @@ async def run_proxy(cls):
4847
cls.proxy_loop = loop = asyncio.get_event_loop()
4948
cls.proxy_stop = stop = loop.create_future()
5049

51-
cls.proxy_options = options = Options(mode=[cls.proxy_mode])
50+
cls.proxy_options = options = Options(
51+
mode=[cls.proxy_mode],
52+
# Don't intercept connections, but record them.
53+
ignore_hosts=["^localhost:", "^127.0.0.1:", "^::1:"],
54+
# This option requires mitmproxy 11.0.0, which requires Python 3.11.
55+
show_ignored_hosts=True,
56+
)
5257
cls.proxy_master = master = Master(options)
5358
master.addons.add(
5459
core.Core(),
@@ -58,12 +63,6 @@ async def run_proxy(cls):
5863
tlsconfig.TlsConfig(),
5964
RecordFlows(on_running=cls.proxy_ready.set),
6065
)
61-
options.update(
62-
# Use test certificate for TLS between client and proxy.
63-
certs=[str(pathlib.Path(__file__).with_name("test_localhost.pem"))],
64-
# Disable TLS verification between proxy and upstream.
65-
ssl_insecure=True,
66-
)
6766

6867
task = loop.create_task(cls.proxy_master.run())
6968
await stop

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ commands =
1515
pass_env =
1616
WEBSOCKETS_*
1717
deps =
18-
mitmproxy
19-
python-socks[asyncio]
18+
py311,py312,py313,coverage,maxi_cov: mitmproxy
19+
py311,py312,py313,coverage,maxi_cov: python-socks[asyncio]
2020

2121
[testenv:coverage]
2222
commands =

0 commit comments

Comments
 (0)