Skip to content

Commit 9688dfc

Browse files
Fix package checksum reporting
Package checksums were being wrongly ignored in package instance data update from detected package data, this commit fixes that. Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent 0f57bce commit 9688dfc

File tree

11 files changed

+28
-20
lines changed

11 files changed

+28
-20
lines changed

src/formattedcode/output_cyclonedx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def from_package(cls, package):
268268
properties.append(
269269
CycloneDxProperty(
270270
name='WARNING',
271-
value=f'WARNING: component skipped in CycloneDX output: {self!r}'
271+
value=f'WARNING: component skipped in CycloneDX output: {package!r}'
272272
)
273273
)
274274

src/packagedcode/models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ def populate_instance_from_package_data(self, package_data_by_path, uuid):
853853
logger.debug('Merging package manifest data for: {}'.format(path))
854854
logger.debug('package manifest data: {}'.format(repr(package_data)))
855855
self.package_data_paths.append(path)
856-
self.merge_package_data_into_instance(package_data.copy())
856+
self.update(package_data.copy())
857857

858858
self.package_data_paths = tuple(self.package_data_paths)
859859

@@ -939,12 +939,12 @@ def get_file_patterns(self, manifests):
939939

940940
return manifest_file_patterns
941941

942-
def merge_package_data_into_instance(self, package_data, replace=False):
942+
def update(self, package_data, replace=False):
943943
"""
944-
Merge the `package_data` ScannedPackage object into the `package_instance`
945-
Package model object.
944+
Update the PackageInstance object with data from the `package_data`
945+
object.
946946
When an `package_instance` field has no value one side and and the
947-
package_data field has a value, the package_instance field is always
947+
`package_data` field has a value, the `package_instance` field is always
948948
set to this value.
949949
If `replace` is True and a field has a value on both sides, then
950950
package_instance field value will be replaced by the package_data
@@ -954,7 +954,7 @@ def merge_package_data_into_instance(self, package_data, replace=False):
954954
existing_mapping = self.get_package_data()
955955

956956
# Remove PackageData specific attributes
957-
for attribute in ('md5', 'sha1', 'sha256', 'sha512', 'root_path'):
957+
for attribute in ['root_path']:
958958
package_data.pop(attribute, None)
959959
existing_mapping.pop(attribute, None)
960960

tests/formattedcode/data/cyclonedx/expected.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
"author": "Isaac Z. Schlueter",
1616
"description": "a package manager for JavaScript",
1717
"purl": "pkg:npm/npm@2.13.5",
18-
"hashes": [],
18+
"hashes": [
19+
{
20+
"alg": "SHA-1",
21+
"content": "a124386bce4a90506f28ad4b1d1a804a17baaf32"
22+
}
23+
],
1924
"licenses": [
2025
{
2126
"expression": "Artistic-2.0"

tests/formattedcode/data/cyclonedx/expected.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
<author>Isaac Z. Schlueter</author>
1818
<scope>required</scope>
1919
<purl>pkg:npm/npm@2.13.5</purl>
20+
<hashes>
21+
<hash alg="SHA-1">a124386bce4a90506f28ad4b1d1a804a17baaf32</hash>
22+
</hashes>
2023
<licenses>
2124
<expression>Artistic-2.0</expression>
2225
</licenses>

tests/licensedcode/data/plugin_licenses_reference/scan.expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"homepage_url": "https://docs.npmjs.com/",
5050
"download_url": "https://registry.npmjs.org/npm/-/npm-2.13.5.tgz",
5151
"size": null,
52-
"sha1": null,
52+
"sha1": "a124386bce4a90506f28ad4b1d1a804a17baaf32",
5353
"md5": null,
5454
"sha256": null,
5555
"sha512": null,

tests/packagedcode/data/instance/python-manifests-atomicwrites-scanned-result.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"size": null,
3232
"sha1": null,
3333
"md5": null,
34-
"sha256": null,
34+
"sha256": "6e45251662433bf51f96fb3d2204b65416fece329d60e6235c0f0edc416cfe24",
3535
"sha512": null,
3636
"bug_tracking_url": null,
3737
"code_view_url": null,

tests/packagedcode/data/plugin/python-package-expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"message": null,
1515
"errors": [],
1616
"extra_data": {
17-
"spdx_license_list_version": "3.14",
17+
"spdx_license_list_version": "3.16",
1818
"files_count": 8
1919
}
2020
}
@@ -328,7 +328,7 @@
328328
"size": null,
329329
"sha1": null,
330330
"md5": null,
331-
"sha256": null,
331+
"sha256": "6e45251662433bf51f96fb3d2204b65416fece329d60e6235c0f0edc416cfe24",
332332
"sha512": null,
333333
"bug_tracking_url": null,
334334
"code_view_url": null,

tests/packagedcode/test_package_instance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_package_data_merge_generic(self, regen=False):
4343

4444
pk_instance = PythonPackageInstance()
4545
for manifest in manifests:
46-
pk_instance.merge_package_data_into_instance(manifest)
46+
pk_instance.update(manifest)
4747

4848
self.check_package(pk_instance, expected_file, regen)
4949

@@ -56,6 +56,6 @@ def test_package_data_merge_with_dependencies(self, regen=False):
5656

5757
pk_instance = PythonPackageInstance()
5858
for manifest in manifests:
59-
pk_instance.merge_package_data_into_instance(manifest)
59+
pk_instance.update(manifest)
6060

6161
self.check_package(pk_instance, expected_file, regen)

tests/summarycode/data/full_summary/summary.expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"message": null,
1717
"errors": [],
1818
"extra_data": {
19-
"spdx_license_list_version": "3.15",
19+
"spdx_license_list_version": "3.16",
2020
"files_count": 26
2121
}
2222
}
@@ -3069,7 +3069,7 @@
30693069
"homepage_url": "https://docs.npmjs.com/",
30703070
"download_url": "https://registry.npmjs.org/npm/-/npm-2.13.5.tgz",
30713071
"size": null,
3072-
"sha1": null,
3072+
"sha1": "a124386bce4a90506f28ad4b1d1a804a17baaf32",
30733073
"md5": null,
30743074
"sha256": null,
30753075
"sha512": null,

tests/summarycode/data/full_summary/summary_by_facet.expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"message": null,
2828
"errors": [],
2929
"extra_data": {
30-
"spdx_license_list_version": "3.15",
30+
"spdx_license_list_version": "3.16",
3131
"files_count": 26
3232
}
3333
}
@@ -3080,7 +3080,7 @@
30803080
"homepage_url": "https://docs.npmjs.com/",
30813081
"download_url": "https://registry.npmjs.org/npm/-/npm-2.13.5.tgz",
30823082
"size": null,
3083-
"sha1": null,
3083+
"sha1": "a124386bce4a90506f28ad4b1d1a804a17baaf32",
30843084
"md5": null,
30853085
"sha256": null,
30863086
"sha512": null,

0 commit comments

Comments
 (0)