Skip to content

Commit

Permalink
appstream: Require that appstream IDs match $FLATPAK_ID
Browse files Browse the repository at this point in the history
For historical reasons flatpak-builder passes ``$FLATPAK_ID.desktop`
as a valid component ID to appstreamcli. This mismatch creates issues
like the one described in flatpak/flatpak#5752
and flathub/flathub#4222

So require that both match and avoid new submissions leaking in with a
mismatch.
  • Loading branch information
bbhtt committed Mar 31, 2024
1 parent 9d6da33 commit 714ab32
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 1 deletion.
5 changes: 5 additions & 0 deletions flatpak_builder_lint/appstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def components(path: str) -> list:
return list(components)


def appstream_id(path: str) -> Optional[str]:
aps_cid = components(path)[0].xpath("id/text()")[0]
return str(aps_cid)


def is_developer_name_present(path: str) -> bool:
developer_name = components(path)[0].xpath("developer/name")
legacy_developer_name = components(path)[0].xpath("developer_name")
Expand Down
4 changes: 4 additions & 0 deletions flatpak_builder_lint/checks/metainfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def _validate(self, path: str, appid: str) -> None:
if not appstream.is_valid_component_type(appstream_path):
self.errors.add("appstream-unsupported-component-type")

aps_cid = appstream.appstream_id(appstream_path)
if aps_cid != appid:
self.errors.add("appstream-id-mismatch-flatpak-id")

if appstream.component_type(appstream_path) not in (
"desktop",
"desktop-application",
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop-application">
<id>org.flathub.appstream-cid-mismatch-flatpak-id.desktop</id>
<name>Foo Foo Foo Foo Foo Foo Foo Foo Foo Foo</name>
<summary>Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar.</summary>
<url type="homepage">https://flathub.org</url>
<description>
<p>This is an example</p>
</description>
<metadata_license>CC0-1.0</metadata_license>
<launchable type="desktop-id">org.flathub.appstream-cid-mismatch-flatpak-id.desktop</launchable>
<icon type="cached" width="128" height="128">com.github.flathub.appdata-quality.png</icon>
<categories>
<category>Network</category>
</categories>
<provides>
<id>com.github.flathub.appdata-quality.desktop</id>
</provides>
<screenshots>
<screenshot type="default">
<image type="source">https://upload.wikimedia.org/wikipedia/commons/a/af/Tux.png</image>
</screenshot>
<screenshot>
<image type="source">https://dl.flathub.org/assets/badges/flathub-badge-en.png</image>
</screenshot>
<screenshot>
<caption>Foo Foo Foo</caption>
<image type="source">https://dl.flathub.org/assets/badges/flathub-badge-i-en.png</image>
</screenshot>
</screenshots>
<content_rating type="oars-1.1"/>
</component>
2 changes: 2 additions & 0 deletions tests/builddir/appstream-cid-mismatch-flatpak-id/metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Application]
name=org.flathub.appstream-cid-mismatch-flatpak-id
10 changes: 9 additions & 1 deletion tests/test_builddir.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ def test_builddir_quality_guidelines() -> None:
assert e in found_errors
# If present, it means a metainfo file that was validating
# correctly broke and that should be fixed
assert "appstream-failed-validation" not in found_errors
not_founds = {"appstream-failed-validation" "appstream-id-mismatch-flatpak-id"}
for e in not_founds:
assert e not in found_errors


def test_builddir_broken_icon() -> None:
Expand Down Expand Up @@ -189,3 +191,9 @@ def test_min_success_metadata() -> None:
# CLI applications are allowed to have no finish-args with exceptions
accepted = {"finish-args-not-defined"}
assert len(found_errors - accepted) == 0


def test_builddir_aps_cid_mismatch_flatpak_id() -> None:
ret = run_checks("tests/builddir/appstream-cid-mismatch-flatpak-id")
found_errors = set(ret["errors"])
assert "appstream-id-mismatch-flatpak-id" in found_errors

0 comments on commit 714ab32

Please sign in to comment.