diff options
author | Hod Bin Noon <hodbn@users.noreply.github.com> | 2020-03-20 08:27:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-20 10:27:04 +0400 |
commit | 0b06d0c3c8dafd2c6ca459608df90df14fe353e6 (patch) | |
tree | 72c16fa3992f947e6b3538ef1cdf596c3480d22a | |
parent | eee53a69e1af019da18635d6974f893308db0ada (diff) | |
download | urllib3-0b06d0c3c8dafd2c6ca459608df90df14fe353e6.tar.gz |
Ensure test host resolves to IPv6 in tests (#1819)
* fix hang in TestSNI if client never connects
* handle insane ipv6 setup in tests
* update contributors
* more descriptive names in tests
Co-authored-by: Hod Bin Noon <bin.noon.hod@gmail.com>
-rw-r--r-- | CONTRIBUTORS.txt | 5 | ||||
-rwxr-xr-x | dummyserver/server.py | 16 | ||||
-rw-r--r-- | test/with_dummyserver/test_socketlevel.py | 3 |
3 files changed, 21 insertions, 3 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index f3fe3c46..b632da40 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -284,7 +284,7 @@ In chronological order: * Jorge Lopez Silva <https://github.com/jalopezsilva> * Added support for forwarding requests through HTTPS proxies. - + * Benno Rice <benno@jeamland.net> * Allow cadata parameter to be passed to underlying ``SSLContext.load_verify_locations()``. @@ -294,5 +294,8 @@ In chronological order: * Himanshu Garg <garg_himanshu@outlook.com> * DOC & LICENSE Update +* Hod Bin Noon <bin.noon.hod@gmail.com> + * Test improvements + * [Your name or handle] <[email or website]> * [Brief summary of your changes] diff --git a/dummyserver/server.py b/dummyserver/server.py index 76a44320..09f418a9 100755 --- a/dummyserver/server.py +++ b/dummyserver/server.py @@ -40,6 +40,20 @@ DEFAULT_CA = os.path.join(CERTS_PATH, "cacert.pem") DEFAULT_CA_KEY = os.path.join(CERTS_PATH, "cacert.key") +def _resolves_to_ipv6(host): + """ Returns True if the system resolves host to an IPv6 address by default. """ + resolves_to_ipv6 = False + try: + for res in socket.getaddrinfo(host, None, socket.AF_UNSPEC): + af, _, _, _, _ = res + if af == socket.AF_INET6: + resolves_to_ipv6 = True + except socket.gaierror: + pass + + return resolves_to_ipv6 + + def _has_ipv6(host): """ Returns True if the system can bind an IPv6 address. """ sock = None @@ -54,7 +68,7 @@ def _has_ipv6(host): try: sock = socket.socket(socket.AF_INET6) sock.bind((host, 0)) - has_ipv6 = True + has_ipv6 = _resolves_to_ipv6("localhost") except Exception: pass diff --git a/test/with_dummyserver/test_socketlevel.py b/test/with_dummyserver/test_socketlevel.py index dab353e1..c5f9c7b3 100644 --- a/test/with_dummyserver/test_socketlevel.py +++ b/test/with_dummyserver/test_socketlevel.py @@ -104,7 +104,8 @@ class TestSNI(SocketDummyServerTestCase): pool.request("GET", "/", retries=0) except MaxRetryError: # We are violating the protocol pass - done_receiving.wait() + successful = done_receiving.wait(LONG_TIMEOUT) + assert successful, "Timed out waiting for connection accept" assert ( self.host.encode("ascii") in self.buf ), "missing hostname in SSL handshake" |