From 9fbb889347696db4a15e44b2c73d38aa47da8b97 Mon Sep 17 00:00:00 2001 From: Phoebe Queen Date: Wed, 12 Aug 2015 03:51:33 +0100 Subject: added test for get_extension_for_class --- tests/test_x509_ext.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 2c5438a9..a05dc2a4 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -832,6 +832,16 @@ class TestExtensions(object): extensions = cert.extensions assert len(extensions) == 0 + def test_one_extension_get_for_class(self, backend): + cert = _load_cert( + os.path.join("x509", "custom", "basic_constraints_not_critical.pem"), + x509.load_pem_x509_certificate, + backend + ) + ext = cert.extensions.get_extension_for_class(x509.BasicConstraints) + assert ext is not None + + assert isinstance(ext.value, x509.BasicConstraints) @pytest.mark.requires_backend_interface(interface=RSABackend) @pytest.mark.requires_backend_interface(interface=X509Backend) -- cgit v1.2.3 From 2cc111a18b615ccf3ecec9fe8918836d498e4b67 Mon Sep 17 00:00:00 2001 From: Phoebe Queen Date: Wed, 12 Aug 2015 04:14:22 +0100 Subject: fixing pep8 errors #2255 --- tests/test_x509_ext.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index a05dc2a4..2d3339c3 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -834,7 +834,9 @@ class TestExtensions(object): def test_one_extension_get_for_class(self, backend): cert = _load_cert( - os.path.join("x509", "custom", "basic_constraints_not_critical.pem"), + os.path.join( + "x509", "custom", "basic_constraints_not_critical.pem" + ), x509.load_pem_x509_certificate, backend ) @@ -843,6 +845,7 @@ class TestExtensions(object): assert isinstance(ext.value, x509.BasicConstraints) + @pytest.mark.requires_backend_interface(interface=RSABackend) @pytest.mark.requires_backend_interface(interface=X509Backend) class TestBasicConstraintsExtension(object): -- cgit v1.2.3 From ecae981f3a17236caee76bc95c5881db0b0d39b3 Mon Sep 17 00:00:00 2001 From: Phoebe Queen Date: Wed, 12 Aug 2015 05:00:32 +0100 Subject: added test to raise error --- tests/test_x509_ext.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests') diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 2d3339c3..040347db 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -832,6 +832,22 @@ class TestExtensions(object): extensions = cert.extensions assert len(extensions) == 0 + def test_no_extensions_get_for_class(self, backend): + cert = _load_cert( + os.path.join( + "x509", "verisign_md2_root.pem" + ), + x509.load_pem_x509_certificate, + backend + ) + ext = cert.extensions + assert len(ext) == 0 + assert list(ext) == [] + with pytest.raises(x509.ExtensionNotFound) as exc: + ext.get_extension_for_class(x509.BasicConstraints) + + assert exc.value.oid == ExtensionOID.BASIC_CONSTRAINTS + def test_one_extension_get_for_class(self, backend): cert = _load_cert( os.path.join( -- cgit v1.2.3 From c93752b2f97b54ee3ea5f9b3c89151d06ef3a919 Mon Sep 17 00:00:00 2001 From: Phoebe Queen Date: Wed, 12 Aug 2015 10:54:46 +0100 Subject: making tests more explicit --- tests/test_x509_ext.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 040347db..14df9a22 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -840,12 +840,10 @@ class TestExtensions(object): x509.load_pem_x509_certificate, backend ) - ext = cert.extensions - assert len(ext) == 0 - assert list(ext) == [] + exts = cert.extensions with pytest.raises(x509.ExtensionNotFound) as exc: - ext.get_extension_for_class(x509.BasicConstraints) - + ext = exts.get_extension_for_class(x509.BasicConstraints) + assert ext is None assert exc.value.oid == ExtensionOID.BASIC_CONSTRAINTS def test_one_extension_get_for_class(self, backend): @@ -858,7 +856,6 @@ class TestExtensions(object): ) ext = cert.extensions.get_extension_for_class(x509.BasicConstraints) assert ext is not None - assert isinstance(ext.value, x509.BasicConstraints) -- cgit v1.2.3 From e3c10077a395399d743faaffed42ca9fc33a5087 Mon Sep 17 00:00:00 2001 From: Phoebe Queen Date: Wed, 12 Aug 2015 11:24:09 +0100 Subject: undid erroneous assertion --- tests/test_x509_ext.py | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 14df9a22..75fb914d 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -843,7 +843,6 @@ class TestExtensions(object): exts = cert.extensions with pytest.raises(x509.ExtensionNotFound) as exc: ext = exts.get_extension_for_class(x509.BasicConstraints) - assert ext is None assert exc.value.oid == ExtensionOID.BASIC_CONSTRAINTS def test_one_extension_get_for_class(self, backend): -- cgit v1.2.3 From 85fa546c4a7f68e2632034f28a1a07cb441de8a2 Mon Sep 17 00:00:00 2001 From: Phoebe Queen Date: Wed, 12 Aug 2015 11:41:55 +0100 Subject: fixed pep8 error --- tests/test_x509_ext.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 75fb914d..043aaa7d 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -869,7 +869,7 @@ class TestBasicConstraintsExtension(object): x509.load_der_x509_certificate, backend ) - ext = cert.extensions.get_extension_for_oid( + cert.extensions.get_extension_for_oid( ExtensionOID.BASIC_CONSTRAINTS ) assert ext is not None -- cgit v1.2.3 From 062dec72a2a0d769328c575ae8cc11e21eed2f18 Mon Sep 17 00:00:00 2001 From: Phoebe Queen Date: Wed, 12 Aug 2015 11:42:23 +0100 Subject: fixed pep8 error --- tests/test_x509_ext.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 043aaa7d..33da27ec 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -842,7 +842,7 @@ class TestExtensions(object): ) exts = cert.extensions with pytest.raises(x509.ExtensionNotFound) as exc: - ext = exts.get_extension_for_class(x509.BasicConstraints) + exts.get_extension_for_class(x509.BasicConstraints) assert exc.value.oid == ExtensionOID.BASIC_CONSTRAINTS def test_one_extension_get_for_class(self, backend): @@ -869,7 +869,7 @@ class TestBasicConstraintsExtension(object): x509.load_der_x509_certificate, backend ) - cert.extensions.get_extension_for_oid( + ext = cert.extensions.get_extension_for_oid( ExtensionOID.BASIC_CONSTRAINTS ) assert ext is not None -- cgit v1.2.3 From cb5ec4e90ea06d0b5ee95c68c26927ab7623b588 Mon Sep 17 00:00:00 2001 From: Phoebe Queen Date: Wed, 12 Aug 2015 15:06:26 +0100 Subject: Swap test vector verisign for cryptography.io.pem --- tests/test_x509_ext.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 33da27ec..85373973 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -835,15 +835,15 @@ class TestExtensions(object): def test_no_extensions_get_for_class(self, backend): cert = _load_cert( os.path.join( - "x509", "verisign_md2_root.pem" + "x509", "cryptography.io.pem" ), x509.load_pem_x509_certificate, backend ) exts = cert.extensions with pytest.raises(x509.ExtensionNotFound) as exc: - exts.get_extension_for_class(x509.BasicConstraints) - assert exc.value.oid == ExtensionOID.BASIC_CONSTRAINTS + exts.get_extension_for_class(x509.IssuerAlternativeName) + assert exc.value.oid == ExtensionOID.ISSUER_ALTERNATIVE_NAME def test_one_extension_get_for_class(self, backend): cert = _load_cert( -- cgit v1.2.3