#NEWLINE# def testErrorDetection( self ) : #NEWLINE# #INDENT# 'Tests the end to end encrypted communicators.' #NEWLINE# self . MakeClientAFF4Record ( ) #NEWLINE# message_list = rdf_flows . MessageList ( ) #NEWLINE# for i in range ( 0 , 10 ) : #NEWLINE# #INDENT# message_list . job . Append ( session_id = str ( i ) ) #NEWLINE# #UNINDENT# result = rdf_flows . ClientCommunication ( ) #NEWLINE# self . client_communicator . EncodeMessages ( message_list , result ) #NEWLINE# cipher_text = result . SerializeToString ( ) #NEWLINE# for x in range ( 0 , len ( cipher_text ) , 50 ) : #NEWLINE# #INDENT# mod_cipher_text = ( ( cipher_text [ : x ] + chr ( ( ( ord ( cipher_text [ x ] ) % 250 ) + 1 ) ) ) + cipher_text [ ( x + 1 ) : ] ) #NEWLINE# try : #NEWLINE# #INDENT# ( decoded , client_id , _ ) = self . server_communicator . DecryptMessage ( mod_cipher_text ) #NEWLINE# for ( i , message ) in enumerate ( decoded ) : #NEWLINE# #INDENT# if ( message . auth_state == message . AuthorizationState . AUTHENTICATED ) : #NEWLINE# #INDENT# self . assertEqual ( message . source , client_id ) #NEWLINE# message . auth_state = None #NEWLINE# message . source = None #NEWLINE# self . assertRDFValuesEqual ( message , message_list . job [ i ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# logging . debug ( 'Message %s: Authstate: %s' , i , message . auth_state ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except communicator . DecodingError as e : #NEWLINE# #INDENT# logging . debug ( 'Detected alteration at %s: %s' , x , e )