From cf6e6d6ff864c8de81d9c98c102ff366df289441 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Mon, 22 Dec 2014 08:12:38 -0600 Subject: parametrize some more serialization tests --- tests/hazmat/primitives/test_serialization.py | 88 ++++++++++----------------- 1 file changed, 31 insertions(+), 57 deletions(-) (limited to 'tests/hazmat/primitives/test_serialization.py') diff --git a/tests/hazmat/primitives/test_serialization.py b/tests/hazmat/primitives/test_serialization.py index 6169dd83..3c63be18 100644 --- a/tests/hazmat/primitives/test_serialization.py +++ b/tests/hazmat/primitives/test_serialization.py @@ -4,6 +4,7 @@ from __future__ import absolute_import, division, print_function +import itertools import os import textwrap @@ -242,9 +243,15 @@ class TestTraditionalOpenSSLSerialization(object): 16 ) - def test_unused_password(self, backend): - key_file = os.path.join( - "asymmetric", "Traditional_OpenSSL_Serialization", "testrsa.pem") + @pytest.mark.parametrize( + "key_path", + [ + ["Traditional_OpenSSL_Serialization", "testrsa.pem"], + ["PKCS8", "unenc-rsa-pkcs8.pem"] + ] + ) + def test_unused_password(self, key_path, backend): + key_file = os.path.join("asymmetric", *key_path) password = b"this password will not be used" with pytest.raises(TypeError): @@ -255,12 +262,15 @@ class TestTraditionalOpenSSLSerialization(object): ) ) - def test_wrong_password(self, backend): - key_file = os.path.join( - "asymmetric", - "Traditional_OpenSSL_Serialization", - "testrsa-encrypted.pem" - ) + @pytest.mark.parametrize( + "key_path", + [ + ["Traditional_OpenSSL_Serialization", "testrsa-encrypted.pem"], + ["PKCS8", "enc-rsa-pkcs8.pem"] + ] + ) + def test_wrong_password(self, key_path, backend): + key_file = os.path.join("asymmetric", *key_path) password = b"this password is wrong" with pytest.raises(ValueError): @@ -271,13 +281,19 @@ class TestTraditionalOpenSSLSerialization(object): ) ) - @pytest.mark.parametrize("password", [None, b""]) - def test_missing_password(self, backend, password): - key_file = os.path.join( - "asymmetric", - "Traditional_OpenSSL_Serialization", - "testrsa-encrypted.pem" + @pytest.mark.parametrize( + ("key_path", "password"), + itertools.product( + [ + ["Traditional_OpenSSL_Serialization", + "testrsa-encrypted.pem"], + ["PKCS8", "enc-rsa-pkcs8.pem"], + ], + [b"", None] ) + ) + def test_missing_password(self, key_path, password, backend): + key_file = os.path.join("asymmetric", *key_path) with pytest.raises(TypeError): load_vectors_from_file( @@ -401,48 +417,6 @@ class TestPKCS8Serialization(object): assert key.curve.name == "secp256r1" assert key.curve.key_size == 256 - def test_unused_password(self, backend): - key_file = os.path.join( - "asymmetric", "PKCS8", "unenc-rsa-pkcs8.pem") - password = b"this password will not be used" - - with pytest.raises(TypeError): - load_vectors_from_file( - key_file, - lambda pemfile: load_pem_private_key( - pemfile.read().encode(), password, backend - ) - ) - - def test_wrong_password(self, backend): - key_file = os.path.join( - "asymmetric", "PKCS8", "enc-rsa-pkcs8.pem") - password = b"this password is wrong" - - with pytest.raises(ValueError): - load_vectors_from_file( - key_file, - lambda pemfile: load_pem_private_key( - pemfile.read().encode(), password, backend - ) - ) - - @pytest.mark.parametrize("password", [None, b""]) - def test_missing_password(self, backend, password): - key_file = os.path.join( - "asymmetric", - "PKCS8", - "enc-rsa-pkcs8.pem" - ) - - with pytest.raises(TypeError): - load_vectors_from_file( - key_file, - lambda pemfile: load_pem_private_key( - pemfile.read().encode(), password, backend - ) - ) - def test_wrong_format(self, backend): key_data = b"---- NOT A KEY ----\n" -- cgit v1.2.3