From 99b8b2f4ebadd88906992fafcaa238ed7b792834 Mon Sep 17 00:00:00 2001 From: pyth0n1c <87383215+pyth0n1c@users.noreply.github.com> Date: Tue, 20 Sep 2022 07:46:15 -0700 Subject: [PATCH] Fixed output of files names when running a mock. Handle errors when processing a detection test generates an error. --- .../detection_testing_execution.py | 11 ++++++----- .../modules/splunk_container.py | 10 +++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/bin/docker_detection_tester/detection_testing_execution.py b/bin/docker_detection_tester/detection_testing_execution.py index eda838459f..480eee58d8 100644 --- a/bin/docker_detection_tester/detection_testing_execution.py +++ b/bin/docker_detection_tester/detection_testing_execution.py @@ -255,11 +255,12 @@ def finish_mock(settings: dict, detections: list[Detection], output_file_templat for d in detection_tests: filename = os.path.basename(d) filename = filename.replace(".test.yml", ".yml") - leading = os.path.split(d)[0] - leading = leading.replace("tests/", "detections/") - new_name = os.path.join( - "security_content", leading, filename) - normalized_detection_names.append(new_name) + #leading = os.path.split(d)[0] + #leading = leading.replace() + #new_name = os.path.join( + # "security_content", leading, filename) + #normalized_detection_names.append(new_name) + normalized_detection_names.append(d.replace(".test.yml", ".yml").replace("tests/", "detections/")) # Generate an appropriate config file for this test mock_settings = copy.deepcopy(settings) diff --git a/bin/docker_detection_tester/modules/splunk_container.py b/bin/docker_detection_tester/modules/splunk_container.py index 42bc420f41..b4ea449713 100644 --- a/bin/docker_detection_tester/modules/splunk_container.py +++ b/bin/docker_detection_tester/modules/splunk_container.py @@ -485,14 +485,18 @@ class SplunkContainer: "Warning - uncaught error in detection test for [%s] - this should not happen: [%s]" % (detection_to_test.testFile.path, str(e)) ) - self.synchronization_object.addResult(detection_to_test) - + try: + self.synchronization_object.addResult(detection_to_test) + except Exception as e: + print(f"Adding a failed result to the queue failed with error: {str(e)}") ###begin testing block self.num_tests_completed += 1 # Try to get something from the queue - detection_to_test = self.synchronization_object.getTest() + + #detection_to_test = self.synchronization_object.getTest() + continue ###end testing block