Compare commits

...

18 Commits

Author SHA1 Message Date
Jochen Sprickerhof e0c5d6371f Merge branch 'read_metadata' into 'master'
Read only metadata of apps given on the command line

See merge request fdroid/fdroidserver!1037
2024-05-08 00:04:30 +00:00
Hans-Christoph Steiner 4666330a4d Merge branch 'gradlefile' into 'master'
throw error if gradle build method is used but no build.gradle file is found

See merge request fdroid/fdroidserver!1479
2024-05-07 14:14:26 +00:00
linsui 7104411296 throw error if gradle build method is used but no build.gradle file is found 2024-05-07 14:13:47 +00:00
Hans-Christoph Steiner 99bd544ab9 Merge branch 'fedora-40-ci-failure' into 'master'
make it easier to support the Fedora job

See merge request fdroid/fdroidserver!1474
2024-05-07 14:11:53 +00:00
Hans-Christoph Steiner 5df3d27126 gitlab-ci: stay on Fedora 39 until it is no longer supported
We can rely on the debian:testing job to test the bleeding edge, and it is
a lot easier to troubleshoot.

The Fedora job is a lot harder to troubleshoot than the Debian-based jobs,
and they are often quite bleeding edge.  Currently, there is a change to
either Python or an image processing lib (Pillow?) that now compresses PNGs
differently than all previous releases.  That breaks the tests based on
processing images and checking the SHA-256 matches.

70e7e720b9
fdroidserver!669
2024-05-07 12:58:23 +00:00
Hans-Christoph Steiner 1b65e33835 make it easy to keep test artifacts from jobs
When troubleshooting things that are difficult to reproduce locally, like
different behaviors in the fedora_latest job, these changes make it easy to
keep the test files around after the tests run.  For example, if PNGs are
processed differently by newer Python versions.
2024-05-07 12:58:23 +00:00
Hans-Christoph Steiner 299e3e5f4c index: handle image processing diffs across various Python versions
Apparently, the newest Python thingies strip the PNGs a tiny bit smaller,
so a fixed file size will lead to the test failing:

https://gitlab.com/fdroid/fdroidserver/-/jobs/6703386074
```
Traceback (most recent call last):
  File "/builds/fdroid/fdroidserver/tests/index.TestCase", line 704, in test_package_metadata
    self.assertEqual(36027, metadata['featureGraphic']['en-US']['size'])
AssertionError: 36027 != 35619
```
2024-05-07 12:58:23 +00:00
Hans-Christoph Steiner 1cb1394de3 Merge branch 'debugkey' into 'master'
lint: blocklist known AOSP debug keys in AASK

See merge request fdroid/fdroidserver!1478
2024-05-07 11:33:12 +00:00
Hans-Christoph Steiner 9a9b5beeaa simplify test setup
I'm in the midst of working towards getting rid of the "config" instances
that are in the subcommand module, e.g. `fdroidserver.lint.config`
2024-05-07 11:33:04 +00:00
Hans-Christoph Steiner 14c8647909 add additional tests 2024-05-07 11:33:04 +00:00
linsui d243cbd030 lint: blocklist known AOSP debug keys in AASK 2024-05-07 11:33:04 +00:00
Michael Pöhn 08c553e1cb Merge branch 'deploy' into 'master'
deploy: retry when git push fails

See merge request fdroid/fdroidserver!1480
2024-05-06 06:36:58 +00:00
linsui f82d648cb1 deploy: retry when git push fails 2024-05-05 20:53:35 +00:00
Michael Pöhn 79586fd9e3 Merge branch 'fix-icons-in-fdroid-mirror' into 'master'
mirror: apparently the 'icons' dir does not always exist

See merge request fdroid/fdroidserver!1476
2024-05-05 17:14:49 +00:00
Hans-Christoph Steiner 6f07538cdc mirror: apparently the 'icons' dir does not always exist
https://apt.izzysoft.de/fdroid/archive/com.futsch1.medtimer_28.apk:
2024-04-21 18:55:20 ERROR 404: Not Found.
https://apt.izzysoft.de/fdroid/archive/com.hardbacknutter.nevertoomanybooks_75.apk:
2024-04-21 18:55:20 ERROR 404: Not Found.
https://apt.izzysoft.de/fdroid/archive/com.jovial.jrpn15_20.apk:
2024-04-21 18:55:20 ERROR 404: Not Found.
https://apt.izzysoft.de/fdroid/archive/com.jovial.jrpn2_20.apk:
2024-04-21 18:55:20 ERROR 404: Not Found.
https://apt.izzysoft.de/fdroid/archive/com.logger.app_8.apk:
2024-04-21 18:55:21 ERROR 404: Not Found.
https://apt.izzysoft.de/fdroid/archive/com.lorenzovainigli.foodexpirationdates.foss_22.apk:
2024-04-21 18:55:21 ERROR 404: Not Found.
https://apt.izzysoft.de/fdroid/archive/com.openathena_36.apk:
2024-04-21 18:55:21 ERROR 404: Not Found.
https://apt.izzysoft.de/fdroid/archive/com.oppzippy.openscq30_21.apk:
2024-04-21 18:55:21 ERROR 404: Not Found.
https://apt.izzysoft.de/fdroid/archive/com.sanmer.mrepo_713.apk:
2024-04-21 18:55:21 ERROR 404: Not Found.
https://apt.izzysoft.de/fdroid/archive/com.starry.myne_325.apk:
2024-04-21 18:55:21 ERROR 404: Not Found.
https://apt.izzysoft.de/fdroid/archive/dev.imranr.obtainium_22602.apk:
2024-04-21 18:55:22 ERROR 404: Not Found.
https://apt.izzysoft.de/fdroid/archive/dev.sanmer.pi_137.apk:
2024-04-21 18:55:22 ERROR 404: Not Found.
https://apt.izzysoft.de/fdroid/archive/org.breezyweather_50108.apk:
2024-04-21 18:55:22 ERROR 404: Not Found.
2024-04-21 18:55:22,448 ERROR: no "icon" in org.breezyweather
2024-04-21 18:55:22,449 ERROR: no "icon" in com.lorenzovainigli.foodexpirationdates.foss
2024-04-21 18:55:22,449 ERROR: no "icon" in com.jovial.jrpn15
2024-04-21 18:55:22,450 ERROR: no "icon" in com.jovial.jrpn2
2024-04-21 18:55:22,450 ERROR: no "icon" in com.logger.app
2024-04-21 18:55:22,450 ERROR: no "icon" in com.futsch1.medtimer
2024-04-21 18:55:22,451 ERROR: no "icon" in com.sanmer.mrepo
2024-04-21 18:55:22,451 ERROR: no "icon" in com.starry.myne
2024-04-21 18:55:22,451 ERROR: no "icon" in com.hardbacknutter.nevertoomanybooks
2024-04-21 18:55:22,452 ERROR: no "icon" in dev.imranr.obtainium
2024-04-21 18:55:22,452 ERROR: no "icon" in com.openathena
2024-04-21 18:55:22,453 ERROR: no "icon" in com.oppzippy.openscq30
2024-04-21 18:55:22,453 ERROR: no "icon" in dev.sanmer.pi
2024-04-21 18:55:22,454 CRITICAL: Unknown exception found!
Traceback (most recent call last):
  File "/home/fdroid/code/fdroid/fdroidserver/fdroid", line 22, in <module>
    fdroidserver.__main__.main()
  File "/home/fdroid/code/fdroid/fdroidserver/fdroidserver/__main__.py", line 230, in main
    raise e
  File "/home/fdroid/code/fdroid/fdroidserver/fdroidserver/__main__.py", line 211, in main
    mod.main()
  File "/home/fdroid/code/fdroid/fdroidserver/fdroidserver/mirror.py", line 269, in main
    _run_wget(os.path.join(basedir, section, icondir), urls[icondir])
KeyError: 'icons'
2024-05-02 18:29:42 +02:00
Jochen Sprickerhof 1f3411f14f
Drop duplicated code (already done in get_metadata_files) 2024-01-10 08:30:32 +01:00
Jochen Sprickerhof 86c537f8f2
Use vercodes in read_metadata interface
read_metadata is only called in read_app_args with an argument. As
vercodes is already there, drop the duplicate call.
2024-01-10 08:30:32 +01:00
Jochen Sprickerhof 293849c83a
Read only metadata of apps given on the command line 2024-01-10 08:30:26 +01:00
16 changed files with 96 additions and 42 deletions

View File

@ -285,9 +285,7 @@ black:
- black --check --diff --color $CI_PROJECT_DIR
fedora_latest:
image: fedora:latest
only:
- master@fdroid/fdroidserver
image: fedora:39 # support ends on 2024-11-12
script:
# tricks to hopefully make runs more reliable
- echo "timeout=600" >> /etc/dnf/dnf.conf

View File

@ -20,9 +20,7 @@ def main():
metadata.add_metadata_arguments(parser)
options = parser.parse_args()
common.options = options
pkgs = common.read_pkg_args(options.appid, True)
allapps = metadata.read_metadata(pkgs)
apps = common.read_app_args(options.appid, allapps, True)
apps = common.read_app_args(options.appid, allow_vercodes=True)
common.read_config(options)
srclib_dir = os.path.join('build', 'srclib')
os.makedirs(srclib_dir, exist_ok=True)

View File

@ -974,10 +974,7 @@ def main():
srclib_dir = os.path.join(build_dir, 'srclib')
extlib_dir = os.path.join(build_dir, 'extlib')
# Read all app and srclib metadata
pkgs = common.read_pkg_args(options.appid, True)
allapps = metadata.read_metadata(pkgs, sort_by_time=True)
apps = common.read_app_args(options.appid, allapps, True)
apps = common.read_app_args(options.appid, allow_vercodes=True, sort_by_time=True)
for appid, app in list(apps.items()):
if (app.get('Disabled') and not options.force) or not app.get('RepoType') or not app.get('Builds', []):

View File

@ -730,10 +730,7 @@ def main():
logging.error(_('Build metadata git repo has uncommited changes!'))
sys.exit(1)
# Get all apps...
allapps = metadata.read_metadata()
apps = common.read_app_args(options.appid, allapps, False)
apps = common.read_app_args(options.appid)
processed = []
failed = dict()

View File

@ -891,7 +891,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, allow_vercodes=False, sort_by_time=False):
"""Build a list of App instances for processing.
On top of what read_pkg_args does, this returns the whole app
@ -902,6 +902,7 @@ def read_app_args(appid_versionCode_pairs, allapps, allow_vercodes=False):
"""
vercodes = read_pkg_args(appid_versionCode_pairs, allow_vercodes)
allapps = fdroidserver.metadata.read_metadata(vercodes, sort_by_time)
if not vercodes:
return allapps
@ -911,11 +912,6 @@ def read_app_args(appid_versionCode_pairs, allapps, allow_vercodes=False):
if appid in vercodes:
apps[appid] = app
if len(apps) != len(vercodes):
for p in vercodes:
if p not in allapps:
logging.critical(_("No such package: %s") % p)
raise FDroidException(_("Found invalid appids in arguments"))
if not apps:
raise FDroidException(_("No packages specified"))
@ -2354,6 +2350,8 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
gradlefile = build_gradle
elif os.path.exists(build_gradle_kts):
gradlefile = build_gradle_kts
else:
raise BuildException("No gradle file found")
regsub_file(r'compileSdkVersion[ =]+[0-9]+',
r'compileSdkVersion %s' % n,
gradlefile)

View File

@ -837,7 +837,15 @@ def push_binary_transparency(git_repo_path, git_remote):
origin.set_url(git_remote)
else:
origin = gitrepo.create_remote('origin', git_remote)
origin.push(GIT_BRANCH)
for _i in range(3):
try:
origin.push(GIT_BRANCH)
except git.GitCommandError as e:
logging.error(e)
continue
break
else:
raise FDroidException(_("Pushing to remote server failed!"))
def main():

View File

@ -722,7 +722,13 @@ def check_updates_ucm_http_aum_pattern(app): # noqa: D403
def check_certificate_pinned_binaries(app):
if len(app.get('AllowedAPKSigningKeys')) > 0:
keys = app.get('AllowedAPKSigningKeys')
known_keys = common.config.get('apk_signing_key_block_list', [])
if keys:
if known_keys:
for key in keys:
if key in known_keys:
yield _('Known debug key is used in AllowedAPKSigningKeys: ') + key
return
if app.get('Binaries') is not None:
yield _(
@ -842,9 +848,7 @@ def main():
def lint_metadata(options):
# Get all apps...
allapps = metadata.read_metadata(options.appid)
apps = common.read_app_args(options.appid, allapps, False)
apps = common.read_app_args(options.appid)
anywarns = check_for_unsupported_metadata_files()

View File

@ -551,7 +551,7 @@ def read_srclibs():
srclibs[metadatapath.stem] = parse_yaml_srclib(metadatapath)
def read_metadata(appids={}, sort_by_time=False):
def read_metadata(vercodes={}, sort_by_time=False):
"""Return a list of App instances sorted newest first.
This reads all of the metadata files in a 'data' repository, then
@ -559,7 +559,7 @@ def read_metadata(appids={}, sort_by_time=False):
sorted based on creation time, newest first. Most of the time,
the newer files are the most interesting.
appids is a dict with appids a keys and versionCodes as values.
vercodes is a dict with appids a keys and versionCodes as values.
"""
# Always read the srclibs before the apps, since they can use a srlib as
@ -571,8 +571,7 @@ def read_metadata(appids={}, sort_by_time=False):
for basedir in ('metadata', 'tmp'):
Path(basedir).mkdir(exist_ok=True)
if appids:
vercodes = common.read_pkg_args(appids)
if vercodes:
metadatafiles = common.get_metadata_files(vercodes)
else:
metadatafiles = list(Path('metadata').glob('*.yml')) + list(

View File

@ -268,7 +268,8 @@ def main():
urls[icondir].append(url)
for icondir in icondirs:
_run_wget(os.path.join(basedir, section, icondir), urls[icondir])
if icondir in urls:
_run_wget(os.path.join(basedir, section, icondir), urls[icondir])
if __name__ == "__main__":

View File

@ -82,9 +82,7 @@ def main():
config = common.read_config(options)
# Get all apps...
allapps = metadata.read_metadata(options.appid)
apps = common.read_app_args(options.appid, allapps, False)
apps = common.read_app_args(options.appid)
for appid, app in apps.items():
path = Path(app.metadatapath)

View File

@ -829,10 +829,7 @@ def main():
_get_tool()
return
# Read all app and srclib metadata
allapps = metadata.read_metadata()
apps = common.read_app_args(appids, allapps, True)
apps = common.read_app_args(appids, allow_vercodes=True)
build_dir = 'build'
if not os.path.isdir(build_dir):

View File

@ -701,8 +701,14 @@ class IndexTest(unittest.TestCase):
app = apps[appid]
metadata = index.package_metadata(app, 'repo')
# files
self.assertEqual(36027, metadata['featureGraphic']['en-US']['size'])
self.assertEqual(1413, metadata['icon']['en-US']['size'])
self.assertEqual(
os.path.getsize(f'repo/{appid}/en-US/featureGraphic.png'),
metadata['featureGraphic']['en-US']['size'],
)
self.assertEqual(
os.path.getsize(f'repo/{appid}/en-US/icon.png'),
metadata['icon']['en-US']['size'],
)
# localized strings
self.assertEqual({'en-US': 'title'}, metadata['name'])
self.assertEqual({'en-US': 'video'}, metadata['video'])

View File

@ -438,6 +438,45 @@ class LintTest(unittest.TestCase):
with self.assertRaises(TypeError):
fdroidserver.lint.lint_config('mirrors.yml')
def test_check_certificate_pinned_binaries_empty(self):
fdroidserver.common.config = {}
app = fdroidserver.metadata.App()
app.AllowedAPKSigningKeys = [
'a40da80a59d170caa950cf15c18c454d47a39b26989d8b640ecd745ba71bf5dc'
]
self.assertEqual(
[],
list(fdroidserver.lint.check_certificate_pinned_binaries(app)),
"when the config is empty, any signing key should be allowed",
)
def test_lint_known_debug_keys_no_match(self):
fdroidserver.common.config = {
"apk_signing_key_block_list": "a40da80a59d170caa950cf15c18c454d47a39b26989d8b640ecd745ba71bf5dc"
}
app = fdroidserver.metadata.App()
app.AllowedAPKSigningKeys = [
'2fd4fd5f54babba4bcb21237809bb653361d0d2583c80964ec89b28a26e9539e'
]
self.assertEqual(
[],
list(fdroidserver.lint.check_certificate_pinned_binaries(app)),
"A signing key that does not match one in the config should be allowed",
)
def test_lint_known_debug_keys(self):
fdroidserver.common.config = {
'apk_signing_key_block_list': 'a40da80a59d170caa950cf15c18c454d47a39b26989d8b640ecd745ba71bf5dc'
}
app = fdroidserver.metadata.App()
app.AllowedAPKSigningKeys = [
'a40da80a59d170caa950cf15c18c454d47a39b26989d8b640ecd745ba71bf5dc'
]
for warn in fdroidserver.lint.check_certificate_pinned_binaries(app):
anywarns = True
logging.debug(warn)
self.assertTrue(anywarns)
class LintAntiFeaturesTest(unittest.TestCase):
def setUp(self):

View File

@ -70,7 +70,10 @@ class NightlyTest(unittest.TestCase):
def tearDown(self):
self.tempdir.cleanup()
os.rmdir(self.testroot)
try:
os.rmdir(self.testroot)
except OSError: # other test modules might have left stuff around
pass
def _copy_test_debug_keystore(self):
self.dot_android.mkdir()

View File

@ -14,7 +14,6 @@ import unittest
import uuid
import yaml
import zipfile
import collections
import pathlib
from unittest import mock
from dataclasses import asdict
@ -787,7 +786,7 @@ class Test_main(unittest.TestCase):
self.exit_func.assert_not_called()
self.read_app_args_func.assert_called_once_with(
['com.example.app'], collections.OrderedDict(), True
['com.example.app'], allow_vercodes=True
)
self.scan_binary_func.assert_not_called()

View File

@ -18,6 +18,9 @@
import os
import sys
import tempfile
import unittest
from pathlib import Path
class TmpCwd:
@ -60,3 +63,12 @@ def mkdtemp():
return tempfile.TemporaryDirectory()
else:
return tempfile.TemporaryDirectory(ignore_cleanup_errors=True)
def mkdir_testfiles(localmodule, test):
"""Keep the test files in a labeled test dir for easy reference"""
testroot = Path(localmodule) / '.testfiles'
testroot.mkdir(exist_ok=True)
testdir = testroot / unittest.TestCase.id(test)
testdir.mkdir(exist_ok=True)
return tempfile.mkdtemp(dir=testdir)