Skip to content

Commit

Permalink
Merge pull request #129 from CybercentreCanada/bugfix/duplicate_name_…
Browse files Browse the repository at this point in the history
…hashes

Bugfix/duplicate name hashes
  • Loading branch information
cccs-rs authored Jan 19, 2024
2 parents ecf4ee5 + 8c0d124 commit 1d80262
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions assemblyline_service_utilities/testing/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,23 @@ def _data_compare(ih: IssueHelper, original, new, data_type, ignore_new_extra_fi

@staticmethod
def _file_compare(ih: IssueHelper, f_type, original, new):
# Create a set of maps for lookups between sha256 and names
oh_map, on_map, nh_map, nn_map = {}, {}, {}, {}
[
(
oh_map.setdefault(x["sha256"], []).append(x["name"]),
on_map.setdefault(x["name"], []).append(x["sha256"])
)
for x in original
]
[
(
nh_map.setdefault(x["sha256"], []).append(x["name"]),
nn_map.setdefault(x["name"], []).append(x["sha256"])
)
for x in new
]

oh_map = {x["sha256"]: x["name"] for x in original}
on_map = {x["name"]: x["sha256"] for x in original}
nh_map = {x["sha256"]: x["name"] for x in new}
Expand All @@ -514,15 +531,15 @@ def _file_compare(ih: IssueHelper, f_type, original, new):
ih.add_issue(f_type, ih.ACTION_MISSING, f"File '{name} [{sha256}]' missing from the file list.")
continue

if sha256 != nn_map[name]:
if sha256 not in nn_map[name]:
ih.add_issue(
f_type,
ih.ACTION_CHANGED,
f"The sha256 of the file '{name}' has changed. {sha256} -> {nn_map[name]}",
)
continue

if name != nh_map[sha256]:
if name not in nh_map[sha256]:
ih.add_issue(
f_type,
ih.ACTION_CHANGED,
Expand Down

0 comments on commit 1d80262

Please sign in to comment.