Skip to content

Commit 400a6cf

Browse files
authored
fix(test): ssl test to work with pytest 3.12 (#6059)
ssl.wrap_socket was deprecated in python 3.7 and is removed in 3.12. This change fixes the test by using ssl.SSLContext instead. Signed-off-by: Roman Gershman <[email protected]>
1 parent 67c51eb commit 400a6cf

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

tests/dragonfly/connection_test.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,21 +1088,22 @@ async def test_tls_when_read_write_is_interleaved(
10881088
server: DflyInstance = df_factory.create(
10891089
port=1211, **with_ca_tls_server_args, proactor_threads=1
10901090
)
1091-
# TODO(kostas): to fix the deadlock in the test
1091+
10921092
server.start()
10931093

10941094
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
10951095

10961096
ssl_key = with_ca_tls_client_args["ssl_keyfile"]
10971097
ssl_cert = with_ca_tls_client_args["ssl_certfile"]
10981098
ssl_ca_cert = with_ca_tls_client_args["ssl_ca_certs"]
1099-
ssl_sock = ssl.wrap_socket(
1100-
s,
1101-
keyfile=ssl_key,
1102-
certfile=ssl_cert,
1103-
ca_certs=ssl_ca_cert,
1104-
ssl_version=ssl.PROTOCOL_TLSv1_2,
1105-
)
1099+
1100+
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
1101+
context.load_verify_locations(ssl_ca_cert)
1102+
context.load_cert_chain(certfile=ssl_cert, keyfile=ssl_key)
1103+
context.verify_mode = ssl.CERT_REQUIRED
1104+
context.maximum_version = ssl.TLSVersion.TLSv1_2
1105+
1106+
ssl_sock = context.wrap_socket(s, server_hostname="localhost")
11061107
ssl_sock.connect(("127.0.0.1", server.port))
11071108
ssl_sock.settimeout(0.1)
11081109

tests/dragonfly/utility.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,15 +752,17 @@ def gen_ca_cert(ca_key_path, ca_cert_path):
752752
# In production, CA should be generated by a third party authority
753753
# Expires in one day and is not encrtypted (-nodes)
754754
# X.509 format for the key
755-
step = rf'openssl req -x509 -newkey rsa:4096 -days 1 -nodes -keyout {ca_key_path} -out {ca_cert_path} -subj "/C=GR/ST=SKG/L=Thessaloniki/O=KK/OU=AcmeStudios/CN=Gr/[email protected]"'
755+
step = rf"openssl req -x509 -newkey rsa:4096 -days 1 -nodes -keyout {ca_key_path} -out {ca_cert_path} "
756+
step += '-subj "/C=GR/ST=SKG/L=Thessaloniki/O=KK/OU=AcmeStudios/CN=localhost/[email protected]"'
756757
subprocess.run(step, shell=True)
757758

758759

759760
def gen_certificate(
760761
ca_key_path, ca_certificate_path, certificate_request_path, private_key_path, certificate_path
761762
):
762763
# Generate Dragonfly's private key and certificate signing request (CSR)
763-
step1 = rf'openssl req -newkey rsa:4096 -nodes -keyout {private_key_path} -out {certificate_request_path} -subj "/C=GR/ST=SKG/L=Thessaloniki/O=KK/OU=Comp/CN=Gr/[email protected]"'
764+
step1 = rf"openssl req -newkey rsa:4096 -nodes -keyout {private_key_path} -out {certificate_request_path} "
765+
step1 += '-subj "/C=GR/ST=SKG/L=Thessaloniki/O=KK/OU=Comp/CN=localhost/[email protected]"'
764766
subprocess.run(step1, shell=True)
765767

766768
# Use CA's private key to sign dragonfly's CSR and get back the signed certificate

0 commit comments

Comments
 (0)