Parcourir la source

[772] Small cleanups

Michal 'vorner' Vaner il y a 13 ans
Parent
commit
66ebc54e86
2 fichiers modifiés avec 18 ajouts et 10 suppressions
  1. 15 10
      src/bin/xfrout/tests/xfrout_test.py.in
  2. 3 0
      src/bin/xfrout/xfrout.py.in

+ 15 - 10
src/bin/xfrout/tests/xfrout_test.py.in

@@ -555,16 +555,21 @@ class TestUnixSockServer(unittest.TestCase):
         sock.connect(('127.0.0.1', 12345))
         self.assertEqual(('127.0.0.1', 12345),
                          self.unix._guess_remote(sock.fileno()))
-        sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
-        sock.connect(('::1', 12345))
-        self.assertEqual(('::1', 12345, 0, 0),
-                         self.unix._guess_remote(sock.fileno()))
-        # Try when pretending there's no IPv6 support
-        xfrout.socket.has_ipv6 = False
-        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
-        sock.connect(('127.0.0.1', 12345))
-        self.assertEqual(('127.0.0.1', 12345),
-                         self.unix._guess_remote(sock.fileno()))
+        if socket.has_ipv6:
+            # Don't check IPv6 address on hosts not supporting them
+            sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
+            sock.connect(('::1', 12345))
+            self.assertEqual(('::1', 12345, 0, 0),
+                             self.unix._guess_remote(sock.fileno()))
+            # Try when pretending there's no IPv6 support
+            # (No need to pretend when there's really no IPv6)
+            xfrout.socket.has_ipv6 = False
+            sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+            sock.connect(('127.0.0.1', 12345))
+            self.assertEqual(('127.0.0.1', 12345),
+                             self.unix._guess_remote(sock.fileno()))
+            # Return it back
+            xfrout.socket.has_ipv6 = True
 
     def test_receive_query_message(self):
         send_msg = b"\xd6=\x00\x00\x00\x01\x00"

+ 3 - 0
src/bin/xfrout/xfrout.py.in

@@ -400,6 +400,9 @@ class UnixSockServer(socketserver_mixin.NoPollMixIn, ThreadingUnixStreamServer):
     def _common_init(self):
         self._lock = threading.Lock()
         self._transfers_counter = 0
+        # This default value will probably get overwritten by the (same)
+        # default value from the spec file. This is here just to make
+        # sure and to make the default value in tests consistent.
         self._acl = REQUEST_LOADER.load('[{"action": "ACCEPT"}]')
 
     def _receive_query_message(self, sock):