aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat/primitives/test_serialization.py
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-12-22 08:12:38 -0600
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-12-22 08:12:38 -0600
commitcf6e6d6ff864c8de81d9c98c102ff366df289441 (patch)
tree5e7144a3d0037776f767879c33496c5684f5478a /tests/hazmat/primitives/test_serialization.py
parent217d417243956f703082451f5fd25d7586a69a4e (diff)
downloadcryptography-cf6e6d6ff864c8de81d9c98c102ff366df289441.tar.gz
cryptography-cf6e6d6ff864c8de81d9c98c102ff366df289441.tar.bz2
cryptography-cf6e6d6ff864c8de81d9c98c102ff366df289441.zip
parametrize some more serialization tests
Diffstat (limited to 'tests/hazmat/primitives/test_serialization.py')
-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 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"