]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43921: Cleanup test_ssl.test_wrong_cert_tls13() (GH-26520)
authorVictor Stinner <vstinner@python.org>
Thu, 3 Jun 2021 20:12:31 +0000 (22:12 +0200)
committerGitHub <noreply@github.com>
Thu, 3 Jun 2021 20:12:31 +0000 (22:12 +0200)
Don't catch OSError, and check the SSLError message.

Lib/test/test_ssl.py

index 85ad8ae827a8032e65de490f604d28049a13abbf..fdf5f19d8d4c536e6b50c99988000493fce3c252 100644 (file)
@@ -3192,23 +3192,16 @@ class ThreadedTests(unittest.TestCase):
              client_context.wrap_socket(socket.socket(),
                                         server_hostname=hostname,
                                         suppress_ragged_eofs=False) as s:
-            # TLS 1.3 perform client cert exchange after handshake
             s.connect((HOST, server.port))
-            try:
+            with self.assertRaisesRegex(
+                ssl.SSLError,
+                'alert unknown ca|EOF occurred'
+            ):
+                # TLS 1.3 perform client cert exchange after handshake
                 s.write(b'data')
                 s.read(1000)
                 s.write(b'should have failed already')
                 s.read(1000)
-            except ssl.SSLError as e:
-                if support.verbose:
-                    sys.stdout.write("\nSSLError is %r\n" % e)
-            except OSError as e:
-                if e.errno != errno.ECONNRESET:
-                    raise
-                if support.verbose:
-                    sys.stdout.write("\nsocket.error is %r\n" % e)
-            else:
-                self.fail("Use of invalid cert should have failed!")
 
     def test_rude_shutdown(self):
         """A brutal shutdown of an SSL server should raise an OSError