File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3030from cyclonedx .model import license as cdx_license_model
3131from cyclonedx .model .bom import Bom
3232from cyclonedx .schema import SchemaVersion
33+ from cyclonedx .schema .schema import BaseSchemaVersion
3334from cyclonedx .validation import ValidationError
3435from cyclonedx .validation .json import JsonStrictValidator
3536from defusedxml import ElementTree as SafeElementTree
@@ -184,10 +185,12 @@ def cyclonedx_component_to_package_data(
184185 affected_by_vulnerabilities = []
185186 if affected_by := vulnerabilities .get (bom_ref ):
186187 for cdx_vulnerability in affected_by :
188+ cdx_vulnerability_json = cdx_vulnerability .as_json (view_ = BaseSchemaVersion )
187189 affected_by_vulnerabilities .append (
188190 {
189191 "vulnerability_id" : str (cdx_vulnerability .id ),
190192 "summary" : cdx_vulnerability .description ,
193+ "cdx_vulnerability_json" : cdx_vulnerability_json ,
191194 }
192195 )
193196
Original file line number Diff line number Diff line change @@ -250,13 +250,25 @@ def test_scanpipe_cyclonedx_resolve_cyclonedx_packages_vulnerabilities(self):
250250 self .assertEqual (1 , len (packages ))
251251
252252 affected_by = packages [0 ]["affected_by_vulnerabilities" ]
253+ self .assertEqual ("CVE-2005-2541" , affected_by [0 ]["vulnerability_id" ])
254+ self .assertEqual (
255+ "Tar 1.15.1 does not properly warn the user when..." ,
256+ affected_by [0 ]["summary" ],
257+ )
258+ self .assertIn ("cdx_vulnerability_json" , affected_by [0 ])
259+ vulnerability_json = affected_by [0 ]["cdx_vulnerability_json" ]
260+ cdx_vulnerability = json .loads (vulnerability_json )
253261 expected = [
254- {
255- "vulnerability_id" : "CVE-2005-2541" ,
256- "summary" : "Tar 1.15.1 does not properly warn the user when..." ,
257- }
262+ "advisories" ,
263+ "affects" ,
264+ "description" ,
265+ "id" ,
266+ "published" ,
267+ "ratings" ,
268+ "source" ,
269+ "updated" ,
258270 ]
259- self .assertEqual (expected , affected_by )
271+ self .assertEqual (expected , list ( cdx_vulnerability . keys ()) )
260272
261273 def test_scanpipe_cyclonedx_resolve_cyclonedx_packages_pre_validation (self ):
262274 # This SBOM includes multiple deserialization issues that are "fixed"
Original file line number Diff line number Diff line change @@ -1638,13 +1638,25 @@ def test_scanpipe_load_sbom_pipeline_cyclonedx_with_vulnerabilities(self):
16381638
16391639 self .assertEqual (1 , project1 .discoveredpackages .count ())
16401640 package = project1 .discoveredpackages .get ()
1641+ affected_by = package .affected_by_vulnerabilities [0 ]
1642+ cdx_vulnerability_json = affected_by .pop ("cdx_vulnerability_json" )
1643+ expected = {
1644+ "vulnerability_id" : "CVE-2005-2541" ,
1645+ "summary" : "Tar 1.15.1 does not properly warn the user when..." ,
1646+ }
1647+ self .assertEqual (expected , affected_by )
1648+ cdx_vulnerability = json .loads (cdx_vulnerability_json )
16411649 expected = [
1642- {
1643- "vulnerability_id" : "CVE-2005-2541" ,
1644- "summary" : "Tar 1.15.1 does not properly warn the user when..." ,
1645- }
1650+ "advisories" ,
1651+ "affects" ,
1652+ "description" ,
1653+ "id" ,
1654+ "published" ,
1655+ "ratings" ,
1656+ "source" ,
1657+ "updated" ,
16461658 ]
1647- self .assertEqual (expected , package . affected_by_vulnerabilities )
1659+ self .assertEqual (expected , list ( cdx_vulnerability . keys ()) )
16481660
16491661 @mock .patch ("scanpipe.pipes.purldb.request_post" )
16501662 @mock .patch ("uuid.uuid4" )
You can’t perform that action at this time.
0 commit comments