From 38269bac1e27c3a6cd60c3cfe96024ad51c9d853 Mon Sep 17 00:00:00 2001 From: Wojciech Nowak Date: Mon, 5 Feb 2024 10:27:44 +0100 Subject: [PATCH] Testcase added for TLS1.3 cipherlist handling --- tests/test_ssl.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/test_ssl.py b/tests/test_ssl.py index 5ea068a4..1d243cfc 100644 --- a/tests/test_ssl.py +++ b/tests/test_ssl.py @@ -487,6 +487,24 @@ class TestContext: Unit tests for `OpenSSL.SSL.Context`. """ + @pytest.mark.parametrize( + "cipher_string", + [ + b"hello world:TLS_AES_128_GCM_SHA256", + "hello world:TLS_AES_128_GCM_SHA256", + ], + ) + def test_set_ciphersuites(self, context, cipher_string): + """ + `Context.set_ciphersuites` accepts both byte and unicode strings + for naming the ciphers which connections created with the context + object will be able to choose from. + """ + context.set_ciphersuites(cipher_string) + conn = Connection(context, None) + + assert "TLS_AES_128_GCM_SHA256" in conn.get_cipher_list() + @pytest.mark.parametrize( "cipher_string", [b"hello world:AES128-SHA", "hello world:AES128-SHA"], @@ -502,13 +520,16 @@ def test_set_cipher_list(self, context, cipher_string): assert "AES128-SHA" in conn.get_cipher_list() - def test_set_cipher_list_wrong_type(self, context): + @pytest.mark.parametrize( + "set_cipher_method", ["set_cipher_list", "set_ciphersuites"] + ) + def test_set_cipher_wrong_type(self, context, set_cipher_method): """ - `Context.set_cipher_list` raises `TypeError` when passed a non-string + `Context.set_cipher_list` and `Context.set_ciphersuites` raises `TypeError` when passed a non-string argument. """ with pytest.raises(TypeError): - context.set_cipher_list(object()) + getattr(context, set_cipher_method)(object()) @flaky.flaky def test_set_cipher_list_no_cipher_match(self, context):