From ba0d542bd14938d48d78187b3f3d2d5bbdb36bfb Mon Sep 17 00:00:00 2001 From: Alban Diquet Date: Thu, 26 Dec 2024 10:06:22 +0100 Subject: [PATCH] Add some type annotations --- tests/ssl_client_test.py | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/ssl_client_test.py b/tests/ssl_client_test.py index 364bab3..a6ac2f6 100644 --- a/tests/ssl_client_test.py +++ b/tests/ssl_client_test.py @@ -32,7 +32,7 @@ # TODO(AD): Switch to legacy server and add a TODO; skip tests for TLS 1.3 @pytest.mark.parametrize("ssl_client_cls", [SslClient, LegacySslClient]) class TestSslClientClientAuthentication: - def test_client_authentication_no_certificate_supplied(self, ssl_client_cls): + def test_client_authentication_no_certificate_supplied(self, ssl_client_cls) -> None: # Given a server that requires client authentication with LegacyOpenSslServer(client_auth_config=ClientAuthConfigEnum.REQUIRED) as server: # And the client does NOT provide a client certificate @@ -51,7 +51,7 @@ def test_client_authentication_no_certificate_supplied(self, ssl_client_cls): ssl_client.shutdown() - def test_client_authentication_no_certificate_supplied_but_ignore(self, ssl_client_cls): + def test_client_authentication_no_certificate_supplied_but_ignore(self, ssl_client_cls) -> None: # Given a server that accepts optional client authentication with LegacyOpenSslServer(client_auth_config=ClientAuthConfigEnum.OPTIONAL) as server: # And the client does NOT provide a client cert but is configured to ignore the client auth request @@ -71,7 +71,7 @@ def test_client_authentication_no_certificate_supplied_but_ignore(self, ssl_clie finally: ssl_client.shutdown() - def test_client_authentication_succeeds(self, ssl_client_cls): + def test_client_authentication_succeeds(self, ssl_client_cls) -> None: # Given a server that requires client authentication with LegacyOpenSslServer(client_auth_config=ClientAuthConfigEnum.REQUIRED) as server: # And the client provides a client certificate @@ -96,7 +96,7 @@ def test_client_authentication_succeeds(self, ssl_client_cls): @pytest.mark.parametrize("ssl_client_cls", [SslClient, LegacySslClient]) class TestSslClientOnline: - def test(self, ssl_client_cls): + def test(self, ssl_client_cls) -> None: # Given an SslClient connecting to Google sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(5) @@ -123,7 +123,7 @@ def test(self, ssl_client_cls): finally: ssl_client.shutdown() - def test_get_dh_info_ecdh(self, ssl_client_cls): + def test_get_dh_info_ecdh(self, ssl_client_cls) -> None: with LegacyOpenSslServer(cipher="ECDHE-RSA-AES256-SHA") as server: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(5) @@ -149,7 +149,7 @@ def test_get_dh_info_ecdh(self, ssl_client_cls): assert len(dh_info.x) > 0 assert len(dh_info.y) > 0 - def test_get_dh_info_dh(self, ssl_client_cls): + def test_get_dh_info_dh(self, ssl_client_cls) -> None: with LegacyOpenSslServer(cipher="DHE-RSA-AES256-SHA") as server: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(5) @@ -175,7 +175,7 @@ def test_get_dh_info_dh(self, ssl_client_cls): assert len(dh_info.prime) > 0 assert len(dh_info.generator) > 0 - def test_get_dh_info_no_dh(self, ssl_client_cls): + def test_get_dh_info_no_dh(self, ssl_client_cls) -> None: with LegacyOpenSslServer(cipher="AES256-SHA") as server: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(5) @@ -198,7 +198,7 @@ def test_get_dh_info_no_dh(self, ssl_client_cls): class TestModernSslClientOnline: - def test_get_verified_chain(self): + def test_get_verified_chain(self) -> None: # Given an SslClient connecting to Google sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(5) @@ -221,7 +221,7 @@ def test_get_verified_chain(self): finally: ssl_client.shutdown() - def test_get_verified_chain_but_validation_failed(self): + def test_get_verified_chain_but_validation_failed(self) -> None: # Given an SslClient connecting to Google sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(5) @@ -245,7 +245,7 @@ def test_get_verified_chain_but_validation_failed(self): finally: ssl_client.shutdown() - def test_get_dh_info_ecdh_p256(self): + def test_get_dh_info_ecdh_p256(self) -> None: with ModernOpenSslServer(cipher="ECDHE-RSA-AES256-SHA", groups="P-256") as server: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(5) @@ -272,7 +272,7 @@ def test_get_dh_info_ecdh_p256(self): assert len(dh_info.x) == 32 assert len(dh_info.y) == 32 - def test_get_dh_info_ecdh_x25519(self): + def test_get_dh_info_ecdh_x25519(self) -> None: with ModernOpenSslServer(cipher="ECDHE-RSA-AES256-SHA", groups="X25519") as server: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(5) @@ -297,7 +297,7 @@ def test_get_dh_info_ecdh_x25519(self): assert dh_info.curve == OpenSslEcNidEnum.X25519 assert len(dh_info.public_bytes) == 32 - def test_set_groups_curve_secp192k1(self): + def test_set_groups_curve_secp192k1(self) -> None: # Given a server that supports a bunch of curves with ModernOpenSslServer( cipher="ECDHE-RSA-AES256-SHA", @@ -327,7 +327,7 @@ def test_set_groups_curve_secp192k1(self): assert isinstance(dh_info, EcDhEphemeralKeyInfo) assert dh_info.curve == configured_curve - def test_set_groups_curve_x448(self): + def test_set_groups_curve_x448(self) -> None: # Given a server that supports a bunch of curves with ModernOpenSslServer( cipher="ECDHE-RSA-AES256-SHA", @@ -360,7 +360,7 @@ def test_set_groups_curve_x448(self): assert dh_info.size == 448 assert len(dh_info.public_bytes) == 56 - def test_get_extended_master_secret_not_used(self): + def test_get_extended_master_secret_not_used(self) -> None: with LegacyOpenSslServer() as server: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(5) @@ -382,7 +382,7 @@ def test_get_extended_master_secret_not_used(self): exms_support = ssl_client.get_extended_master_secret_support() assert exms_support == ExtendedMasterSecretSupportEnum.NOT_USED_IN_CURRENT_SESSION - def test_get_extended_master_secret_used(self): + def test_get_extended_master_secret_used(self) -> None: with ModernOpenSslServer() as server: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(5) @@ -404,7 +404,7 @@ def test_get_extended_master_secret_used(self): class TestLegacySslClientOnline: - def test_ssl_2(self): + def test_ssl_2(self) -> None: # Given a server that supports SSL 2.0 with LegacyOpenSslServer() as server: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -425,7 +425,7 @@ def test_ssl_2(self): class TestModernSslClientOnlineTls13: - def test(self): + def test(self) -> None: # Given a server that supports TLS 1.3 with ModernOpenSslServer() as server: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -443,7 +443,7 @@ def test(self): finally: ssl_client.shutdown() - def test_set_ciphersuites(self): + def test_set_ciphersuites(self) -> None: # Given a server that supports TLS 1.3 with ModernOpenSslServer() as server: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -489,7 +489,7 @@ def _create_tls_1_3_session(server_host: str, server_port: int) -> _nassl.SSL_SE ssl_client.shutdown() return session - def test_write_early_data_does_not_finish_handshake(self): + def test_write_early_data_does_not_finish_handshake(self) -> None: # Given a server that supports TLS 1.3 and early data with ModernOpenSslServer(max_early_data=512) as server: # That has a previous TLS 1.3 session with the server @@ -528,7 +528,7 @@ def test_write_early_data_does_not_finish_handshake(self): ssl_client_early_data.shutdown() - def test_write_early_data_fail_when_used_on_non_reused_session(self): + def test_write_early_data_fail_when_used_on_non_reused_session(self) -> None: # Given a server that supports TLS 1.3 and early data with ModernOpenSslServer(max_early_data=512) as server: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -549,7 +549,7 @@ def test_write_early_data_fail_when_used_on_non_reused_session(self): ssl_client.shutdown() - def test_write_early_data_fail_when_trying_to_send_more_than_max_early_data(self): + def test_write_early_data_fail_when_trying_to_send_more_than_max_early_data(self) -> None: # Given a server that supports TLS 1.3 and early data with ModernOpenSslServer(max_early_data=1) as server: # That has a previous TLS 1.3 session with the server @@ -584,7 +584,7 @@ def test_write_early_data_fail_when_trying_to_send_more_than_max_early_data(self ssl_client_early_data.shutdown() - def test_client_authentication(self): + def test_client_authentication(self) -> None: # Given a server that requires client authentication with ModernOpenSslServer(client_auth_config=ClientAuthConfigEnum.REQUIRED) as server: # And the client provides an invalid client certificate (actually the server cert)