From 0e82b475fd7b6d2a06363baf647d4354ebf24671 Mon Sep 17 00:00:00 2001 From: Valentijn Scholten Date: Sun, 16 Feb 2025 15:42:57 +0100 Subject: [PATCH] fix integration test path handling --- docker/entrypoint-integration-tests.sh | 2 +- docs/content/en/open_source/upgrading/2.44.md | 2 +- dojo/engagement/views.py | 5 ++- tests/Import_scanner_test.py | 2 +- tests/close_old_findings_dedupe_test.py | 14 ++++---- tests/close_old_findings_test.py | 14 ++++---- tests/dedupe_test.py | 32 +++++++++---------- tests/report_builder_test.py | 4 --- 8 files changed, 34 insertions(+), 41 deletions(-) diff --git a/docker/entrypoint-integration-tests.sh b/docker/entrypoint-integration-tests.sh index 075d419d89d..7204bfcf1e5 100755 --- a/docker/entrypoint-integration-tests.sh +++ b/docker/entrypoint-integration-tests.sh @@ -251,7 +251,7 @@ else else fail "$test" fi - + test="False Positive History tests" echo "Running: $test" if python3 tests/false_positive_history_test.py ; then diff --git a/docs/content/en/open_source/upgrading/2.44.md b/docs/content/en/open_source/upgrading/2.44.md index 8e987e5d3e0..a2179a05654 100644 --- a/docs/content/en/open_source/upgrading/2.44.md +++ b/docs/content/en/open_source/upgrading/2.44.md @@ -14,6 +14,6 @@ The Burp parser now has a custom deduplication configuration to make deduplicati This command has various command line arguments to tweak its behavior, for example to trigger a run of the deduplication process. See [dedupe.py](https://github.com/DefectDojo/django-DefectDojo/blob/master/dojo/management/commands/dedupe.py) for more information. ---- +--- Check the [Release Notes](https://github.com/DefectDojo/django-DefectDojo/releases/tag/2.44.0) for the contents of the release. diff --git a/dojo/engagement/views.py b/dojo/engagement/views.py index 1b69da01494..4f51c5ae2ea 100644 --- a/dojo/engagement/views.py +++ b/dojo/engagement/views.py @@ -1585,6 +1585,7 @@ def get_foreign_keys(): def csv_export(request): + logger.debug("starting csv export") engagements, test_counts = get_engagements(request) response = HttpResponse(content_type="text/csv") @@ -1617,11 +1618,12 @@ def csv_export(request): fields.append(test_counts.get(engagement.id, 0)) writer.writerow(fields) - + logger.debug("done with csv export") return response def excel_export(request): + logger.debug("starting excel export") engagements, test_counts = get_engagements(request) workbook = Workbook() @@ -1667,4 +1669,5 @@ def excel_export(request): content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", ) response["Content-Disposition"] = "attachment; filename=engagements.xlsx" + logger.debug("done with excel export") return response diff --git a/tests/Import_scanner_test.py b/tests/Import_scanner_test.py index 8f0ac1beb53..853acfcdc50 100644 --- a/tests/Import_scanner_test.py +++ b/tests/Import_scanner_test.py @@ -13,7 +13,7 @@ from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select -dir_path = Path(os.path.realpath(__file__)).parent +dir_path = str(Path(os.path.realpath(__file__)).parent) logger = logging.getLogger(__name__) diff --git a/tests/close_old_findings_dedupe_test.py b/tests/close_old_findings_dedupe_test.py index d168ae5485c..4dd9e674d1e 100644 --- a/tests/close_old_findings_dedupe_test.py +++ b/tests/close_old_findings_dedupe_test.py @@ -14,8 +14,6 @@ logger = logging.getLogger(__name__) -dir_path = Path(os.path.realpath(__file__)).parent - class CloseOldDedupeTest(BaseTestCase): # -------------------------------------------------------------------------------------------------------- @@ -137,7 +135,7 @@ def test_import_same_engagement_tests(self): scan_environment = Select(driver.find_element(By.ID, "id_environment")) scan_environment.select_by_visible_text("Development") driver.find_element(By.ID, "id_close_old_findings").click() - driver.find_element(By.ID, "id_file").send_keys(self.relative_path + "/dedupe_scans/dedupe_endpoint_1.xml") + driver.find_element(By.ID, "id_file").send_keys(self.relative_path / "dedupe_scans/dedupe_endpoint_1.xml") driver.find_elements(By.CLASS_NAME, "btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="3 findings and closed 0 findings")) @@ -154,7 +152,7 @@ def test_import_same_engagement_tests(self): scan_environment = Select(driver.find_element(By.ID, "id_environment")) scan_environment.select_by_visible_text("Development") driver.find_element(By.ID, "id_close_old_findings").click() - driver.find_element(By.ID, "id_file").send_keys(self.relative_path + "/dedupe_scans/dedupe_endpoint_1.xml") + driver.find_element(By.ID, "id_file").send_keys(self.relative_path / "dedupe_scans/dedupe_endpoint_1.xml") driver.find_elements(By.CLASS_NAME, "btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="3 findings and closed 0 findings")) @@ -176,7 +174,7 @@ def test_close_same_engagement_tests(self): scan_environment = Select(driver.find_element(By.ID, "id_environment")) scan_environment.select_by_visible_text("Development") driver.find_element(By.ID, "id_close_old_findings").click() - driver.find_element(By.ID, "id_file").send_keys(self.relative_path + "/dedupe_scans/dedupe_and_close_1.xml") + driver.find_element(By.ID, "id_file").send_keys(self.relative_path / "dedupe_scans/dedupe_and_close_1.xml") driver.find_elements(By.CLASS_NAME, "btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="1 findings and closed 2 findings")) @@ -244,7 +242,7 @@ def test_import_same_product_tests(self): scan_environment = Select(driver.find_element(By.ID, "id_environment")) scan_environment.select_by_visible_text("Development") driver.find_element(By.ID, "id_close_old_findings_product_scope").click() - driver.find_element(By.ID, "id_file").send_keys(self.relative_path + "/dedupe_scans/dedupe_endpoint_1.xml") + driver.find_element(By.ID, "id_file").send_keys(self.relative_path / "dedupe_scans/dedupe_endpoint_1.xml") driver.find_elements(By.CLASS_NAME, "btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="3 findings and closed 0 findings")) @@ -261,7 +259,7 @@ def test_import_same_product_tests(self): scan_environment = Select(driver.find_element(By.ID, "id_environment")) scan_environment.select_by_visible_text("Development") driver.find_element(By.ID, "id_close_old_findings_product_scope").click() - driver.find_element(By.ID, "id_file").send_keys(self.relative_path + "/dedupe_scans/dedupe_endpoint_1.xml") + driver.find_element(By.ID, "id_file").send_keys(self.relative_path / "dedupe_scans/dedupe_endpoint_1.xml") driver.find_elements(By.CLASS_NAME, "btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="3 findings and closed 0 findings")) @@ -283,7 +281,7 @@ def test_close_same_product_tests(self): scan_environment = Select(driver.find_element(By.ID, "id_environment")) scan_environment.select_by_visible_text("Development") driver.find_element(By.ID, "id_close_old_findings_product_scope").click() - driver.find_element(By.ID, "id_file").send_keys(self.relative_path + "/dedupe_scans/dedupe_and_close_1.xml") + driver.find_element(By.ID, "id_file").send_keys(self.relative_path / "dedupe_scans/dedupe_and_close_1.xml") driver.find_elements(By.CLASS_NAME, "btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="1 findings and closed 2 findings")) diff --git a/tests/close_old_findings_test.py b/tests/close_old_findings_test.py index 64fe1edca3b..876cbe5f5ca 100644 --- a/tests/close_old_findings_test.py +++ b/tests/close_old_findings_test.py @@ -13,8 +13,6 @@ logger = logging.getLogger(__name__) -dir_path = Path(os.path.realpath(__file__)).parent - class CloseOldTest(BaseTestCase): # -------------------------------------------------------------------------------------------------------- @@ -95,7 +93,7 @@ def test_import_same_engagement_tests(self): scan_environment = Select(driver.find_element(By.ID, "id_environment")) scan_environment.select_by_visible_text("Development") driver.find_element(By.ID, "id_close_old_findings").click() - driver.find_element(By.ID, "id_file").send_keys(self.relative_path + "/close_old_scans/closeold_nodedupe_1.xml") + driver.find_element(By.ID, "id_file").send_keys(self.relative_path / "close_old_scans/closeold_nodedupe_1.xml") driver.find_elements(By.CLASS_NAME, "btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="3 findings and closed 0 findings")) @@ -112,7 +110,7 @@ def test_import_same_engagement_tests(self): scan_environment = Select(driver.find_element(By.ID, "id_environment")) scan_environment.select_by_visible_text("Development") driver.find_element(By.ID, "id_close_old_findings").click() - driver.find_element(By.ID, "id_file").send_keys(self.relative_path + "/close_old_scans/closeold_nodedupe_2.xml") + driver.find_element(By.ID, "id_file").send_keys(self.relative_path / "close_old_scans/closeold_nodedupe_2.xml") driver.find_elements(By.CLASS_NAME, "btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="3 findings and closed 3 findings")) @@ -134,7 +132,7 @@ def test_close_same_engagement_tests(self): scan_environment = Select(driver.find_element(By.ID, "id_environment")) scan_environment.select_by_visible_text("Development") driver.find_element(By.ID, "id_close_old_findings").click() - driver.find_element(By.ID, "id_file").send_keys(self.relative_path + "/dedupe_scans/dedupe_and_close_1.xml") + driver.find_element(By.ID, "id_file").send_keys(self.relative_path / "dedupe_scans/dedupe_and_close_1.xml") driver.find_elements(By.CLASS_NAME, "btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="1 findings and closed 3 findings")) @@ -198,7 +196,7 @@ def test_import_same_product_tests(self): scan_environment = Select(driver.find_element(By.ID, "id_environment")) scan_environment.select_by_visible_text("Development") driver.find_element(By.ID, "id_close_old_findings_product_scope").click() - driver.find_element(By.ID, "id_file").send_keys(self.relative_path + "/close_old_scans/closeold_nodedupe_1.xml") + driver.find_element(By.ID, "id_file").send_keys(self.relative_path / "close_old_scans/closeold_nodedupe_1.xml") driver.find_elements(By.CLASS_NAME, "btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="3 findings and closed 0 findings")) @@ -215,7 +213,7 @@ def test_import_same_product_tests(self): scan_environment = Select(driver.find_element(By.ID, "id_environment")) scan_environment.select_by_visible_text("Development") driver.find_element(By.ID, "id_close_old_findings_product_scope").click() - driver.find_element(By.ID, "id_file").send_keys(self.relative_path + "/close_old_scans/closeold_nodedupe_2.xml") + driver.find_element(By.ID, "id_file").send_keys(self.relative_path / "close_old_scans/closeold_nodedupe_2.xml") driver.find_elements(By.CLASS_NAME, "btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="3 findings and closed 3 findings")) @@ -237,7 +235,7 @@ def test_close_same_product_tests(self): scan_environment = Select(driver.find_element(By.ID, "id_environment")) scan_environment.select_by_visible_text("Development") driver.find_element(By.ID, "id_close_old_findings_product_scope").click() - driver.find_element(By.ID, "id_file").send_keys(self.relative_path + "/dedupe_scans/dedupe_and_close_1.xml") + driver.find_element(By.ID, "id_file").send_keys(self.relative_path / "dedupe_scans/dedupe_and_close_1.xml") driver.find_elements(By.CLASS_NAME, "btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="1 findings and closed 3 findings")) diff --git a/tests/dedupe_test.py b/tests/dedupe_test.py index ffa77fccc03..c92eeda44d0 100644 --- a/tests/dedupe_test.py +++ b/tests/dedupe_test.py @@ -14,8 +14,6 @@ logger = logging.getLogger(__name__) -dir_path = Path(os.path.realpath(__file__)).parent - class DedupeTest(BaseTestCase): # -------------------------------------------------------------------------------------------------------- @@ -23,7 +21,7 @@ class DedupeTest(BaseTestCase): # -------------------------------------------------------------------------------------------------------- def setUp(self): super().setUp() - self.relative_path = str(Path(os.path.realpath(__file__)).parent) + self.relative_path = Path(os.path.realpath(__file__)).parent def check_nb_duplicates(self, expected_number_of_duplicates): logger.debug("checking duplicates...") @@ -140,7 +138,7 @@ def test_import_path_tests(self): driver.find_element(By.PARTIAL_LINK_TEXT, "Path Test 1").click() driver.find_element(By.ID, "dropdownMenu1").click() driver.find_element(By.LINK_TEXT, "Re-Upload Scan").click() - driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path + "/dedupe_scans/dedupe_path_1.json")) + driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path / "dedupe_scans/dedupe_path_1.json")) driver.find_elements(By.CSS_SELECTOR, "button.btn.btn-primary")[1].click() # 'Bandit Scan processed a total of 1 findings created 1 findings did not touch 1 findings.' @@ -154,7 +152,7 @@ def test_import_path_tests(self): driver.find_element(By.PARTIAL_LINK_TEXT, "Path Test 2").click() driver.find_element(By.ID, "dropdownMenu1").click() driver.find_element(By.LINK_TEXT, "Re-Upload Scan").click() - driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path + "/dedupe_scans/dedupe_path_2.json")) + driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path / "dedupe_scans/dedupe_path_2.json")) driver.find_elements(By.CSS_SELECTOR, "button.btn.btn-primary")[1].click() # 'Bandit Scan processed a total of 2 findings created 2 findings did not touch 1 findings.' @@ -212,7 +210,7 @@ def test_import_endpoint_tests(self): driver.find_element(By.PARTIAL_LINK_TEXT, "Endpoint Test 1").click() driver.find_element(By.ID, "dropdownMenu1").click() driver.find_element(By.LINK_TEXT, "Re-Upload Scan").click() - driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path + "/dedupe_scans/dedupe_endpoint_1.xml")) + driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path / "dedupe_scans/dedupe_endpoint_1.xml")) driver.find_elements(By.CSS_SELECTOR, "button.btn.btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="a total of 3 findings")) @@ -223,7 +221,7 @@ def test_import_endpoint_tests(self): driver.find_element(By.PARTIAL_LINK_TEXT, "Endpoint Test 2").click() driver.find_element(By.ID, "dropdownMenu1").click() driver.find_element(By.LINK_TEXT, "Re-Upload Scan").click() - driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path + "/dedupe_scans/dedupe_endpoint_2.xml")) + driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path / "dedupe_scans/dedupe_endpoint_2.xml")) driver.find_elements(By.CSS_SELECTOR, "button.btn.btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="a total of 3 findings")) @@ -276,7 +274,7 @@ def test_import_same_eng_tests(self): driver.find_element(By.PARTIAL_LINK_TEXT, "Same Eng Test 1").click() driver.find_element(By.ID, "dropdownMenu1").click() driver.find_element(By.LINK_TEXT, "Re-Upload Scan").click() - driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path + "/dedupe_scans/dedupe_endpoint_1.xml")) + driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path / "dedupe_scans/dedupe_endpoint_1.xml")) driver.find_elements(By.CSS_SELECTOR, "button.btn.btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="a total of 3 findings")) @@ -287,7 +285,7 @@ def test_import_same_eng_tests(self): driver.find_element(By.PARTIAL_LINK_TEXT, "Same Eng Test 2").click() driver.find_element(By.ID, "dropdownMenu1").click() driver.find_element(By.LINK_TEXT, "Re-Upload Scan").click() - driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path + "/dedupe_scans/dedupe_cross_1.csv")) + driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path / "dedupe_scans/dedupe_cross_1.csv")) driver.find_elements(By.CSS_SELECTOR, "button.btn.btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="a total of 3 findings")) @@ -345,7 +343,7 @@ def test_import_path_tests_checkmarx_scan(self): driver.find_element(By.ID, "dropdownMenu1").click() driver.find_element(By.LINK_TEXT, "Re-Upload Scan").click() # os.path.realpath makes the path canonical - driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path + "/dedupe_scans/multiple_findings.xml")) + driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path / "dedupe_scans/multiple_findings.xml")) driver.find_elements(By.CSS_SELECTOR, "button.btn.btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="a total of 2 findings")) @@ -356,7 +354,7 @@ def test_import_path_tests_checkmarx_scan(self): driver.find_element(By.PARTIAL_LINK_TEXT, "Path Test 2").click() driver.find_element(By.ID, "dropdownMenu1").click() driver.find_element(By.LINK_TEXT, "Re-Upload Scan").click() - driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path + "/dedupe_scans/multiple_findings_line_changed.xml")) + driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path / "dedupe_scans/multiple_findings_line_changed.xml")) driver.find_elements(By.CSS_SELECTOR, "button.btn.btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="a total of 2 findings")) @@ -419,7 +417,7 @@ def test_import_cross_test(self): driver.find_element(By.PARTIAL_LINK_TEXT, "Immuniweb Test").click() driver.find_element(By.CSS_SELECTOR, "i.fa-solid.fa-ellipsis-vertical").click() driver.find_element(By.LINK_TEXT, "Re-Upload Scan Results").click() - driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path + "/dedupe_scans/dedupe_endpoint_1.xml")) + driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path / "dedupe_scans/dedupe_endpoint_1.xml")) driver.find_elements(By.CSS_SELECTOR, "button.btn.btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="a total of 3 findings")) @@ -430,7 +428,7 @@ def test_import_cross_test(self): driver.find_element(By.PARTIAL_LINK_TEXT, "Generic Test").click() driver.find_element(By.CSS_SELECTOR, "i.fa-solid.fa-ellipsis-vertical").click() driver.find_element(By.LINK_TEXT, "Re-Upload Scan Results").click() - driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path + "/dedupe_scans/dedupe_cross_1.csv")) + driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path / "dedupe_scans/dedupe_cross_1.csv")) driver.find_elements(By.CSS_SELECTOR, "button.btn.btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="a total of 3 findings")) @@ -452,7 +450,7 @@ def test_import_no_service(self): driver.find_element(By.PARTIAL_LINK_TEXT, "Path Test 1").click() driver.find_element(By.ID, "dropdownMenu1").click() driver.find_element(By.LINK_TEXT, "Re-Upload Scan").click() - driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path + "/dedupe_scans/multiple_findings.xml")) + driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path / "dedupe_scans/multiple_findings.xml")) driver.find_elements(By.CSS_SELECTOR, "button.btn.btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="Checkmarx Scan processed a total of 2 findings created 2 findings.")) @@ -463,7 +461,7 @@ def test_import_no_service(self): driver.find_element(By.PARTIAL_LINK_TEXT, "Path Test 2").click() driver.find_element(By.ID, "dropdownMenu1").click() driver.find_element(By.LINK_TEXT, "Re-Upload Scan").click() - driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path + "/dedupe_scans/multiple_findings.xml")) + driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path / "dedupe_scans/multiple_findings.xml")) driver.find_elements(By.CSS_SELECTOR, "button.btn.btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="Checkmarx Scan processed a total of 2 findings created 2 findings.")) @@ -484,7 +482,7 @@ def test_import_service(self): driver.find_element(By.ID, "dropdownMenu1").click() driver.find_element(By.LINK_TEXT, "Re-Upload Scan").click() driver.find_element(By.ID, "id_service").send_keys("service_1") - driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path + "/dedupe_scans/multiple_findings.xml")) + driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path / "dedupe_scans/multiple_findings.xml")) driver.find_elements(By.CSS_SELECTOR, "button.btn.btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="Checkmarx Scan processed a total of 2 findings created 2 findings.")) @@ -496,7 +494,7 @@ def test_import_service(self): driver.find_element(By.ID, "dropdownMenu1").click() driver.find_element(By.LINK_TEXT, "Re-Upload Scan").click() driver.find_element(By.ID, "id_service").send_keys("service_2") - driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path + "/dedupe_scans/multiple_findings.xml")) + driver.find_element(By.ID, "id_file").send_keys(os.path.realpath(self.relative_path / "dedupe_scans/multiple_findings.xml")) driver.find_elements(By.CSS_SELECTOR, "button.btn.btn-primary")[1].click() self.assertTrue(self.is_success_message_present(text="Checkmarx Scan processed a total of 2 findings created 2 findings.")) diff --git a/tests/report_builder_test.py b/tests/report_builder_test.py index 8cc0c6ebce9..1bce835afbd 100644 --- a/tests/report_builder_test.py +++ b/tests/report_builder_test.py @@ -1,7 +1,5 @@ -import os import sys import unittest -from pathlib import Path from base_test_class import BaseTestCase from product_test import ProductTest @@ -10,8 +8,6 @@ from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import Select, WebDriverWait -dir_path = Path(os.path.realpath(__file__)).parent - class ReportBuilderTest(BaseTestCase):