1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-16 20:00:11 +01:00

Merge branch 'appid-args-should-not-end-with-colon' into 'master'

throw error when CLI appid args end with a : but no Version Code

See merge request fdroid/fdroidserver!1522
This commit is contained in:
Hans-Christoph Steiner 2024-09-23 08:21:31 +00:00
commit 0d148d58e1
2 changed files with 21 additions and 6 deletions

View File

@ -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

View File

@ -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')