Skip to content

Commit 284a2ba

Browse files
authored
bpo-28728: clarify possible test failure due to ISP (GH-412) (GH-531)
1 parent 130c4ec commit 284a2ba

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Lib/test/test_socket.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -803,11 +803,6 @@ def testHostnameRes(self):
803803
self.fail("Error testing host resolution mechanisms. (fqdn: %s, all: %s)" % (fqhn, repr(all_host_names)))
804804

805805
def test_host_resolution(self):
806-
for addr in ['0.1.1.~1', '1+.1.1.1', '::1q', '::1::2',
807-
'1:1:1:1:1:1:1:1:1']:
808-
self.assertRaises(OSError, socket.gethostbyname, addr)
809-
self.assertRaises(OSError, socket.gethostbyaddr, addr)
810-
811806
for addr in [support.HOST, '10.0.0.1', '255.255.255.255']:
812807
self.assertEqual(socket.gethostbyname(addr), addr)
813808

@@ -816,6 +811,21 @@ def test_host_resolution(self):
816811
for host in [support.HOST]:
817812
self.assertIn(host, socket.gethostbyaddr(host)[2])
818813

814+
def test_host_resolution_bad_address(self):
815+
# These are all malformed IP addresses and expected not to resolve to
816+
# any result. But some ISPs, e.g. AWS, may successfully resolve these
817+
# IPs.
818+
explanation = (
819+
"resolving an invalid IP address did not raise OSError; "
820+
"can be caused by a broken DNS server"
821+
)
822+
for addr in ['0.1.1.~1', '1+.1.1.1', '::1q', '::1::2',
823+
'1:1:1:1:1:1:1:1:1']:
824+
with self.assertRaises(OSError):
825+
socket.gethostbyname(addr)
826+
with self.assertRaises(OSError, msg=explanation):
827+
socket.gethostbyaddr(addr)
828+
819829
@unittest.skipUnless(hasattr(socket, 'sethostname'), "test needs socket.sethostname()")
820830
@unittest.skipUnless(hasattr(socket, 'gethostname'), "test needs socket.gethostname()")
821831
def test_sethostname(self):

0 commit comments

Comments
 (0)