]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
further test low_level_address_tuple()
authorBob Halley <halley@dnspython.org>
Wed, 17 Jun 2020 00:20:57 +0000 (17:20 -0700)
committerBob Halley <halley@dnspython.org>
Wed, 17 Jun 2020 00:20:57 +0000 (17:20 -0700)
tests/test_ntoaaton.py

index 3a72891fb526455a8128468039f51f0491a9f492..b5d425f996b321e0f03708145a3c766b757dfc9c 100644 (file)
@@ -284,6 +284,27 @@ class NtoAAtoNTestCase(unittest.TestCase):
         self.assertEqual(t, ('1.2.3.4', 53))
         t = dns.inet.low_level_address_tuple(('2600::1', 53), socket.AF_INET6)
         self.assertEqual(t, ('2600::1', 53, 0, 0))
+        t = dns.inet.low_level_address_tuple(('fd80::1%2', 53), socket.AF_INET6)
+        self.assertEqual(t, ('fd80::1', 53, 0, 2))
+        try:
+            # This can fail on windows for python < 3.8, so we tolerate
+            # the failure and only test if we have something we can work
+            # with.
+            info = socket.if_nameindex()
+        except Exception:
+            info = []
+        if info:
+            # find first thing on list that is not zero (should be first thing!
+            pair = None
+            for p in info:
+                if p[0] != 0:
+                    pair = p
+                    break
+            if pair:
+                address = 'fd80::1%' + pair[1]
+                t = dns.inet.low_level_address_tuple((address, 53),
+                                                     socket.AF_INET6)
+                self.assertEqual(t, ('fd80::1', 53, 0, pair[0]))
         def bad():
             bogus = socket.AF_INET + socket.AF_INET6 + 1
             t = dns.inet.low_level_address_tuple(('2600::1', 53), bogus)