MCPcopy
hub / github.com/mitmproxy/mitmproxy / test_transparent

Function test_transparent

test/mitmproxy/proxy/test_mode_servers.py:138–169  ·  view source on GitHub ↗
(failure, monkeypatch, caplog_async)

Source from the content-addressed store, hash-verified

136
137@pytest.mark.parametrize("failure", [True, False])
138async def test_transparent(failure, monkeypatch, caplog_async):
139 caplog_async.set_level("INFO")
140 manager = MagicMock()
141
142 if failure:
143 monkeypatch.setattr(mitmproxy.platform, "original_addr", None)
144 else:
145 monkeypatch.setattr(
146 mitmproxy.platform, "original_addr", lambda s: ("address", 42)
147 )
148
149 with taddons.context(Proxyserver()) as tctx:
150 tctx.options.connection_strategy = "lazy"
151 inst = ServerInstance.make("transparent@127.0.0.1:0", manager)
152 await inst.start()
153 await caplog_async.await_log("listening")
154
155 host, port, *_ = inst.listen_addrs[0]
156 reader, writer = await asyncio.open_connection(host, port)
157
158 if failure:
159 assert await caplog_async.await_log("Transparent mode failure")
160 writer.close()
161 await writer.wait_closed()
162 else:
163 assert await caplog_async.await_log("client connect")
164 writer.close()
165 await writer.wait_closed()
166 assert await caplog_async.await_log("client disconnect")
167
168 await inst.stop()
169 assert await caplog_async.await_log("stopped")
170
171
172async def _echo_server(self: ConnectionHandler):

Callers

nothing calls this directly

Calls 9

ProxyserverClass · 0.90
set_levelMethod · 0.80
contextMethod · 0.80
await_logMethod · 0.80
open_connectionMethod · 0.80
makeMethod · 0.45
startMethod · 0.45
closeMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…