summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_socket.py
diff options
context:
space:
mode:
authorCharles-François Natali <cf.natali@gmail.com>2013-09-13 17:53:08 (GMT)
committerCharles-François Natali <cf.natali@gmail.com>2013-09-13 17:53:08 (GMT)
commit0cc86850b69c23ab834ae2c97c5dc8b717420a38 (patch)
treef23470e923bbc8686452e4ece2ee32babcb76f85 /Lib/test/test_socket.py
parent12f18289c0481ffc1731dfa606baa9f65baa6478 (diff)
downloadcpython-0cc86850b69c23ab834ae2c97c5dc8b717420a38.zip
cpython-0cc86850b69c23ab834ae2c97c5dc8b717420a38.tar.gz
cpython-0cc86850b69c23ab834ae2c97c5dc8b717420a38.tar.bz2
Issue #16201: socket: Use inet_pton()/inet_addr() instead of ad-hoc parsing for
numeric IP addresses.
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r--Lib/test/test_socket.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 490f776..e995c99 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -757,6 +757,20 @@ class GeneralModuleTests(unittest.TestCase):
if not fqhn in all_host_names:
self.fail("Error testing host resolution mechanisms. (fqdn: %s, all: %s)" % (fqhn, repr(all_host_names)))
+ def test_host_resolution(self):
+ for addr in ['0.1.1.~1', '1+.1.1.1', '::1q', '::1::2',
+ '1:1:1:1:1:1:1:1:1']:
+ self.assertRaises(OSError, socket.gethostbyname, addr)
+ self.assertRaises(OSError, socket.gethostbyaddr, addr)
+
+ for addr in [support.HOST, '10.0.0.1', '255.255.255.255']:
+ self.assertEqual(socket.gethostbyname(addr), addr)
+
+ # we don't test support.HOSTv6 because there's a chance it doesn't have
+ # a matching name entry (e.g. 'ip6-localhost')
+ for host in [support.HOST]:
+ self.assertIn(host, socket.gethostbyaddr(host)[2])
+
@unittest.skipUnless(hasattr(socket, 'sethostname'), "test needs socket.sethostname()")
@unittest.skipUnless(hasattr(socket, 'gethostname'), "test needs socket.gethostname()")
def test_sethostname(self):