Skip to content

Commit c770983

Browse files
committed
Add support when the "components" entry is missing #1727
Signed-off-by: tdruez <[email protected]>
1 parent 88991d2 commit c770983

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

scanpipe/pipes/cyclonedx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def is_empty(value):
285285
elif isinstance(value, list) and not any(value):
286286
return True
287287

288-
for component in cyclonedx_document_json["components"]:
288+
for component in cyclonedx_document_json.get("components", []):
289289
for property_name, property_value in component.items():
290290
if is_empty(property_value) or property_name in ignored_properties:
291291
entries_to_delete.append((component, property_name))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"$schema": "http://cyclonedx.org/schema/bom-1.6.schema.json",
3+
"bomFormat": "CycloneDX",
4+
"specVersion": "1.6",
5+
"serialNumber": "urn:uuid:b74fe5df-e965-415e-ba65-f38421a0695d",
6+
"version": 1,
7+
"metadata": {
8+
"component": {
9+
"bom-ref": "804c3391-e6f9-415f-bb7a-cb6653853a46",
10+
"name": "name",
11+
"type": "library"
12+
},
13+
"timestamp": "2024-03-07T17:05:37.329061+00:00",
14+
"tools": [
15+
{
16+
"name": "ScanCode.io",
17+
"version": "0.0.0"
18+
}
19+
]
20+
}
21+
}

scanpipe/tests/pipes/test_cyclonedx.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ def test_scanpipe_cyclonedx_resolve_cyclonedx_packages_pre_validation(self):
270270
expected = [{"name": "asgiref", "package_uid": "pkg:pypi/[email protected]"}]
271271
self.assertEqual(expected, package_data)
272272

273+
def test_scanpipe_cyclonedx_resolve_cyclonedx_packages_missing_components(self):
274+
input_location = self.data / "missing_components.json"
275+
package_data = cyclonedx.resolve_cyclonedx_packages(input_location)
276+
self.assertEqual([], package_data)
277+
273278
def test_scanpipe_cyclonedx_cleanup_components_properties(self):
274279
cyclonedx_document_json = {
275280
"components": [

0 commit comments

Comments
 (0)