Skip to content

Commit ef68257

Browse files
authored
Turn off CycloneDX document validation and load data anyway #1515 (#1516)
Signed-off-by: tdruez <tdruez@nexb.com>
1 parent 5de4116 commit ef68257

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ v34.9.4 (unreleased)
1616
the input filename.
1717
https://github.com/aboutcode-org/scancode.io/issues/926
1818

19+
- Disable CycloneDX document strict validation, which halts the entire loading process,
20+
and let the data loading process handle the data issues.
21+
https://github.com/aboutcode-org/scancode.io/issues/1515
22+
1923
v34.9.3 (2024-12-31)
2024
--------------------
2125

scanpipe/pipes/cyclonedx.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,14 @@ def get_bom_instance_from_file(input_location):
296296
cyclonedx_document = delete_ignored_root_properties(cyclonedx_document)
297297
cyclonedx_document = cleanup_components_properties(cyclonedx_document)
298298

299-
if errors := validate_document(cyclonedx_document):
300-
error_msg = (
301-
f'CycloneDX document "{input_path.name}" is not valid:\n{errors}'
302-
)
303-
raise ValueError(error_msg)
299+
# Instead of validating and raising an error (which halts the entire loading
300+
# process), we proceed to load as much data as possible.
301+
# This approach prioritizes displaying data in the UI over the output of
302+
# validate_document() which is not quite pertinent in its current state.
303+
# Additionally, the ValidationError from validate_document() might include the
304+
# entire document content, which is impractical for large files.
305+
#
306+
# validation_error = validate_document(cyclonedx_document)
304307

305308
cyclonedx_bom = Bom.from_json(data=cyclonedx_document)
306309
return cyclonedx_bom

scanpipe/tests/pipes/test_cyclonedx.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -200,31 +200,13 @@ def test_scanpipe_cyclonedx_component_to_package_data_encoded_purl_name(self):
200200
self.assertEqual(expected, package_data)
201201

202202
def test_scanpipe_cyclonedx_get_bom_instance_from_file(self):
203-
input_location = self.data / "missing_schema.json"
204-
with self.assertRaises(ValueError) as cm:
205-
cyclonedx.get_bom_instance_from_file(input_location)
206-
expected_error = (
207-
'CycloneDX document "missing_schema.json" is not valid:\n'
208-
"Additional properties are not allowed ('invalid_entry' was unexpected)"
209-
)
210-
self.assertIn(expected_error, str(cm.exception))
211-
212203
input_location = self.data / "laravel-7.12.0" / "bom.1.4.json"
213204
bom = cyclonedx.get_bom_instance_from_file(input_location)
214205
self.assertIsInstance(bom, Bom)
215206
self.assertEqual(62, len(bom.components))
216207
self.assertEqual(63, len(bom.dependencies))
217208

218209
def test_scanpipe_cyclonedx_resolve_cyclonedx_packages(self):
219-
input_location = self.data / "missing_schema.json"
220-
with self.assertRaises(ValueError) as cm:
221-
cyclonedx.resolve_cyclonedx_packages(input_location)
222-
expected_error = (
223-
'CycloneDX document "missing_schema.json" is not valid:\n'
224-
"Additional properties are not allowed ('invalid_entry' was unexpected)"
225-
)
226-
self.assertIn(expected_error, str(cm.exception))
227-
228210
packages = cyclonedx.resolve_cyclonedx_packages(self.bom_file)
229211
self.assertEqual(3, len(packages))
230212

0 commit comments

Comments
 (0)