'Tests the end to end encrypted communicators.'

def testErrorDetection(self):

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