def test_encode_encrypted_text_message(sample_data): encryption_string = str(Fernet.generate_key(), "utf-8") print(encryption_string) sample_data['encrypt_at_rest'] = True message_bytes = message.encode_message(sample_data, encryption_string) assert isinstance(message_bytes, bytes) pprint(message_bytes)
def ingest_etk(): if request.method == 'POST' and request.content_type == 'application/json': payload = request.json encoded_message = encode_message(payload, Config.ENCRYPT_KEY) if payload is not None and g.writer.publish(available_parameters['form']['queue'], encoded_message): return jsonify(payload), 200 else: return Response('Unavailable', 500, mimetype='application/json')
def publish_to_fail_queue(**args) -> tuple: config = args.get('config') message_with_errors = args.get('message') writer = args.get('writer') is_success = writer.publish( config.FAIL_QUEUE, encode_message(message_with_errors, config.ENCRYPT_KEY)) return is_success, args
def test_encode_encrypted_text_message_v1(self, sample_data): sample_data['encrypt_at_rest'] = True message_bytes = message.encode_message(sample_data, self.KEY) message_string = message_bytes.decode("utf-8") message_dict = json.loads(message_string) assert isinstance(message_bytes, bytes) assert isinstance(message_dict, dict) assert 'encrypted' in message_dict assert 'vt_query' not in message_dict
def ingest_e_ticket_event(): if request.method == 'POST' and request.content_type == 'application/json': payload = request.json encoded_message = encode_message(payload, Config.ENCRYPT_KEY) if payload is not None and g.writer.publish('ingested', encoded_message): return jsonify(payload), 200 else: return Response({'error': 'Unavailable'}, 500, mimetype='application/json')
def add_to_hold_queue(**args) -> tuple: config = args.get('config') message = args.get('message') writer = args.get('writer') logging.warning('writing to hold queue') if not writer.publish(config.HOLD_QUEUE, encode_message(message, config.ENCRYPT_KEY)): logging.critical('unable to write to RabbitMQ {} queue'.format( config.HOLD_QUEUE)) return False, args return True, args
def callback(self, ch, method, properties, body): logging.info('message received; callback invoked') message_dict = decode_message(body, self.config.ENCRYPT_KEY) result = self.validator.validate(message_dict) logging.info("write to: " + result['queue']) if result['isSuccess']: # Validation SUCCESSFUL if self.writer.publish( result['queue'], encode_message(message_dict, self.config.ENCRYPT_KEY)): ch.basic_ack(delivery_tag=method.delivery_tag) else: # Validation FAILED message_with_errors = add_error_to_message(message_dict, result) if self.writer.publish( result['queue'], encode_message(message_with_errors, self.config.ENCRYPT_KEY)): ch.basic_ack(delivery_tag=method.delivery_tag)
def encode_payload(**args) -> tuple: payload = args.get('payload') config = args.get('config') args['encoded_message'] = encode_message(payload, config.ENCRYPT_KEY) return True, args
def test_decode_plain_text_message(sample_data): message_bytes = message.encode_message(sample_data, '') message_dict = message.decode_message(message_bytes, '') pprint(message_bytes) assert sample_data == message_dict
def test_encode_plain_text_message(sample_data): message_bytes = message.encode_message(sample_data, '') assert isinstance(message_bytes, bytes) pprint(message_bytes)
def test_plain_message_encode(self, sample_data): encoded_message = message.encode_message(sample_data, '') assert isinstance(encoded_message, bytes)