Skip to content

Commit

Permalink
Import History: Adding a few tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Maffooch committed May 21, 2024
1 parent 342d14e commit b351adc
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
38 changes: 38 additions & 0 deletions unittests/scans/generic/test_import_report1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "Unicorn",
"type": "Unicorn",
"findings": [
{
"title": "Henry Smith",
"description": "small",
"severity": "Critical",
"active": false,
"verified": false,
"is_mitigated": true
},
{
"title": "Emma Jones",
"description": "small",
"severity": "Critical",
"active": false,
"verified": false,
"is_mitigated": true
},
{
"title": "Emma Jones",
"description": "small",
"severity": "Critical",
"active": true,
"verified": true,
"is_mitigated": false
},
{
"title": "Emma Jones",
"description": "small",
"severity": "Critical",
"active": false,
"verified": false,
"is_mitigated": true
}
]
}
38 changes: 38 additions & 0 deletions unittests/scans/generic/test_import_report2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "Unicorn",
"type": "Unicorn",
"findings": [
{
"title": "Henry Smith",
"description": "small",
"severity": "Critical",
"active": false,
"verified": false,
"is_mitigated": true
},
{
"title": "Henry Smith",
"description": "small",
"severity": "Critical",
"active": false,
"verified": false,
"is_mitigated": true
},
{
"title": "Henry Smith",
"description": "small",
"severity": "Critical",
"active": false,
"verified": false,
"is_mitigated": true
},
{
"title": "Henry Smith",
"description": "small",
"severity": "Critical",
"active": true,
"verified": true,
"is_mitigated": false
}
]
}
15 changes: 15 additions & 0 deletions unittests/test_import_reimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ def __init__(self, *args, **kwargs):
self.clair_empty = self.scans_path + 'clair/clair_empty.json'
self.scan_type_clair = 'Clair Scan'

self.scan_type_generic = "Generic Findings Import"
self.generic_filename_with_file = self.scans_path + "generic/test_with_image.json"
self.generic_import_1 = self.scans_path + "generic/test_import_report1.json"
self.generic_import_2 = self.scans_path + "generic/test_import_report2.json"

self.aws_prowler_file_name = self.scans_path + 'aws_prowler/many_vuln.json'
self.aws_prowler_file_name_plus_one = self.scans_path + 'aws_prowler/many_vuln_plus_one.json'
Expand Down Expand Up @@ -1445,6 +1448,18 @@ def test_import_reimport_vulnerability_ids(self):
self.assertEqual('GHSA-v6rh-hp5x-86rv', findings[3].vulnerability_ids[0])
self.assertEqual('CVE-2021-44420', findings[3].vulnerability_ids[1])

def test_import_history_reactivated_and_untouched_findings_do_not_mix(self):
with assertTestImportModelsCreated(self, imports=1, affected_findings=4, created=4):
import0 = self.import_scan_with_params(self.generic_import_1, scan_type=self.scan_type_generic)
test_id = import0['test']
# reimport the second report
with assertTestImportModelsCreated(self, reimports=1, affected_findings=4, closed=3, reactivated=1):
self.reimport_scan_with_params(test_id, self.generic_import_2, scan_type=self.scan_type_generic)
# reimport the first report again
with assertTestImportModelsCreated(self, reimports=1, affected_findings=2, closed=1, reactivated=1):
self.reimport_scan_with_params(test_id, self.generic_import_1, scan_type=self.scan_type_generic)
# Passing this test means an exception does not occur


class ImportReimportTestAPI(DojoAPITestCase, ImportReimportMixin):
fixtures = ['dojo_testdata.json']
Expand Down

0 comments on commit b351adc

Please sign in to comment.