MCPcopy
hub / github.com/mitmproxy/mitmproxy / test_dual_stack

Function test_dual_stack

test/mitmproxy/proxy/test_mode_servers.py:367–398  ·  view source on GitHub ↗

Test that a server bound to "" binds on both IPv4 and IPv6 for both TCP and UDP.

(ip_version, protocol, caplog_async)

Source from the content-addressed store, hash-verified

365@pytest.mark.parametrize("ip_version", ["v4", "v6"])
366@pytest.mark.parametrize("protocol", ["tcp", "udp"])
367async def test_dual_stack(ip_version, protocol, caplog_async):
368 """Test that a server bound to "" binds on both IPv4 and IPv6 for both TCP and UDP."""
369
370 if ip_version == "v6" and no_ipv6:
371 pytest.skip("Skipped because IPv6 is unavailable.")
372
373 if ip_version == "v4":
374 addr = "127.0.0.1"
375 else:
376 addr = "::1"
377
378 caplog_async.set_level("DEBUG")
379 manager = MagicMock()
380 manager.connections = {}
381
382 with taddons.context():
383 inst = ServerInstance.make("dns@0", manager)
384 await inst.start()
385 assert await caplog_async.await_log("server listening")
386 _, port, *_ = inst.listen_addrs[0]
387
388 if protocol == "tcp":
389 _, stream = await asyncio.open_connection(addr, port)
390 else:
391 stream = await mitmproxy_rs.udp.open_udp_connection(addr, port)
392 stream.write(b"\x00\x00\x01")
393 assert await caplog_async.await_log("sent an invalid message")
394 stream.close()
395 await stream.wait_closed()
396
397 await inst.stop()
398 assert await caplog_async.await_log("stopped")
399
400
401@pytest.mark.parametrize("transport_protocol", ["udp", "tcp"])

Callers

nothing calls this directly

Calls 9

set_levelMethod · 0.80
contextMethod · 0.80
await_logMethod · 0.80
open_connectionMethod · 0.80
makeMethod · 0.45
startMethod · 0.45
writeMethod · 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…