diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 6aa44a28..36ec0071 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -2689,9 +2689,11 @@ def get_apk_id(apkfile): try: return get_apk_id_androguard(apkfile) except zipfile.BadZipFile as e: - logging.error(apkfile + ': ' + str(e)) - if 'aapt' in config: + if config and 'aapt' in config: + logging.error(apkfile + ': ' + str(e)) return get_apk_id_aapt(apkfile) + else: + raise e def get_apk_id_androguard(apkfile): diff --git a/tests/common.TestCase b/tests/common.TestCase index 955de457..c511901d 100755 --- a/tests/common.TestCase +++ b/tests/common.TestCase @@ -21,7 +21,7 @@ import textwrap import yaml import gzip import stat -from zipfile import ZipFile, ZipInfo +from zipfile import BadZipFile, ZipFile, ZipInfo from unittest import mock from pathlib import Path @@ -959,9 +959,24 @@ class CommonTest(unittest.TestCase): self.assertEqual(versionCode, vc, 'aapt versionCode parsing failed for ' + apkfilename) self.assertEqual(versionName, vn, 'aapt versionName parsing failed for ' + apkfilename) + def test_get_apk_id_bad_path(self): with self.assertRaises(FDroidException): fdroidserver.common.get_apk_id('nope') + def test_get_apk_id_api_call(self): + self.assertEqual( + ('info.guardianproject.urzip', '100', '0.1'), + fdroidserver.common.get_apk_id('urzip.apk'), + ) + + def test_get_apk_id_bad_zip(self): + os.chdir(self.tmpdir) + badzip = 'badzip.apk' + with open(badzip, 'w') as fp: + fp.write('not a ZIP') + with self.assertRaises(BadZipFile): + fdroidserver.common.get_apk_id(badzip) + def test_get_apk_id_aapt_regex(self): files = glob.glob(os.path.join(self.basedir, 'build-tools', '[1-9]*.*', '*.txt')) self.assertNotEqual(0, len(files))