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 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-30 15:32:32 +02:00
commit b62bfc7c8c

View file

@ -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()