def get_evidence(self): requests = self.server_pubsub.check_messages() evidence_list = [] for request in requests: for evidence_ in request.evidence: if not evidence_.request_id: evidence_.request_id = request.request_id log.info( 'Received evidence [{0:s}] from PubSub message.'.format( str(evidence_))) success, message = recipe_helpers.validate_recipe( request.recipe) if not success: self.abort_request(evidence_.request_id, request.requester, evidence_.name, message) else: evidence_.config = request.recipe evidence_.config['globals'][ 'requester'] = request.requester evidence_list.append(evidence_) turbinia_server_request_total.inc() return evidence_list
def get_evidence(self): """Receives new evidence. Returns: list[Evidence]: evidence to process. """ requests = self.kombu.check_messages() evidence_list = [] for request in requests: for evidence_ in request.evidence: if not evidence_.request_id: evidence_.request_id = request.request_id log.info( 'Received evidence [{0:s}] from Kombu message.'.format( str(evidence_))) success, message = recipe_helpers.validate_recipe( request.recipe) if not success: self.abort_request(evidence_.request_id, request.requester, evidence_.name, message) else: evidence_.config = request.recipe evidence_.config['globals'][ 'requester'] = request.requester evidence_.config['globals']['group_id'] = request.recipe[ 'globals']['group_id'] evidence_list.append(evidence_) turbinia_server_request_total.inc() return evidence_list
def testValidateRecipeInvalidTaskName(self, mock_log): """Tests that a recipe with an invalid task name is handled correctly.""" self.test_recipe_dict['plaso_base'] = {'task': 'NoTask'} expected_error_message = ( 'Task NoTask defined for task recipe plaso_base does not exist.') result = recipe_helpers.validate_recipe(self.test_recipe_dict) mock_log.assert_called_with(expected_error_message) self.assertEqual(result, (False, expected_error_message))
def testValidateRecipeNoTask(self, mock_log): """Tests that a recipe with no task key is handled correctly.""" self.test_recipe_dict['plaso_base'] = {'notask': 'PlasoTask'} expected_error_message = ( 'Recipe item "plaso_base" has no "task" key. All recipe items must ' 'have a "task" key indicating the TurbiniaTask to which it relates.' ) result = recipe_helpers.validate_recipe(self.test_recipe_dict) mock_log.assert_called_with(expected_error_message) self.assertEqual(result, (False, expected_error_message))
def testValidateRecipeInvalidGlobals(self, mock_log): """Tests that a recipe with invalid globals is handled correctly.""" recipe_dict = { 'globals': { 'invalid_key': 'invalid_value' }, 'plaso_base': { 'task': 'PlasoTask' } } expected_error_message = ( 'Invalid recipe: Unknown keys [{\'invalid_key\'}] found in globals ' 'recipe') result = recipe_helpers.validate_recipe(recipe_dict) mock_log.assert_called_with(expected_error_message) self.assertEqual(result, (False, expected_error_message))
def testValidateRecipe(self): """Tests that a valid recipe passes validation.""" result = recipe_helpers.validate_recipe(self.test_recipe_dict) self.assertEqual(result, (True, ''))