fix: verify sha1 with the builder digest rule

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 06:01:18 +01:00
1 parent c8270b5361
commit f6d5e60501
2 files changed
+37 -6

No files matched your search

+7 -6
View File
@@ -195,26 +195,27 @@ def verify_entry_sha1(
) -> dict:
"""SHA1 verification -BizHawk firmware hash check."""
name = file_entry.get("name", "")
expected_sha1 = file_entry.get("sha1", "")
value = file_entry.get("sha1")
expected = [str(v).strip().lower() for v in (value if isinstance(value, list) else [value]) if v]
required = file_entry.get("required", True)
base = {"name": name, "required": required}
if not local_path:
return {**base, "status": Status.MISSING}
if not expected_sha1:
if not expected:
return {**base, "status": Status.OK, "path": local_path}
hashes = compute_hashes(local_path)
actual_sha1 = hashes["sha1"].lower()
if actual_sha1 == expected_sha1.lower():
# The builder's comparison, so the two count the same files as held.
if frontend_digest_matches(file_entry, local_path, "sha1"):
return {**base, "status": Status.OK, "path": local_path}
actual_sha1 = compute_hashes(local_path)["sha1"].lower()
return {
**base,
"status": Status.UNTESTED,
"path": local_path,
"reason": f"expected {expected_sha1[:12]}... got {actual_sha1[:12]}...",
"reason": f"expected {expected[0][:12]}... got {actual_sha1[:12]}...",
}
+30
View File
@@ -7939,5 +7939,35 @@ class EveryReaderOfACoreFileIsNamed(unittest.TestCase):
self.assertIsNone(omitted["SHARED.BIN"]["cores"])
class VerifySha1ReadsTheBuilderDigest(unittest.TestCase):
"""verify_entry_sha1 accepts what the builder's sha1 comparison accepts:
a list of revisions and a padded value, which it crashed on or refused."""
def setUp(self):
scratch = tempfile.TemporaryDirectory(dir=Path(__file__).resolve().parents[1] / "tmp")
self.addCleanup(scratch.cleanup)
self.path = str(Path(scratch.name) / "fw.bin")
Path(self.path).write_bytes(b"bizhawk firmware")
self.sha1 = hashlib.sha1(b"bizhawk firmware").hexdigest()
def _status(self, sha1: object) -> str:
from resolve.validation import frontend_digest_matches
entry = {"name": "fw.bin", "sha1": sha1}
builder = frontend_digest_matches(entry, self.path, "sha1")
status = verdicts.verify_entry_sha1(entry, self.path)["status"]
self.assertEqual(status == verdicts.Status.OK, builder)
return status
def test_a_list_of_revisions(self):
self.assertEqual(self._status(["0" * 40, self.sha1]), verdicts.Status.OK)
def test_a_padded_value(self):
self.assertEqual(self._status(self.sha1.upper() + " "), verdicts.Status.OK)
def test_another_dump(self):
self.assertEqual(self._status("0" * 40), verdicts.Status.UNTESTED)
if __name__ == "__main__":
unittest.main()