Test that a server bound to "" binds on both IPv4 and IPv6 for both TCP and UDP.
(ip_version, protocol, caplog_async)
| 365 | @pytest.mark.parametrize("ip_version", ["v4", "v6"]) |
| 366 | @pytest.mark.parametrize("protocol", ["tcp", "udp"]) |
| 367 | async 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"]) |
nothing calls this directly
no test coverage detected
searching dependent graphs…