aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat/primitives
diff options
context:
space:
mode:
Diffstat (limited to 'tests/hazmat/primitives')
-rw-r--r--tests/hazmat/primitives/test_serialization.py88
1 files changed, 31 insertions, 57 deletions
diff --git a/tests/hazmat/primitives/test_serialization.py b/tests/hazmat/primitives/test_serialization.py
index 8a7e7f67..80a802d9 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
@@ -236,9 +237,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):
@@ -249,12 +256,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):
@@ -265,13 +275,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(
@@ -395,48 +411,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"