mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-24 18:47:53 -06:00
fix: check zipped pack members like the builder
This commit is contained in:
1 parent
434d660647
commit
75b5fb987e
6 files changed
+99
-69
No files matched your search
@@ -5953,9 +5953,10 @@ class ZippedFileMd5IsParsedOnce(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_the_three_sites_share_the_parser(self):
|
||||
for module in ("resolve/validation.py", "packs/integrity.py", "verify.py"):
|
||||
for module in ("resolve/validation.py", "verify.py"):
|
||||
source = script_source(module)
|
||||
self.assertIn("parse_md5_list(", source, module)
|
||||
self.assertIn("inner_rom_data_check(", script_source("packs/integrity.py"))
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5406,18 +5406,6 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
self.assertTrue(result[3][0].startswith("baseline missing: "))
|
||||
self.assertEqual(result[9], 0)
|
||||
|
||||
def test_214_hash_matches_truncated_and_multi(self):
|
||||
"""Declared-hash compare handles truncation, case, multi-values."""
|
||||
from packs.integrity import _hash_matches
|
||||
|
||||
full = "85254fbe320ca82a768ec2c26bb08def"
|
||||
self.assertTrue(_hash_matches(full, full))
|
||||
self.assertTrue(_hash_matches(full.upper(), full))
|
||||
self.assertTrue(_hash_matches(full[:29], full)) # Batocera truncated
|
||||
self.assertTrue(_hash_matches(f"deadbeef, {full}", full))
|
||||
self.assertFalse(_hash_matches("0" * 32, full))
|
||||
self.assertFalse(_hash_matches("", full))
|
||||
|
||||
def test_216_resolve_by_sha256(self):
|
||||
"""resolve_local_file matches files by declared sha256."""
|
||||
import tempfile
|
||||
|
||||
@@ -58,6 +58,40 @@ class ZippedMemberIsChecked(unittest.TestCase):
|
||||
|
||||
|
||||
|
||||
class PackIntegrityChecksTheMember(unittest.TestCase):
|
||||
"""Step 6 skipped a zipped_file entry without md5 and matched a cut md5
|
||||
by prefix: dragon32.zip without d32.rom passed where Batocera refuses it
|
||||
(batocera-systems checkInsideZip with md5 "", whole-string compare)."""
|
||||
|
||||
def _verdict(self, members: dict[str, bytes], entry: dict) -> str | None:
|
||||
import io
|
||||
|
||||
from packs.integrity import _check_member_hash
|
||||
|
||||
inner = io.BytesIO()
|
||||
with zipfile.ZipFile(inner, "w") as zf:
|
||||
for name, data in members.items():
|
||||
zf.writestr(name, data)
|
||||
pack = io.BytesIO()
|
||||
with zipfile.ZipFile(pack, "w") as zf:
|
||||
zf.writestr("bios/dragon32.zip", inner.getvalue())
|
||||
with zipfile.ZipFile(pack) as zf:
|
||||
return _check_member_hash(zf, "bios/dragon32.zip", entry, "md5")
|
||||
|
||||
def test_member_needed_without_md5(self):
|
||||
entry = {"name": "dragon32.zip", "zipped_file": "d32.rom"}
|
||||
self.assertIn("not found inside ZIP", self._verdict({"other.rom": b"x"}, entry))
|
||||
self.assertIsNone(self._verdict({"D32.ROM": b"x"}, entry))
|
||||
|
||||
def test_whole_md5_only(self):
|
||||
md5 = hashlib.md5(b"x").hexdigest()
|
||||
members = {"d32.rom": b"x"}
|
||||
entry = {"name": "dragon32.zip", "zipped_file": "d32.rom"}
|
||||
self.assertIsNone(self._verdict(members, {**entry, "md5": f"{'0' * 32},{md5}"}))
|
||||
self.assertIsNone(self._verdict(members, {**entry, "md5": ["0" * 32, md5.upper()]}))
|
||||
self.assertIsNotNone(self._verdict(members, {**entry, "md5": md5[:29]}))
|
||||
|
||||
|
||||
class TheMemberIndexIsCachedByContent(unittest.TestCase):
|
||||
"""Each pipeline step that resolves a zipped_file decompressed all 54 845
|
||||
archive members again, about 23 s a step."""
|
||||
|
||||
Reference in new issue
Block a user