summaryrefslogtreecommitdiff
path: root/Lib/test/test_socket.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r--Lib/test/test_socket.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 2851922bd0..b0e1b7471e 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -1594,6 +1594,72 @@ class GeneralModuleTests(unittest.TestCase):
with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s:
self.assertRaises(OverflowError, s.bind, (support.HOSTv6, 0, -10))
+ @unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test.')
+ def test_getaddrinfo_ipv6_basic(self):
+ ((*_, sockaddr),) = socket.getaddrinfo(
+ 'ff02::1de:c0:face:8D', # Note capital letter `D`.
+ 1234, socket.AF_INET6,
+ socket.SOCK_DGRAM,
+ socket.IPPROTO_UDP
+ )
+ self.assertEqual(sockaddr, ('ff02::1de:c0:face:8d', 1234, 0, 0))
+
+ @unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test.')
+ @unittest.skipUnless(
+ hasattr(socket, 'if_nameindex'),
+ 'if_nameindex is not supported')
+ def test_getaddrinfo_ipv6_scopeid_symbolic(self):
+ # Just pick up any network interface (Linux, Mac OS X)
+ (ifindex, test_interface) = socket.if_nameindex()[0]
+ ((*_, sockaddr),) = socket.getaddrinfo(
+ 'ff02::1de:c0:face:8D%' + test_interface,
+ 1234, socket.AF_INET6,
+ socket.SOCK_DGRAM,
+ socket.IPPROTO_UDP
+ )
+ # Note missing interface name part in IPv6 address
+ self.assertEqual(sockaddr, ('ff02::1de:c0:face:8d', 1234, 0, ifindex))
+
+ @unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test.')
+ @unittest.skipUnless(
+ sys.platform == 'win32',
+ 'Numeric scope id does not work or undocumented')
+ def test_getaddrinfo_ipv6_scopeid_numeric(self):
+ # Also works on Linux and Mac OS X, but is not documented (?)
+ # Windows, Linux and Max OS X allow nonexistent interface numbers here.
+ ifindex = 42
+ ((*_, sockaddr),) = socket.getaddrinfo(
+ 'ff02::1de:c0:face:8D%' + str(ifindex),
+ 1234, socket.AF_INET6,
+ socket.SOCK_DGRAM,
+ socket.IPPROTO_UDP
+ )
+ # Note missing interface name part in IPv6 address
+ self.assertEqual(sockaddr, ('ff02::1de:c0:face:8d', 1234, 0, ifindex))
+
+ @unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test.')
+ @unittest.skipUnless(
+ hasattr(socket, 'if_nameindex'),
+ 'if_nameindex is not supported')
+ def test_getnameinfo_ipv6_scopeid_symbolic(self):
+ # Just pick up any network interface.
+ (ifindex, test_interface) = socket.if_nameindex()[0]
+ sockaddr = ('ff02::1de:c0:face:8D', 1234, 0, ifindex) # Note capital letter `D`.
+ nameinfo = socket.getnameinfo(sockaddr, socket.NI_NUMERICHOST | socket.NI_NUMERICSERV)
+ self.assertEqual(nameinfo, ('ff02::1de:c0:face:8d%' + test_interface, '1234'))
+
+ @unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test.')
+ @unittest.skipUnless(
+ sys.platform == 'win32',
+ 'Numeric scope id does not work or undocumented')
+ def test_getnameinfo_ipv6_scopeid_numeric(self):
+ # Also works on Linux (undocumented), but does not work on Mac OS X
+ # Windows and Linux allow nonexistent interface numbers here.
+ ifindex = 42
+ sockaddr = ('ff02::1de:c0:face:8D', 1234, 0, ifindex) # Note capital letter `D`.
+ nameinfo = socket.getnameinfo(sockaddr, socket.NI_NUMERICHOST | socket.NI_NUMERICSERV)
+ self.assertEqual(nameinfo, ('ff02::1de:c0:face:8d%' + str(ifindex), '1234'))
+
def test_str_for_enums(self):
# Make sure that the AF_* and SOCK_* constants have enum-like string
# reprs.