def test_cert_contents_unequal(self): """ Two Certificate instances with unequal contents are not equal. """ cert1 = pem.Certificate(b"test1") cert2 = pem.Certificate(b"test2") assert cert1 != cert2 assert cert2 != cert1
def test_certs_equal(self): """ Two Certificate instances with equal contents are equal. """ cert1 = pem.Certificate(b"test") cert2 = pem.Certificate(b"test") assert cert1 == cert2 assert cert2 == cert1 assert hash(cert1) == hash(cert2)
def test_cert_has_correct_str(self): """ Calling str on a Certificate instance returns the proper string. """ cert = pem.Certificate(b"test") assert str(cert) == "test"
def test_cert_has_correct_repr(self): """ Calling repr on a Certificate instance returns the proper string. """ cert = pem.Certificate(b"test") assert "<Certificate({0})>".format(TEST_DIGEST) == repr(cert)
def test_certificate_unicode(self): """ Passing unicode to Certificate encodes the string as ASCII. """ cert = pem.Certificate(u'a string') assert cert.as_bytes() == b'a string' assert str(cert) == 'a string'
def test_incompatible_types(self): """ A PEM object is not equal to some other arbitrary object. """ cert = pem.Certificate(b"test") assert cert != object() assert object() != cert
def test_as_text(self): """ obj.as_text() returns the contents as Unicode. """ cert_text = pem.Certificate(b"test").as_text() assert "test" == cert_text assert isinstance(cert_text, text_type)
def test_sha1_hexdigest(self): """ obj.sha1_digest contains the correct digest and caches it properly. """ cert = pem.Certificate(b"test") assert ("a94a8fe5ccb19ba61c4c0873d391e987982fbbd3" == cert.sha1_hexdigest == cert.sha1_hexdigest)
def test_different_objects_unequal(self): """ Two PEM objects of different types but with equal contents are not equal. """ cert = pem.Certificate(b"test") key = pem.Key(b"test") rsa_key = pem.RSAPrivateKey(b"test") assert cert != key assert key != cert assert key != rsa_key assert rsa_key != key
def test_different_objects_unequal(self): """ Two PEM objects of different types but with equal contents are not equal. """ c = b"test" pems = [ pem.Certificate(c), pem.CertificateRequest(c), pem.Key(c), pem.RSAPrivateKey(c), pem.CertificateRevocationList(c), ] for pem1, pem2 in combinations(pems, 2): assert not pem1 == pem2 assert pem1 != pem2
from twisted.internet import defer from twisted.python.compat import unicode from twisted.python.filepath import FilePath from twisted.trial.unittest import TestCase from txacme.store import DirectoryStore from txacme.testing import MemoryStore EXAMPLE_PEM_OBJECTS = [ pem.RSAPrivateKey( b'-----BEGIN RSA PRIVATE KEY-----\n' b'iq63EP+H3w==\n' b'-----END RSA PRIVATE KEY-----\n'), pem.Certificate( b'-----BEGIN CERTIFICATE-----\n' b'yns=\n' b'-----END CERTIFICATE-----\n'), pem.Certificate( b'-----BEGIN CERTIFICATE-----\n' b'pNaiqhAT\n' b'-----END CERTIFICATE-----\n'), ] EXAMPLE_PEM_OBJECTS2 = [ pem.RSAPrivateKey( b'-----BEGIN RSA PRIVATE KEY-----\n' b'fQ==\n' b'-----END RSA PRIVATE KEY-----\n'), pem.Certificate( b'-----BEGIN CERTIFICATE-----\n' b'xUg=\n'
def test_cert_has_correct_repr(self): """ Calling repr on a Certificate instance returns the proper string. """ cert = pem.Certificate('test') assert "<Certificate(pem_str='test')>" == repr(cert)