test_rfc7296.py 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #
  2. # This file is part of pyasn1-modules software.
  3. #
  4. # Created by Russ Housley
  5. # Copyright (c) 2019, Vigil Security, LLC
  6. # License: http://snmplabs.com/pyasn1/license.html
  7. #
  8. import sys
  9. import unittest
  10. from pyasn1.codec.der.decoder import decode as der_decoder
  11. from pyasn1.codec.der.encoder import encode as der_encoder
  12. from pyasn1_modules import pem
  13. from pyasn1_modules import rfc7296
  14. class CertBundleTestCase(unittest.TestCase):
  15. cert_bundle_pem_text = """\
  16. MIITfqCCA8kwggPFMIICraADAgECAhACrFwmagtAm48LefKuRiV3MA0GCSqGSIb3
  17. DQEBBQUAMGwxCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAX
  18. BgNVBAsTEHd3dy5kaWdpY2VydC5jb20xKzApBgNVBAMTIkRpZ2lDZXJ0IEhpZ2gg
  19. QXNzdXJhbmNlIEVWIFJvb3QgQ0EwHhcNMDYxMTEwMDAwMDAwWhcNMzExMTEwMDAw
  20. MDAwWjBsMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYD
  21. VQQLExB3d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFz
  22. c3VyYW5jZSBFViBSb290IENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC
  23. AQEAxszlc+b71LvlLS0ypt/lgT/JzSVJtnEqw9WUNGeiChywX2mmQLHEt7KP0Jik
  24. qUFZOtPclNY823Q4pErMTSWC90qlUxI47vNJbXGRfmO2q6Zfw6SE+E9iUb74xezb
  25. OJLjBuUIkQzEKEFV+8taiRV+ceg1v01yCT2+OjhQW3cxG42zxy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OluvMN0PzvPve0ECAE+D4e
  120. m9Y=
  121. """
  122. def setUp(self):
  123. self.asn1Spec = rfc7296.CertificateBundle()
  124. def testDerCodec(self):
  125. substrate = pem.readBase64fromText(self.cert_bundle_pem_text)
  126. asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
  127. self.assertFalse(rest)
  128. self.assertTrue(asn1Object.prettyPrint())
  129. self.assertEqual(substrate, der_encoder(asn1Object))
  130. cert_count = 0
  131. crl_count = 0
  132. unk_count = 0
  133. for item in asn1Object:
  134. if item.getName() == 'cert':
  135. cert_count += 1
  136. elif item.getName() == 'crl':
  137. crl_count += 1
  138. else:
  139. unk_count += 1
  140. self.assertEqual(3, cert_count)
  141. self.assertEqual(2, crl_count)
  142. self.assertEqual(0, unk_count)
  143. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  144. if __name__ == '__main__':
  145. unittest.TextTestRunner(verbosity=2).run(suite)