#NEWLINE# def testGetFieldsFromSequenceWhenX509V3Missing( self ) : #NEWLINE# #INDENT# 'Test _GetFieldsFromSequence().' #NEWLINE# sig_alg_seq = ( 'a' , 'b' ) #NEWLINE# sig_alg = 'sigalg' #NEWLINE# before_ts = self . mox . CreateMockAnything ( ) #NEWLINE# after_ts = self . mox . CreateMockAnything ( ) #NEWLINE# mock_utctime = self . mox . CreateMockAnything ( ) #NEWLINE# self . stubs . Set ( x509 . pyasn1 . type . useful , 'UTCTime' , mock_utctime ) #NEWLINE# mock_utctime ( ) . AndReturn ( mock_utctime ) #NEWLINE# mock_utctime ( ) . AndReturn ( mock_utctime ) #NEWLINE# before_ts . isSameTypeWith ( mock_utctime ) . AndReturn ( True ) #NEWLINE# after_ts . isSameTypeWith ( mock_utctime ) . AndReturn ( True ) #NEWLINE# serial_num = 12345 #NEWLINE# v3ext = { #NEWLINE# #INDENT# 'may_act_as_ca' : 123 , #NEWLINE# 'key_usage' : ( 1 , 2 , 3 ) , #NEWLINE# #UNINDENT# } #NEWLINE# seq = ( x509 . X509_CERT_VERSION_3 , serial_num , sig_alg_seq , ( ( ( x509 . OID_ID [ 'CN' ] , 'issuer' ) , ) , ) , ( before_ts , after_ts ) , ( ( ( x509 . OID_ID [ 'CN' ] , 'subject' ) , ) , ) , 'public key' ) #NEWLINE# seq_encoded = 'raw bytes' #NEWLINE# before_dt = 'before_dt' #NEWLINE# after_dt = 'after_dt' #NEWLINE# self . mox . StubOutWithMock ( before_dt . x , '_GetSignatureAlgorithmFromSequence' ) #NEWLINE# self . mox . StubOutWithMock ( self . x , '_CertTimestampToDatetime' ) #NEWLINE# self . mox . StubOutWithMock ( self . x , '_AssembleDNSequence' ) #NEWLINE# self . mox . StubOutWithMock ( x509 . der_encoder , 'encode' , True ) #NEWLINE# self . x . _GetSignatureAlgorithmFromSequence ( sig_alg_seq ) . AndReturn ( sig_alg ) #NEWLINE# self . x . _AssembleDNSequence ( seq [ 3 ] ) . AndReturn ( 'CN=issuer' ) #NEWLINE# self . x . _CertTimestampToDatetime ( before_ts ) . AndReturn ( before_dt ) #NEWLINE# self . x . _CertTimestampToDatetime ( after_ts ) . AndReturn ( after_dt ) #NEWLINE# self . x . _AssembleDNSequence ( seq [ 5 ] ) . AndReturn ( 'CN=subject' ) #NEWLINE# x509 . der_encoder . encode ( seq ) . AndReturn ( seq_encoded ) #NEWLINE# self . mox . ReplayAll ( ) #NEWLINE# output = self . x . _GetFieldsFromSequence ( seq ) #NEWLINE# self . _CheckSaneCertFields ( output ) #NEWLINE# self . assertEqual ( output , { #NEWLINE# #INDENT# 'serial_num' : serial_num , #NEWLINE# 'issuer' : 'CN=issuer' , #NEWLINE# 'subject' : 'CN=subject' , #NEWLINE# 'valid_notbefore' : before_dt , #NEWLINE# 'valid_notafter' : after_dt , #NEWLINE# 'fields_data' : seq_encoded , #NEWLINE# 'sig_algorithm' : sig_alg , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . mox . VerifyAll ( )