diff --git a/tools/components/preloads.py b/tools/components/preloads.py index f0216f1779..36d0b3dcc8 100644 --- a/tools/components/preloads.py +++ b/tools/components/preloads.py @@ -133,7 +133,8 @@ def artifact_bytes(origin, cache): if len(names) != 1: raise ValueError('Expected one original APK') with ZipFile(io.BytesIO(archive.read(names[0]))) as apk: - return {name: apk.read('assets/linuxfs/' + name) for name in FILES} + present = set(apk.namelist()) + return {name: apk.read('assets/linuxfs/' + name) for name in FILES if 'assets/linuxfs/' + name in present} def validate_lock(data): diff --git a/tools/tests/test_preload_snapshots.py b/tools/tests/test_preload_snapshots.py index 6629d1ab22..2d0ee01642 100644 --- a/tools/tests/test_preload_snapshots.py +++ b/tools/tests/test_preload_snapshots.py @@ -150,6 +150,30 @@ class PreloadSnapshotTest(unittest.TestCase): with self.assertRaisesRegex(ValueError, 'successful main'): snapshots.artifact_bytes(self.data['origin'], self.root / 'cache') + def test_origin_apk_without_a_newer_output_reads_the_rest(self): + from zipfile import ZipFile + newest = 'libddnatv-hook.so' + apk = io.BytesIO() + with ZipFile(apk, 'w') as z: + for name, value in self.binaries.items(): + if name != newest: + z.writestr('assets/linuxfs/' + name, value) + outer = io.BytesIO() + with ZipFile(outer, 'w') as z: + z.writestr('app-release.apk', apk.getvalue()) + digest = snapshots.sha(outer.getvalue()) + origin = dict(self.data['origin'], artifact_sha256=digest) + build = dict(event='push', head_branch='main', conclusion='success', head_sha=origin['commit'], + path='.github/workflows/build.yml', repository=dict(full_name=snapshots.REPO)) + artifact = dict(name='droiddeck-apk', workflow_run=dict(id=origin['run']), digest='sha256:' + digest) + cache = self.root / 'cache' + cache.mkdir() + (cache / (digest + '.zip')).write_bytes(outer.getvalue()) + with patch.object(snapshots, 'api', side_effect=[build, artifact]): + content = snapshots.artifact_bytes(origin, cache) + self.assertNotIn(newest, content) + self.assertEqual(set(content), snapshots.FILES - {newest}) + def test_corrupt_archive_is_rejected(self): with self.assertRaisesRegex(ValueError, 'checksum'): snapshots.unpack(self.content + b'tampered', self.data)