git » kxd » commit 26069a5

tests: Update deprecated ssl.wrap_socket() call

author Alberto Bertogli
2024-08-10 16:17:45 UTC
committer Alberto Bertogli
2024-08-10 16:17:45 UTC
parent d8ed805afe4150b74697c67682a0390dd8317e95

tests: Update deprecated ssl.wrap_socket() call

ssl.wrap_socket() has been deprecated and is no longer functional in
Python 3.12: https://docs.python.org/3/whatsnew/3.12.html#ssl.

This patch replaces it with the equivalent (in this context)
ssl.SSLContext.

tests/run_tests +4 -5

diff --git a/tests/run_tests b/tests/run_tests
index 8c8f84d..1782cc2 100755
--- a/tests/run_tests
+++ b/tests/run_tests
@@ -395,11 +395,10 @@ class TrickyRequests(TestCase):
 
     def test_server_cert(self):
         rawsock = socket.create_connection(("localhost", 19840))
-        sock = ssl.wrap_socket(
-            rawsock,
-            keyfile=self.client.key_path(),
-            certfile=self.client.cert_path(),
-        )
+        context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
+        context.load_verify_locations(self.server.cert_path())
+        context.check_hostname = False
+        sock = context.wrap_socket(rawsock)
 
         # We don't check the cipher itself, as it depends on the environment,
         # but we should be using >= 128 bit secrets.