From b62bfc7c8ceffdcd60d6150c18814e92a4a75d0e Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 30 Sep 2026 15:32:32 +0200 Subject: [PATCH] cultnet-py: the explicit-bind test stays on loopback The test sent from an explicit 127.0.0.1 bind to a non-loopback address, which Windows refuses outright (WinError 10051), so it only held on Linux. It now binds 127.0.0.2 for a 127.0.0.1 endpoint, whose derived bind is 127.0.0.1, and checks the source address the listener sees. That still fails if the explicit host is ignored, on every platform, with no dependence on a non-loopback route. Co-Authored-By: Claude Opus 5.5 --- packages/cultnet-py/tests/test_cultnet.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/cultnet-py/tests/test_cultnet.py b/packages/cultnet-py/tests/test_cultnet.py index 0d707730..4f3984b7 100644 --- a/packages/cultnet-py/tests/test_cultnet.py +++ b/packages/cultnet-py/tests/test_cultnet.py @@ -2446,24 +2446,31 @@ class CultNetRudpClientBindTests(unittest.TestCase): finally: listener.close() + # The endpoint alone would bind 127.0.0.1; the explicit host must win, and the + # source address shows which one was bound. It stays on loopback, because a + # loopback-bound socket cannot send off the host on Windows. def test_a_schema_transport_binds_an_explicit_bind_host(self) -> None: - address = _non_loopback_ipv4_address() - if address is None: - self.skipTest("no non-loopback IPv4 address on this host") + probe = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + try: + probe.bind(("127.0.0.2", 0)) + except OSError: + self.skipTest("127.0.0.2 is not a local address on this host") + finally: + probe.close() listener = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - listener.bind(("0.0.0.0", 0)) + listener.bind(("127.0.0.1", 0)) listener.settimeout(2.0) try: with self.assertRaises(TimeoutError): create_rudp_schema_transport( - host=address, + host="127.0.0.1", port=listener.getsockname()[1], connection_id=0x43554C54, timeout_seconds=0.2, - bind_host="127.0.0.1", + bind_host="127.0.0.2", ) _, source = listener.recvfrom(65535) - self.assertEqual(source[0], "127.0.0.1") + self.assertEqual(source[0], "127.0.0.2") finally: listener.close()