From 0d5c7516f2aa3ff40151e095df53b0ae05bd543b Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 16 May 2024 11:55:01 +0200 Subject: [PATCH] throw error when CLI appid args end with a : but no Version Code This is already the behavior in read_app_args(), but wasn't implemented in read_pkg_args() yet. --- fdroidserver/common.py | 20 ++++++++++++++------ tests/common.TestCase | 7 +++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 29a5747d..28ea3736 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -868,13 +868,13 @@ def get_local_metadata_files(): return glob.glob('.fdroid.[a-jl-z]*[a-rt-z]') -def read_pkg_args(appid_versionCode_pairs, allow_vercodes=False): +def read_pkg_args(appid_versionCode_pairs, allow_version_codes=False): """No summary. Parameters ---------- appids - arguments in the form of multiple appid:[vc] strings + arguments in the form of multiple appid:[versionCode] strings Returns ------- @@ -884,13 +884,18 @@ def read_pkg_args(appid_versionCode_pairs, allow_vercodes=False): if not appid_versionCode_pairs: return vercodes + error = False apk_regex = re.compile(r'_(\d+)\.apk$') for p in appid_versionCode_pairs: # Convert the apk name to a appid:versioncode pair p = apk_regex.sub(r':\1', p) - if allow_vercodes and ':' in p: + if allow_version_codes and ':' in p: package, vercode = p.split(':') - vercode = version_code_string_to_int(vercode) + try: + vercode = version_code_string_to_int(vercode) + except ValueError as e: + logging.error('"%s": %s' % (p, str(e))) + error = True else: package, vercode = p, None if package not in vercodes: @@ -899,6 +904,9 @@ def read_pkg_args(appid_versionCode_pairs, allow_vercodes=False): elif vercode and vercode not in vercodes[package]: vercodes[package] += [vercode] if vercode else [] + if error: + raise FDroidException(_("Found invalid versionCodes for some apps")) + return vercodes @@ -930,7 +938,7 @@ def get_metadata_files(vercodes): return metadatafiles -def read_app_args(appid_versionCode_pairs, allapps, allow_vercodes=False): +def read_app_args(appid_versionCode_pairs, allapps, allow_version_codes=False): """Build a list of App instances for processing. On top of what read_pkg_args does, this returns the whole app @@ -940,7 +948,7 @@ def read_app_args(appid_versionCode_pairs, allapps, allow_vercodes=False): returned. """ - vercodes = read_pkg_args(appid_versionCode_pairs, allow_vercodes) + vercodes = read_pkg_args(appid_versionCode_pairs, allow_version_codes) if not vercodes: return allapps diff --git a/tests/common.TestCase b/tests/common.TestCase index cf961f8d..a3a54bb7 100755 --- a/tests/common.TestCase +++ b/tests/common.TestCase @@ -2321,6 +2321,13 @@ class CommonTest(unittest.TestCase): fdroidserver.common.read_pkg_args(appid_versionCode_pairs, allow_vercodes), ) + def test_read_pkg_args_errors(self): + allow_vercodes = True + with self.assertRaises(FDroidException): + fdroidserver.common.read_pkg_args(['org.fdroid.fdroid:'], allow_vercodes), + with self.assertRaises(FDroidException): + fdroidserver.common.read_pkg_args(['org.fdroid.fdroid:foo'], allow_vercodes), + def test_apk_strip_v1_signatures(self): before = os.path.join(self.basedir, 'no_targetsdk_minsdk1_unsigned.apk') after = os.path.join(self.testdir, 'after.apk')