Compare commits

...

17 Commits

Author SHA1 Message Date
FestplattenSchnitzel 24fcb61a11 Merge branch 'metadata_improvements' into 'master'
Draft: metadata: Save context managers for opening files

See merge request fdroid/fdroidserver!1357
2024-05-08 12:35:02 +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
Gregor Düster c6171b7814
metadata: Save context managers for opening files
ruamel.yaml also accepts pathlib.Path objects; no need to open a YAML
file ourselves.

Ref.: https://yaml.readthedocs.io/en/latest/basicuse.html

This feature has been added in version 0.15.0 of ruamel.yaml which is
the minimum version supported by fdroidserver already.

Ref.: https://sourceforge.net/p/ruamel-yaml/code/ci/default/tree/CHANGES
2023-09-14 13:48:42 +02:00
Gregor Düster fce23987de
metadata: Simplify metadata path list sorting 2023-09-14 13:37:05 +02:00
11 changed files with 118 additions and 49 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

@ -2354,6 +2354,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 _(

View File

@ -476,28 +476,26 @@ def parse_yaml_srclib(metadatapath):
)
return thisinfo
with metadatapath.open("r", encoding="utf-8") as f:
try:
yaml = ruamel.yaml.YAML(typ='safe')
data = yaml.load(f)
if type(data) is not dict:
if platform.system() == 'Windows':
# Handle symlink on Windows
symlink = metadatapath.parent / metadatapath.read_text(encoding='utf-8')
if symlink.is_file():
with symlink.open("r", encoding="utf-8") as s:
data = yaml.load(s)
if type(data) is not dict:
raise ruamel.yaml.YAMLError(
_('{file} is blank or corrupt!').format(file=metadatapath)
)
except ruamel.yaml.YAMLError as e:
_warn_or_exception(_("Invalid srclib metadata: could not "
"parse '{file}'")
.format(file=metadatapath) + '\n'
+ common.run_yamllint(metadatapath, indent=4),
cause=e)
return thisinfo
try:
yaml = ruamel.yaml.YAML(typ='safe')
data = yaml.load(metadatapath)
if type(data) is not dict:
if platform.system() == 'Windows':
# Handle symlink on Windows
symlink = metadatapath.parent / metadatapath.read_text(encoding='utf-8')
if symlink.is_file():
data = yaml.load(symlink)
if type(data) is not dict:
raise ruamel.yaml.YAMLError(
_('{file} is blank or corrupt!').format(file=metadatapath)
)
except ruamel.yaml.YAMLError as e:
_warn_or_exception(_("Invalid srclib metadata: could not "
"parse '{file}'")
.format(file=metadatapath) + '\n'
+ common.run_yamllint(metadatapath, indent=4),
cause=e)
return thisinfo
for key in data:
if key not in thisinfo:
@ -579,14 +577,11 @@ def read_metadata(appids={}, sort_by_time=False):
Path('.').glob('.fdroid.yml')
)
# Most things want the index alpha sorted for stability
metadatafiles.sort()
if sort_by_time:
entries = ((path.stat().st_mtime, path) for path in metadatafiles)
metadatafiles = []
for _ignored, path in sorted(entries, reverse=True):
metadatafiles.append(path)
else:
# most things want the index alpha sorted for stability
metadatafiles = sorted(metadatafiles)
# Sort on mtime as primary, alpha as secondary (sort stability)
metadatafiles.sort(key=lambda path: path.stat().st_mtime, reverse=True)
for metadatapath in metadatafiles:
appid = metadatapath.stem
@ -650,8 +645,7 @@ def parse_metadata(metadatapath):
app = App()
app.metadatapath = metadatapath.as_posix()
if metadatapath.suffix == '.yml':
with metadatapath.open('r', encoding='utf-8') as mf:
app.update(parse_yaml_metadata(mf))
app.update(parse_yaml_metadata(metadatapath))
else:
_warn_or_exception(
_('Unknown metadata format: {path} (use: *.yml)').format(path=metadatapath)
@ -1268,16 +1262,15 @@ def write_yaml(mf, app):
yaml_app = _app_to_yaml(app)
yaml = ruamel.yaml.YAML()
yaml.indent(mapping=2, sequence=4, offset=2)
yaml.dump(yaml_app, stream=mf)
yaml.dump(yaml_app, mf)
def write_metadata(metadatapath, app):
metadatapath = Path(metadatapath)
if metadatapath.suffix == '.yml':
with metadatapath.open('w') as mf:
return write_yaml(mf, app)
_warn_or_exception(_('Unknown metadata format: %s') % metadatapath)
write_yaml(metadatapath, app)
else:
_warn_or_exception(_('Unknown metadata format: %s') % metadatapath)
def add_metadata_arguments(parser):

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

@ -33,14 +33,15 @@ options = None
def proper_format(app):
s = io.StringIO()
# TODO: currently reading entire file again, should reuse first
# read in metadata.py
cur_content = Path(app.metadatapath).read_text(encoding='utf-8')
content = ''
if Path(app.metadatapath).suffix == '.yml':
metadata.write_yaml(s, app)
content = s.getvalue()
s.close()
with io.StringIO() as s:
metadata.write_yaml(s, app)
content = s.getvalue()
return content == cur_content

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

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