]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Hack around mac ipv6 firewall problems in bind_sockets to reenable tests.
authorBen Darnell <ben@bendarnell.com>
Sat, 3 May 2014 18:41:51 +0000 (14:41 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 18 May 2014 14:18:57 +0000 (10:18 -0400)
Fix a test ResourceWarning.

tornado/netutil.py
tornado/test/netutil_test.py

index 2042b91dd924d0449355f6eabf495a396923bdf3..7e37d0eaa9f89f6ba7bb391e787ba9a9b248ef9f 100644 (file)
@@ -20,6 +20,7 @@ from __future__ import absolute_import, division, print_function, with_statement
 
 import errno
 import os
+import platform
 import socket
 import stat
 
@@ -93,6 +94,15 @@ def bind_sockets(port, address=None, family=socket.AF_UNSPEC, backlog=128, flags
     for res in set(socket.getaddrinfo(address, port, family, socket.SOCK_STREAM,
                                       0, flags)):
         af, socktype, proto, canonname, sockaddr = res
+        if (platform.system() == 'Darwin' and address == 'localhost' and
+            af == socket.AF_INET6 and sockaddr[3] != 0):
+            # Mac OS X includes a link-local address fe80::1%lo0 in the
+            # getaddrinfo results for 'localhost'.  However, the firewall
+            # doesn't understand that this is a local address and will
+            # prompt for access (often repeatedly, due to an apparent
+            # bug in its ability to remember granting access to an
+            # application). Skip these addresses.
+            continue
         try:
             sock = socket.socket(af, socktype, proto)
         except socket.error as e:
index 0f18b3305ce8828d7dd44f929c48ae4cf5ed56ce..9f7c85cb5ef8fbc1ea2455f987a2ca2a3e062209 100644 (file)
@@ -1,6 +1,5 @@
 from __future__ import absolute_import, division, print_function, with_statement
 
-import platform
 import signal
 import socket
 from subprocess import Popen
@@ -154,15 +153,13 @@ class IsValidIPTest(unittest.TestCase):
         self.assertTrue(not is_valid_ip('\x00'))
 
 
-# The mac firewall prompts when listening on "localhost" instead of
-# "127.0.0.1" like the other tests use (maybe due to the ipv6
-# link-local address fe80::1%lo0?), and it doesn't remember whether
-# you've previously allowed or denied access.  It's better to skip this
-# test on the mac than to have the prompts come up for every configuration
-# in tox.ini.
-@unittest.skipIf(platform.system() == 'Darwin', 'avoid firewall prompts on Mac')
 class TestPortAllocation(unittest.TestCase):
     def test_same_port_allocation(self):
         sockets = bind_sockets(None, 'localhost')
-        port = sockets[0].getsockname()[1]
-        self.assertTrue(all(s.getsockname()[1] == port for s in sockets[1:]))
+        try:
+            port = sockets[0].getsockname()[1]
+            self.assertTrue(all(s.getsockname()[1] == port
+                                for s in sockets[1:]))
+        finally:
+            for sock in sockets:
+                sock.close()