diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2015-03-28 13:33:01 -0400 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2015-03-28 13:33:01 -0400 |
commit | 320050b92d98c9dd8f3949f04a13756a4018f85d (patch) | |
tree | 5c6715eb538ff5308045be4a342ddc687795570b /tests | |
parent | 7d31b38ae1000d6691c62426219f8c8c03ac3f7d (diff) | |
parent | fbb7ac804a769ff48cddde6fb1f36d8af0d56174 (diff) | |
download | cryptography-320050b92d98c9dd8f3949f04a13756a4018f85d.tar.gz cryptography-320050b92d98c9dd8f3949f04a13756a4018f85d.tar.bz2 cryptography-320050b92d98c9dd8f3949f04a13756a4018f85d.zip |
Merge pull request #1793 from reaperhulk/x509-extensions-class
add x509 extensions class and basic tests (no extensions supported)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_x509_ext.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 74d14c57..d8281526 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -4,9 +4,14 @@ from __future__ import absolute_import, division, print_function +import os + import pytest from cryptography import x509 +from cryptography.hazmat.backends.interfaces import RSABackend, X509Backend + +from .test_x509 import _load_cert class TestExtension(object): @@ -55,3 +60,55 @@ class TestBasicConstraints(object): assert repr(na) == ( "<BasicConstraints(ca=True, path_length=None)>" ) + + +@pytest.mark.requires_backend_interface(interface=RSABackend) +@pytest.mark.requires_backend_interface(interface=X509Backend) +class TestExtensions(object): + def test_no_extensions(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) == [] + + def test_duplicate_extension(self, backend): + cert = _load_cert( + os.path.join( + "x509", "custom", "two_basic_constraints.pem" + ), + x509.load_pem_x509_certificate, + backend + ) + with pytest.raises(x509.DuplicateExtension) as exc: + cert.extensions + + assert exc.value.oid == x509.OID_BASIC_CONSTRAINTS + + def test_unsupported_critical_extension(self, backend): + cert = _load_cert( + os.path.join( + "x509", "custom", "unsupported_extension_critical.pem" + ), + x509.load_pem_x509_certificate, + backend + ) + with pytest.raises(x509.UnsupportedExtension) as exc: + cert.extensions + + assert exc.value.oid == x509.ObjectIdentifier("1.2.3.4") + + def test_unsupported_extension(self, backend): + # TODO: this will raise an exception when all extensions are complete + cert = _load_cert( + os.path.join( + "x509", "custom", "unsupported_extension.pem" + ), + x509.load_pem_x509_certificate, + backend + ) + extensions = cert.extensions + assert len(extensions) == 0 |