From 54a837d25df0ba2fa2a15238da9553e9a359bc14 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sun, 20 Dec 2015 23:42:32 -0600 Subject: add a CRL public_bytes method --- tests/test_x509.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'tests') diff --git a/tests/test_x509.py b/tests/test_x509.py index 511aac6b..fecafecc 100644 --- a/tests/test_x509.py +++ b/tests/test_x509.py @@ -222,6 +222,48 @@ class TestCertificateRevocationList(object): verifier.update(crl.tbs_certlist_bytes) verifier.verify() + def test_public_bytes_pem(self, backend): + crl = _load_cert( + os.path.join("x509", "custom", "crl_empty.pem"), + x509.load_pem_x509_crl, + backend + ) + + # Encode it to PEM and load it back. + crl = x509.load_pem_x509_crl(crl.public_bytes( + encoding=serialization.Encoding.PEM, + ), backend) + + assert len(crl) == 0 + assert crl.last_update == datetime.datetime(2015, 12, 20, 23, 44, 47) + assert crl.next_update == datetime.datetime(2015, 12, 28, 0, 44, 47) + + def test_public_bytes_der(self, backend): + crl = _load_cert( + os.path.join("x509", "custom", "crl_all_reasons.pem"), + x509.load_pem_x509_crl, + backend + ) + + # Encode it to DER and load it back. + crl = x509.load_der_x509_crl(crl.public_bytes( + encoding=serialization.Encoding.DER, + ), backend) + + assert len(crl) == 12 + assert crl.last_update == datetime.datetime(2015, 1, 1, 0, 0, 0) + assert crl.next_update == datetime.datetime(2016, 1, 1, 0, 0, 0) + + def test_public_bytes_invalid_encoding(self, backend): + crl = _load_cert( + os.path.join("x509", "custom", "crl_empty.pem"), + x509.load_pem_x509_crl, + backend + ) + + with pytest.raises(TypeError): + crl.public_bytes('NotAnEncoding') + @pytest.mark.requires_backend_interface(interface=X509Backend) class TestRevokedCertificate(object): -- cgit v1.2.3 From 2c91858de5fca63ee56b342d44fee73ed220d547 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Mon, 21 Dec 2015 09:25:36 -0600 Subject: add test for byte matching --- tests/test_x509.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests') diff --git a/tests/test_x509.py b/tests/test_x509.py index fecafecc..27ce21e2 100644 --- a/tests/test_x509.py +++ b/tests/test_x509.py @@ -254,6 +254,30 @@ class TestCertificateRevocationList(object): assert crl.last_update == datetime.datetime(2015, 1, 1, 0, 0, 0) assert crl.next_update == datetime.datetime(2016, 1, 1, 0, 0, 0) + @pytest.mark.parametrize( + ("cert_path", "loader_func", "encoding"), + [ + ( + os.path.join("x509", "custom", "crl_all_reasons.pem"), + x509.load_pem_x509_crl, + serialization.Encoding.PEM, + ), + ( + os.path.join("x509", "PKITS_data", "crls", "GoodCACRL.crl"), + x509.load_der_x509_crl, + serialization.Encoding.DER, + ), + ] + ) + def test_public_bytes_match(self, cert_path, loader_func, encoding, + backend): + crl_bytes = load_vectors_from_file( + cert_path, lambda pemfile: pemfile.read(), mode="rb" + ) + crl = loader_func(crl_bytes, backend) + serialized = crl.public_bytes(encoding) + assert serialized == crl_bytes + def test_public_bytes_invalid_encoding(self, backend): crl = _load_cert( os.path.join("x509", "custom", "crl_empty.pem"), -- cgit v1.2.3