@@ -3429,6 +3429,85 @@ def test_create_not_authorized_product_name_engagement_name_scan_type_title(self
34293429 importer_mock .assert_not_called ()
34303430 reimporter_mock .assert_not_called ()
34313431
3432+ # Security tests: verify that conflicting ID-based and name-based identifiers are rejected
3433+
3434+ @patch ("dojo.importers.default_reimporter.DefaultReImporter.process_scan" )
3435+ @patch ("dojo.importers.default_importer.DefaultImporter.process_scan" )
3436+ def test_reimport_with_engagement_id_mismatched_product_name_is_rejected (self , importer_mock , reimporter_mock ):
3437+ """Sending engagement ID from one product with product_name from another must be rejected."""
3438+ importer_mock .return_value = IMPORTER_MOCK_RETURN_VALUE
3439+ reimporter_mock .return_value = REIMPORTER_MOCK_RETURN_VALUE
3440+
3441+ with Path ("tests/zap_sample.xml" ).open (encoding = "utf-8" ) as testfile :
3442+ payload = {
3443+ "minimum_severity" : "Low" ,
3444+ "active" : True ,
3445+ "verified" : True ,
3446+ "scan_type" : "ZAP Scan" ,
3447+ "file" : testfile ,
3448+ # Engagement 1 belongs to Product 2 ("Security How-to")
3449+ "engagement" : 1 ,
3450+ # But product_name points to Product 1 ("Python How-to")
3451+ "product_name" : "Python How-to" ,
3452+ "engagement_name" : "April monthly engagement" ,
3453+ "version" : "1.0.0" ,
3454+ }
3455+ response = self .client .post (self .url , payload )
3456+ self .assertEqual (400 , response .status_code , response .content [:1000 ])
3457+ importer_mock .assert_not_called ()
3458+ reimporter_mock .assert_not_called ()
3459+
3460+ @patch ("dojo.importers.default_reimporter.DefaultReImporter.process_scan" )
3461+ @patch ("dojo.importers.default_importer.DefaultImporter.process_scan" )
3462+ def test_reimport_with_test_id_mismatched_product_name_is_rejected (self , importer_mock , reimporter_mock ):
3463+ """Sending test ID from one product with product_name from another must be rejected."""
3464+ importer_mock .return_value = IMPORTER_MOCK_RETURN_VALUE
3465+ reimporter_mock .return_value = REIMPORTER_MOCK_RETURN_VALUE
3466+
3467+ with Path ("tests/zap_sample.xml" ).open (encoding = "utf-8" ) as testfile :
3468+ payload = {
3469+ "minimum_severity" : "Low" ,
3470+ "active" : True ,
3471+ "verified" : True ,
3472+ "scan_type" : "ZAP Scan" ,
3473+ "file" : testfile ,
3474+ # Test 3 belongs to Engagement 1 -> Product 2 ("Security How-to")
3475+ "test" : 3 ,
3476+ # But product_name points to Product 1 ("Python How-to")
3477+ "product_name" : "Python How-to" ,
3478+ "version" : "1.0.0" ,
3479+ }
3480+ response = self .client .post (self .url , payload )
3481+ self .assertEqual (400 , response .status_code , response .content [:1000 ])
3482+ importer_mock .assert_not_called ()
3483+ reimporter_mock .assert_not_called ()
3484+
3485+ @patch ("dojo.importers.default_reimporter.DefaultReImporter.process_scan" )
3486+ @patch ("dojo.importers.default_importer.DefaultImporter.process_scan" )
3487+ def test_reimport_with_test_id_mismatched_engagement_name_is_rejected (self , importer_mock , reimporter_mock ):
3488+ """Sending test ID from one engagement with engagement_name from another must be rejected."""
3489+ importer_mock .return_value = IMPORTER_MOCK_RETURN_VALUE
3490+ reimporter_mock .return_value = REIMPORTER_MOCK_RETURN_VALUE
3491+
3492+ with Path ("tests/zap_sample.xml" ).open (encoding = "utf-8" ) as testfile :
3493+ payload = {
3494+ "minimum_severity" : "Low" ,
3495+ "active" : True ,
3496+ "verified" : True ,
3497+ "scan_type" : "ZAP Scan" ,
3498+ "file" : testfile ,
3499+ # Test 3 belongs to Engagement 1 ("1st Quarter Engagement")
3500+ "test" : 3 ,
3501+ # But engagement_name points to a different engagement
3502+ "product_name" : "Security How-to" ,
3503+ "engagement_name" : "April monthly engagement" ,
3504+ "version" : "1.0.0" ,
3505+ }
3506+ response = self .client .post (self .url , payload )
3507+ self .assertEqual (400 , response .status_code , response .content [:1000 ])
3508+ importer_mock .assert_not_called ()
3509+ reimporter_mock .assert_not_called ()
3510+
34323511
34333512@versioned_fixtures
34343513class ProductTypeTest (BaseClass .BaseClassTest ):
0 commit comments