4949from scanpipe .pipes import flag
5050from scanpipe .pipes import purldb
5151from scanpipe .tests import filter_warnings
52+ from scanpipe .tests import make_dependency
5253from scanpipe .tests import make_mock_response
5354from scanpipe .tests import make_package
5455from scanpipe .tests import make_project
@@ -1196,9 +1197,7 @@ def test_scanpipe_management_command_check_compliance(self):
11961197 call_command ("check-compliance" , * options , stderr = out )
11971198 self .assertEqual (cm .exception .code , 1 )
11981199 out_value = out .getvalue ().strip ()
1199- expected = (
1200- "1 compliance issues detected on this project.\n [packages]\n > ERROR: 1"
1201- )
1200+ expected = "1 compliance issues detected.\n [packages]\n > ERROR: 1"
12021201 self .assertEqual (expected , out_value )
12031202
12041203 out = StringIO ()
@@ -1208,12 +1207,46 @@ def test_scanpipe_management_command_check_compliance(self):
12081207 self .assertEqual (cm .exception .code , 1 )
12091208 out_value = out .getvalue ().strip ()
12101209 expected = (
1211- "2 compliance issues detected on this project ."
1210+ "2 compliance issues detected."
12121211 "\n [packages]\n > ERROR: 1"
12131212 "\n [resources]\n > WARNING: 1"
12141213 )
12151214 self .assertEqual (expected , out_value )
12161215
1216+ def test_scanpipe_management_command_check_compliance_vulnerabilities (self ):
1217+ project = make_project (name = "my_project" )
1218+ package1 = make_package (
project ,
package_url = "pkg:generic/[email protected] " )
1219+
1220+ out = StringIO ()
1221+ options = ["--project" , project .name , "--fail-on-vulnerabilities" ]
1222+ with self .assertRaises (SystemExit ) as cm :
1223+ call_command ("check-compliance" , * options , stdout = out )
1224+ self .assertEqual (cm .exception .code , 0 )
1225+ out_value = out .getvalue ().strip ()
1226+ self .assertEqual ("No vulnerabilities found" , out_value )
1227+
1228+ vulnerability_data = [{"vulnerability_id" : "VCID-cah8-awtr-aaad" }]
1229+ package1 .update (affected_by_vulnerabilities = vulnerability_data )
1230+ make_dependency (
1231+ project ,
1232+ dependency_uid = "dependency1" ,
1233+ affected_by_vulnerabilities = vulnerability_data ,
1234+ )
1235+ out = StringIO ()
1236+ options = ["--project" , project .name , "--fail-on-vulnerabilities" ]
1237+ with self .assertRaises (SystemExit ) as cm :
1238+ call_command ("check-compliance" , * options , stderr = out )
1239+ self .assertEqual (cm .exception .code , 1 )
1240+ out_value = out .getvalue ().strip ()
1241+ expected = (
1242+ "2 vulnerable records found:\n "
1243+ 1244+ " > VCID-cah8-awtr-aaad\n "
1245+ "dependency1\n "
1246+ " > VCID-cah8-awtr-aaad"
1247+ )
1248+ self .assertEqual (expected , out_value )
1249+
12171250 def test_scanpipe_management_command_report (self ):
12181251 label1 = "label1"
12191252 project1 = make_project ("project1" , labels = [label1 ])
0 commit comments