Skip to content

Commit

Permalink
fix / cleanup paths in integration tests (#11809)
Browse files Browse the repository at this point in the history
* fix integration test path handling

* Some adjustments to use Path properly.

* Typo

* Typo

---------

Co-authored-by: kiblik <5609770+kiblik@users.noreply.github.com>
  • Loading branch information
valentijnscholten and kiblik authored Feb 25, 2025
1 parent c115a59 commit f470502
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 51 deletions.
2 changes: 1 addition & 1 deletion docker/entrypoint-integration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/open_source/upgrading/2.44.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 4 additions & 1 deletion dojo/engagement/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
22 changes: 11 additions & 11 deletions tests/Import_scanner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
class ScannerTest(BaseTestCase):
def setUp(self):
super().setUp(self)
self.repo_path = dir_path + "/scans"
if Path(self.repo_path).is_dir():
self.repo_path = dir_path / "scans"
if self.repo_path.is_dir():
shutil.rmtree(self.repo_path)
Path(self.repo_path).mkdir()
self.repo_path.mkdir()
git.Repo.clone_from("https://github.com/DefectDojo/sample-scan-files", self.repo_path)
self.remove_items = ["__init__.py", "__init__.pyc", "factory.py", "factory.pyc",
"factory.py", "LICENSE", "README.md", ".gitignore", ".git", "__pycache__"]
tool_path = Path(dir_path[:-5] + "dojo/tools")
tool_path = dir_path.parent / "dojo" / "tools"
tools = sorted(any(tool_path.iterdir()))
p = Path(self.repo_path)
p = self.repo_path
tests = sorted(any(p.iterdir()))
self.tools = [i for i in tools if i not in self.remove_items]
self.tests = [i for i in tests if i not in self.remove_items]
Expand All @@ -44,7 +44,7 @@ def test_check_test_file(self):
missing_tests += ["\nNO TEST FILES"]

for test in self.tests:
p = Path(self.repo_path + "/" + test)
p = self.repo_path / test
cases = sorted(any(p.iterdir()))
cases = [i for i in cases if i not in self.remove_items]
if len(cases) == 0 and tool not in missing_tests:
Expand All @@ -60,7 +60,7 @@ def test_check_test_file(self):
self.assertEqual(len(missing_tests), 0)

def test_check_for_forms(self):
forms_path = dir_path[:-5] + "dojo/forms.py"
forms_path = dir_path.parent / "dojo" / "forms.py"
file = open(forms_path, "r+", encoding="utf-8")
forms = file.readlines()
file.close()
Expand Down Expand Up @@ -98,7 +98,7 @@ def test_check_for_forms(self):

@unittest.skip("Deprecated since Dynamic Parser infrastructure")
def test_check_for_options(self):
template_path = dir_path[:-5] + "dojo/templates/dojo/import_scan_results.html"
template_path = dir_path.parent / "dojo" / "templates" / "dojo" / "import_scan_results.html"
file = open(template_path, "r+", encoding="utf-8")
templates = file.readlines()
file.close()
Expand Down Expand Up @@ -179,7 +179,7 @@ def test_engagement_import_scan_result(self):

failed_tests = []
for test in self.tests:
p = Path(self.repo_path + "/" + test)
p = self.repo_path / test
cases = sorted(any(p.iterdir()))
cases = [i for i in cases if i not in self.remove_items]
if len(cases) == 0:
Expand All @@ -195,8 +195,8 @@ def test_engagement_import_scan_result(self):
driver.find_element(By.ID, "id_verified").get_attribute("checked")
scan_type = scan_map[test]
Select(driver.find_element(By.ID, "id_scan_type")).select_by_visible_text(scan_type)
test_location = self.repo_path + "/" + test + "/" + case
driver.find_element(By.ID, "id_file").send_keys(test_location)
test_location = self.repo_path / test / case
driver.find_element(By.ID, "id_file").send_keys(str(test_location))
driver.find_element(By.CSS_SELECTOR, "input.btn.btn-primary").click()
EngagementTXT = "".join(driver.find_element(By.TAG_NAME, "BODY").text).split("\n")
reg = re.compile(r"processed, a total of")
Expand Down
14 changes: 6 additions & 8 deletions tests/close_old_findings_dedupe_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

logger = logging.getLogger(__name__)

dir_path = Path(os.path.realpath(__file__)).parent


class CloseOldDedupeTest(BaseTestCase):
# --------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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(str(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"))
Expand All @@ -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(str(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"))
Expand All @@ -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(str(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"))
Expand Down Expand Up @@ -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(str(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"))
Expand All @@ -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(str(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"))
Expand All @@ -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(str(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"))
Expand Down
14 changes: 6 additions & 8 deletions tests/close_old_findings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

logger = logging.getLogger(__name__)

dir_path = Path(os.path.realpath(__file__)).parent


class CloseOldTest(BaseTestCase):
# --------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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(str(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"))
Expand All @@ -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(str(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"))
Expand All @@ -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"))
Expand Down Expand Up @@ -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(str(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"))
Expand All @@ -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(str(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"))
Expand All @@ -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(str(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"))
Expand Down
Loading

0 comments on commit f470502

Please sign in to comment.