From f62dcc6a2f9dba8aff5e9782d72711a7785800a8 Mon Sep 17 00:00:00 2001 From: Ee Durbin Date: Thu, 7 Sep 2023 09:38:57 -0400 Subject: [PATCH 1/2] gh-75743: Restore test_timeout.testConnectTimeout() This un-skips this test now that pythontest.net implements appropriate firewall rules for it. --- Lib/test/test_timeout.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/Lib/test/test_timeout.py b/Lib/test/test_timeout.py index 30e843a423a777b..a48a86e7728d119 100644 --- a/Lib/test/test_timeout.py +++ b/Lib/test/test_timeout.py @@ -148,13 +148,12 @@ def setUp(self): def tearDown(self): self.sock.close() - @unittest.skipIf(True, 'need to replace these hosts; see bpo-35518') def testConnectTimeout(self): # Testing connect timeout is tricky: we need to have IP connectivity # to a host that silently drops our packets. We can't simulate this # from Python because it's a function of the underlying TCP/IP stack. - # So, the following Snakebite host has been defined: - blackhole = resolve_address('blackhole.snakebite.net', 56666) + # So, the following port on the pythontest.net host has been defined: + blackhole = resolve_address('pythontest.net', 56666) # Blackhole has been configured to silently drop any incoming packets. # No RSTs (for TCP) or ICMP UNREACH (for UDP/ICMP) will be sent back @@ -166,7 +165,7 @@ def testConnectTimeout(self): # to firewalling or general network configuration. In order to improve # our confidence in testing the blackhole, a corresponding 'whitehole' # has also been set up using one port higher: - whitehole = resolve_address('whitehole.snakebite.net', 56667) + whitehole = resolve_address('pythontest.net', 56667) # This address has been configured to immediately drop any incoming # packets as well, but it does it respectfully with regards to the @@ -180,19 +179,15 @@ def testConnectTimeout(self): # timeframe). # For the records, the whitehole/blackhole configuration has been set - # up using the 'pf' firewall (available on BSDs), using the following: + # up using the 'iptables' firewall, using the following rules: # - # ext_if="bge0" + # -A INPUT -p tcp --destination-port 56666 -j DROP + # -A INPUT -p udp --destination-port 56666 -j DROP + # -A INPUT -p tcp --destination-port 56667 -j RETURN + # -A INPUT -p udp --destination-port 56667 -j RETURN # - # blackhole_ip="35.8.247.6" - # whitehole_ip="35.8.247.6" - # blackhole_port="56666" - # whitehole_port="56667" - # - # block return in log quick on $ext_if proto { tcp udp } \ - # from any to $whitehole_ip port $whitehole_port - # block drop in log quick on $ext_if proto { tcp udp } \ - # from any to $blackhole_ip port $blackhole_port + # See pillar/base/firewall/snakebite.sls in + # https://github.com/python/psf-salt for the current configuration. # skip = True From 1aed13b304c51548b746a6089858e53023a1c4dc Mon Sep 17 00:00:00 2001 From: Ee Durbin Date: Thu, 7 Sep 2023 11:50:41 -0400 Subject: [PATCH 2/2] update comment to reflect update to pythontest.net firewall Ref: https://github.com/python/psf-salt/commit/0e2a423637b89c87fe0ac5972e615600a81e9e00 RETURN was relying on default REJECT, explicitly REJECT in INPUT --- Lib/test/test_timeout.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_timeout.py b/Lib/test/test_timeout.py index a48a86e7728d119..35ff56f1a5ee091 100644 --- a/Lib/test/test_timeout.py +++ b/Lib/test/test_timeout.py @@ -183,12 +183,11 @@ def testConnectTimeout(self): # # -A INPUT -p tcp --destination-port 56666 -j DROP # -A INPUT -p udp --destination-port 56666 -j DROP - # -A INPUT -p tcp --destination-port 56667 -j RETURN - # -A INPUT -p udp --destination-port 56667 -j RETURN - # - # See pillar/base/firewall/snakebite.sls in - # https://github.com/python/psf-salt for the current configuration. + # -A INPUT -p tcp --destination-port 56667 -j REJECT + # -A INPUT -p udp --destination-port 56667 -j REJECT # + # See https://github.com/python/psf-salt/blob/main/pillar/base/firewall/snakebite.sls + # for the current configuration. skip = True sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)