Home | History | Annotate | Download | only in tests
      1 #
      2 # This file is part of pyasn1-modules software.
      3 #
      4 # Copyright (c) 2005-2017, Ilya Etingof <etingof (at] gmail.com>
      5 # License: http://pyasn1.sf.net/license.html
      6 #
      7 import sys
      8 
      9 from pyasn1.codec.der import decoder as der_decoder
     10 from pyasn1.codec.der import encoder as der_encoder
     11 
     12 from pyasn1_modules import pem
     13 from pyasn1_modules import rfc2511
     14 
     15 try:
     16     import unittest2 as unittest
     17 
     18 except ImportError:
     19     import unittest
     20 
     21 
     22 class CertificateReqTestCase(unittest.TestCase):
     23     pem_text = """\
     24 MIIBozCCAZ8wggEFAgUAwTnj2jCByoABAqURMA8xDTALBgNVBAMTBHVzZXKmgZ8w
     25 DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAJ6ZQ2cYbn/lFsmBOlRltbRbFQUvvE0Q
     26 nbopOu1kC7Bmaaz7QTx8nxeiHi4m7uxCbGGxHNoGCt7EmdG8eZUBNAcHyGlXrJdm
     27 0z3/uNEGiBHq+xB8FnFJCA5EIJ3RWFnlbu9otSITLxWK7c5+/NHmWM+yaeHD/f/h
     28 rp01c/8qXZfZAgMBAAGpEDAOBgNVHQ8BAf8EBAMCBeAwLzASBgkrBgEFBQcFAQEM
     29 BTExMTExMBkGCSsGAQUFBwUBAgwMc2VydmVyX21hZ2ljoYGTMA0GCSqGSIb3DQEB
     30 BQUAA4GBAEI3KNEvTq/n1kNVhNhPkovk1AZxyJrN1u1+7Gkc4PLjWwjLOjcEVWt4
     31 AajUk/gkIJ6bbeO+fZlMjHfPSDKcD6AV2hN+n72QZwfzcw3icNvBG1el9EU4XfIm
     32 xfu5YVWi81/fw8QQ6X6YGHFQkomLd7jxakVyjxSng9BhO6GpjJNF
     33 """
     34 
     35     def setUp(self):
     36         self.asn1Spec = rfc2511.CertReqMessages()
     37 
     38     def testDerCodec(self):
     39 
     40         substrate = pem.readBase64fromText(self.pem_text)
     41 
     42         asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec)
     43 
     44         assert not rest
     45         assert asn1Object.prettyPrint()
     46         assert der_encoder.encode(asn1Object) == substrate
     47 
     48 
     49 suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
     50 
     51 if __name__ == '__main__':
     52     unittest.TextTestRunner(verbosity=2).run(suite)
     53