From fa561db694219cf7cbbddfe624d8c4e1990907be Mon Sep 17 00:00:00 2001 From: P4T12ICK Date: Tue, 2 Mar 2021 09:13:27 +0100 Subject: [PATCH] wip --- bin/ssa-end-to-end-testing/run_ssa_smoketest.py | 1 - .../{ => tests}/modules/data_manipulation.py | 9 +++------ .../{ => tests}/modules/security_content_handler.py | 7 +++++++ .../tests/test_ssa_detections_playground.py | 9 ++++++++- 4 files changed, 18 insertions(+), 8 deletions(-) rename bin/ssa-end-to-end-testing/{ => tests}/modules/data_manipulation.py (91%) rename bin/ssa-end-to-end-testing/{ => tests}/modules/security_content_handler.py (85%) diff --git a/bin/ssa-end-to-end-testing/run_ssa_smoketest.py b/bin/ssa-end-to-end-testing/run_ssa_smoketest.py index 415aed615d..42d4adc247 100644 --- a/bin/ssa-end-to-end-testing/run_ssa_smoketest.py +++ b/bin/ssa-end-to-end-testing/run_ssa_smoketest.py @@ -4,7 +4,6 @@ import pytest import argparse from modules.github_service import GithubService -from modules.security_content_handler import prepare_test def main(args): diff --git a/bin/ssa-end-to-end-testing/modules/data_manipulation.py b/bin/ssa-end-to-end-testing/tests/modules/data_manipulation.py similarity index 91% rename from bin/ssa-end-to-end-testing/modules/data_manipulation.py rename to bin/ssa-end-to-end-testing/tests/modules/data_manipulation.py index 9812a9ef39..e46b70fd47 100644 --- a/bin/ssa-end-to-end-testing/modules/data_manipulation.py +++ b/bin/ssa-end-to-end-testing/tests/modules/data_manipulation.py @@ -21,8 +21,7 @@ class DataManipulation: def manipulate_timestamp_exchange_logs(self, file_path): - path = os.path.join(os.path.dirname(__file__), '../attack_data/' + file_path) - path = path.replace('modules/../','') + path = file_path f = io.open(path, "r", encoding="utf-8") @@ -48,8 +47,7 @@ class DataManipulation: def manipulate_timestamp_windows_event_log_raw(self, file_path): - path = os.path.join(os.path.dirname(__file__), '../attack_data/' + file_path) - path = path.replace('modules/../','') + path = file_path f = io.open(path, "r", encoding="utf-8") self.now = datetime.now() @@ -84,8 +82,7 @@ class DataManipulation: def manipulate_timestamp_cloudtrail(self, file_path): - path = os.path.join(os.path.dirname(__file__), '../attack_data/' + file_path) - path = path.replace('modules/../','') + path = file_path f = io.open(path, "r", encoding="utf-8") diff --git a/bin/ssa-end-to-end-testing/modules/security_content_handler.py b/bin/ssa-end-to-end-testing/tests/modules/security_content_handler.py similarity index 85% rename from bin/ssa-end-to-end-testing/modules/security_content_handler.py rename to bin/ssa-end-to-end-testing/tests/modules/security_content_handler.py index 3b047d2a7f..910bec0ffd 100644 --- a/bin/ssa-end-to-end-testing/modules/security_content_handler.py +++ b/bin/ssa-end-to-end-testing/tests/modules/security_content_handler.py @@ -30,6 +30,7 @@ def prepare_test(file_path): for attack_data in test['attack_data']: url = attack_data['data'] r = requests.get(url, allow_redirects=True) + attack_data_file_path = folder_name + '/' + attack_data['file_name'] open(folder_name + '/' + attack_data['file_name'], 'wb').write(r.content) # Update timestamps before replay @@ -38,3 +39,9 @@ def prepare_test(file_path): data_manipulation = DataManipulation() data_manipulation.manipulate_timestamp(folder_name + '/' + attack_data['file_name'], attack_data['sourcetype'], attack_data['source']) + dict_test = { + "test_obj": test_obj, + "attack_data_file_path": attack_data_file_path + } + + return dict_test diff --git a/bin/ssa-end-to-end-testing/tests/test_ssa_detections_playground.py b/bin/ssa-end-to-end-testing/tests/test_ssa_detections_playground.py index 16fa932bba..403e8b1c45 100644 --- a/bin/ssa-end-to-end-testing/tests/test_ssa_detections_playground.py +++ b/bin/ssa-end-to-end-testing/tests/test_ssa_detections_playground.py @@ -3,11 +3,13 @@ import pytest import logging import os import time +import pytest_check as check from http import HTTPStatus from modules.streams_service_api_helper import DSPApi from modules.utils import read_spl, read_data -import pytest_check as check +from modules.security_content_handler import prepare_test + # Logger logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO")) @@ -22,6 +24,11 @@ def header_token(token): def api(env, tenant, header_token): return DSPApi(env, tenant, header_token) +@pytest.fixture +def test_file(test_file): + prepare_test(test_file) + return test_file + @pytest.fixture def results_index(api):