| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bade87e commit 016a485
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1822,13 +1822,9 @@ def test_connect(self): | |||
| 1822 | 1822 | with test_wrap_socket(socket.socket(socket.AF_INET), | |
| 1823 | 1823 | cert_reqs=ssl.CERT_REQUIRED, | |
| 1824 | 1824 | ca_certs=SIGNING_CA) as s: | |
| 1825 | - try: | ||
| 1826 | - s.connect(self.server_addr) | ||
| 1827 | - self.assertTrue(s.getpeercert()) | ||
| 1828 | - self.assertFalse(s.server_side) | ||
| 1829 | - except (ConnectionResetError, ConnectionAbortedError) as e: | ||
| 1830 | - # sometimes windows throws ConnectionResetError during the handshake | ||
| 1831 | - sys.stdout.write(repr(e)) | ||
| 1825 | + s.connect(self.server_addr) | ||
| 1826 | + self.assertTrue(s.getpeercert()) | ||
| 1827 | + self.assertFalse(s.server_side) | ||
| 1832 | 1828 | ||
| 1833 | 1829 | def test_connect_fail(self): | |
| 1834 | 1830 | # This should fail because we have no verification certs. Connection | |
@@ -1885,18 +1881,13 @@ def test_connect_with_context(self): | |||
| 1885 | 1881 | with ctx.wrap_socket(socket.socket(socket.AF_INET), | |
| 1886 | 1882 | server_hostname="dummy") as s: | |
| 1887 | 1883 | s.connect(self.server_addr) | |
| 1888 | - self.assertEqual({}, s.getpeercert()) | ||
| 1889 | 1884 | ctx.verify_mode = ssl.CERT_REQUIRED | |
| 1890 | 1885 | # This should succeed because we specify the root cert | |
| 1891 | 1886 | ctx.load_verify_locations(SIGNING_CA) | |
| 1892 | 1887 | with ctx.wrap_socket(socket.socket(socket.AF_INET)) as s: | |
| 1893 | - try: | ||
| 1894 | - s.connect(self.server_addr) | ||
| 1895 | - cert = s.getpeercert() | ||
| 1896 | - self.assertTrue(cert) | ||
| 1897 | - except (ConnectionResetError, ConnectionRefusedError) as e: | ||
| 1898 | - # sometimes windows throws ConnectionResetError during the handshake | ||
| 1899 | - sys.stdout.write(repr(e)) | ||
| 1888 | + s.connect(self.server_addr) | ||
| 1889 | + cert = s.getpeercert() | ||
| 1890 | + self.assertTrue(cert) | ||
| 1900 | 1891 | ||
| 1901 | 1892 | def test_connect_with_context_fail(self): | |
| 1902 | 1893 | # This should fail because we have no verification certs. Connection | |
@@ -1928,13 +1919,9 @@ def test_connect_capath(self): | |||
| 1928 | 1919 | ctx.verify_mode = ssl.CERT_REQUIRED | |
| 1929 | 1920 | ctx.load_verify_locations(capath=BYTES_CAPATH) | |
| 1930 | 1921 | with ctx.wrap_socket(socket.socket(socket.AF_INET)) as s: | |
| 1931 | - try: | ||
| 1932 | - s.connect(self.server_addr) | ||
| 1933 | - cert = s.getpeercert() | ||
| 1934 | - self.assertTrue(cert) | ||
| 1935 | - except ConnectionResetError as e: | ||
| 1936 | - # sometimes windows throws ConnectionResetError during the handshake | ||
| 1937 | - sys.stdout.write(repr(e)) | ||
| 1922 | + s.connect(self.server_addr) | ||
| 1923 | + cert = s.getpeercert() | ||
| 1924 | + self.assertTrue(cert) | ||
| 1938 | 1925 | ||
| 1939 | 1926 | def test_connect_cadata(self): | |
| 1940 | 1927 | with open(SIGNING_CA) as f: | |
@@ -2248,7 +2235,7 @@ def wrap_conn(self): | |||
| 2248 | 2235 | if support.verbose and self.server.chatty: | |
| 2249 | 2236 | sys.stdout.write(" client cert is " + pprint.pformat(cert) + "\n") | |
| 2250 | 2237 | cert_binary = self.sslconn.getpeercert(True) | |
| 2251 | - if support.verbose and self.server.chatty and cert_binary != None: | ||
| 2238 | + if support.verbose and self.server.chatty: | ||
| 2252 | 2239 | sys.stdout.write(" cert binary is " + str(len(cert_binary)) + " bytes\n") | |
| 2253 | 2240 | cipher = self.sslconn.cipher() | |
| 2254 | 2241 | if support.verbose and self.server.chatty: | |
@@ -2347,8 +2334,9 @@ def run(self): | |||
| 2347 | 2334 | sys.stdout.write(" server: read %r (%s), sending back %r (%s)...\n" | |
| 2348 | 2335 | % (msg, ctype, msg.lower(), ctype)) | |
| 2349 | 2336 | self.write(msg.lower()) | |
| 2350 | - except ConnectionResetError: | ||
| 2351 | - # XXX: OpenSSL 1.1.1 sometimes raises ConnectionResetError | ||
| 2337 | + except (ConnectionResetError, ConnectionAbortedError): | ||
| 2338 | + # XXX: OpenSSL 1.1.1 sometimes raises ConnectionResetError | ||
| 2339 | + # or ConnectionAbortedError (on Windows) | ||
| 2352 | 2340 | # when connection is not shut down gracefully. | |
| 2353 | 2341 | if self.server.chatty and support.verbose: | |
| 2354 | 2342 | sys.stdout.write( | |
@@ -2357,22 +2345,27 @@ def run(self): | |||
| 2357 | 2345 | ) | |
| 2358 | 2346 | self.close() | |
| 2359 | 2347 | self.running = False | |
| 2360 | - except OSError as err: | ||
| 2361 | - if 'peer did not return a certificate' in err.args[1]: | ||
| 2362 | - # test_pha_required_nocert causes this error which results in a false(?) failure | ||
| 2348 | + except ssl.SSLError as err: | ||
| 2349 | + # On Windows sometimes test_pha_required_nocert receives the | ||
| 2350 | + # PEER_DID_NOT_RETURN_A_CERTIFICATE exception | ||
| 2351 | + # before the 'tlsv13 alert certificate required' exception. | ||
| 2352 | + # If the server is stopped when PEER_DID_NOT_RETURN_A_CERTIFICATE | ||
| 2353 | + # is received test_pha_required_nocert fails with ConnectionResetError | ||
| 2354 | + # because the underlying socket is closed | ||
| 2355 | + if 'PEER_DID_NOT_RETURN_A_CERTIFICATE' == err.reason: | ||
| 2363 | 2356 | if self.server.chatty and support.verbose: | |
| 2364 | 2357 | sys.stdout.write(err.args[1]) | |
| 2365 | 2358 | # test_pha_required_nocert is expecting this exception | |
| 2366 | 2359 | raise ssl.SSLError('tlsv13 alert certificate required') | |
| 2367 | - else: | ||
| 2368 | - if self.server.chatty: | ||
| 2369 | - handle_error("Test server failure:\n") | ||
| 2370 | - self.close() | ||
| 2371 | - self.running = False | ||
| 2360 | + except OSError: | ||
| 2361 | + if self.server.chatty: | ||
| 2362 | + handle_error("Test server failure:\n") | ||
| 2363 | + self.close() | ||
| 2364 | + self.running = False | ||
| 2372 | 2365 | ||
| 2373 | - # normally, we'd just stop here, but for the test | ||
| 2374 | - # harness, we want to stop the server | ||
| 2375 | - self.server.stop() | ||
| 2366 | + # normally, we'd just stop here, but for the test | ||
| 2367 | + # harness, we want to stop the server | ||
| 2368 | + self.server.stop() | ||
| 2376 | 2369 | ||
| 2377 | 2370 | def __init__(self, certificate=None, ssl_version=None, | |
| 2378 | 2371 | certreqs=None, cacerts=None, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments