@@ -15,8 +15,9 @@ class TagTests(DojoAPITestCase):
1515 def setUp (self , * args , ** kwargs ):
1616 super ().setUp ()
1717 self .login_as_admin ()
18- self .scans_path = get_unit_tests_scans_path ("zap" )
19- self .zap_sample5_filename = self .scans_path / "5_zap_sample_one.xml"
18+ self .zap_sample5_filename = get_unit_tests_scans_path ("zap" ) / "5_zap_sample_one.xml"
19+ self .generic_sample_with_tags_filename = get_unit_tests_scans_path ("generic" ) / "generic_report1.json"
20+ self .generic_sample_with_more_tags_filename = get_unit_tests_scans_path ("generic" ) / "generic_report1_more_tags.json"
2021
2122 def test_create_product_with_tags (self , expected_status_code : int = 201 ):
2223 product_id = Product .objects .all ().first ().id
@@ -285,6 +286,28 @@ def test_import_multipart_tags(self):
285286 for tag in success_tags :
286287 self .assertIn (tag , response ["tags" ])
287288
289+ def test_import_report_with_tags (self ):
290+ def assert_tags_in_findings (findings : list [dict ], expected_finding_count : int , desired_tags : list [str ]) -> None :
291+ self .assertEqual (expected_finding_count , len (findings ))
292+ for finding in findings :
293+ self .assertEqual (len (desired_tags ), len (finding .get ("tags" )))
294+ for tag in desired_tags :
295+ self .assertIn (tag , finding ["tags" ])
296+
297+ # Import a report with findings that have tags
298+ import0 = self .import_scan_with_params (self .generic_sample_with_tags_filename , scan_type = "Generic Findings Import" )
299+ test_id = import0 ["test" ]
300+ response = self .get_test_findings_api (test_id )
301+ findings = response ["results" ]
302+ # Make sure we have what we are looking for
303+ assert_tags_in_findings (findings , 2 , ["security" , "network" ])
304+ # Reimport with a different report that has more tags
305+ self .reimport_scan_with_params (test_id , self .generic_sample_with_more_tags_filename , scan_type = "Generic Findings Import" )
306+ response = self .get_test_findings_api (test_id )
307+ findings = response ["results" ]
308+ # Make sure we have what we are looking for
309+ assert_tags_in_findings (findings , 2 , ["security" , "network" , "hardened" ])
310+
288311
289312class InheritedTagsTests (DojoAPITestCase ):
290313 fixtures = ["dojo_testdata.json" ]
0 commit comments