Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions scanpipe/pipes/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,16 @@ def extract_headers(input_location, extract_fields):
document_data = input_path.read_text()

if str(input_location).endswith(".json"):
cyclonedx_document = json.loads(document_data)
extracted_headers = {
field: value
for field, value in cyclonedx_document.items()
if field in extract_fields
}
return extracted_headers

return {}
document = json.loads(document_data)
elif str(input_location).endswith((".yml", ".yaml")):
document = saneyaml.load(document_data)
else:
return {}

if not isinstance(document, dict):
return {}

extracted_headers = {
field: value for field, value in document.items() if field in extract_fields
}
return extracted_headers
16 changes: 16 additions & 0 deletions scanpipe/tests/pipes/test_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,22 @@ def test_scanpipe_resolve_get_manifest_headers(self):
headers = resolve.get_manifest_headers(resource)
self.assertEqual(expected, list(headers.keys()))

def test_scanpipe_resolve_get_manifest_headers_spdx_yaml(self):
input_location = self.data / "manifests" / "curl-7.70.0-v2.2.spdx.yml"
resource = mock.Mock(location=input_location)
expected = [
"SPDXID",
"spdxVersion",
"creationInfo",
"name",
"dataLicense",
"documentNamespace",
]
headers = resolve.get_manifest_headers(resource)
self.assertEqual(expected, list(headers.keys()))
self.assertEqual("SPDX-2.2", headers["spdxVersion"])
self.assertEqual("3.9", headers["creationInfo"]["licenseListVersion"])

def test_get_data_from_manifests_returns_tuple_when_no_resources(self):
project1 = Project.objects.create(name="TestEmptyManifest")
empty_resources = project1.codebaseresources.none()
Expand Down
Loading