Skip to content

Commit

Permalink
Add some type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
nabla-c0d3 committed Dec 26, 2024
1 parent 9f5a6a0 commit ba0d542
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions tests/ssl_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ba0d542

Please sign in to comment.