Commit graph

3 commits

Author SHA1 Message Date
Simon Chopin
89a282c12e test_net: figure out the proper IP protocol for localhost
On some systems, localhost is only defined for 127.0.0.1 (e.g. Ubuntu
and Debian containers). However, there is code that hardcodes possible
values for localhost, making it possible to open an IPv6 socket for
localhost.

On those systems, the socket will be open but urllib3 will resolve
localhost *only* to 127.0.0.1, thus failing miserably to connect.

To resolve the situation, rather than defaulting to IPv6 we actually
resolve localhost and use the socket family of the first result. On my
current system (upcoming Ubuntu Plucky) if localhost=::1 is defined in
/etc/hosts it will come up as the first result, if not 127.0.0.1 will.

V2: Use self.port rather than a forgotten hardcoded port.

Fixes: f01628ca6b "fix localhost network tests on systems with IPv6"
2025-01-20 10:33:49 +00:00
Hans-Christoph Steiner
f01628ca6b fix localhost network tests on systems with IPv6
Thanks to themill from Debian for this suggestion:

> https://docs.python.org/3/library/socket.html#socket.socket makes me
> think socket.socket has done an ipv4 only but urilib3 will do
> whatever localhost resolves to.  I suspect the test code should be
> using socket.create_server - there's an example at
> https://docs.python.org/3/library/socket.html#socket.create_server
2024-12-12 15:19:58 +00:00
SilentGhost
7ff32bc4b0 Refactor TestCase files into python modules
Convert all TestCase files into standard python modules to be run and
discovered by unittest.
2024-11-20 10:37:52 +01:00
Renamed from tests/net.TestCase (Browse further)