Commit Graph

713 Commits

Author SHA1 Message Date
Simon McVittie
c2c034733e common: Make flatpak_debug2() use the same domain as g_debug()
Now that we are logging `flatpak -v` messages with log level INFO,
and printing INFO messages in the same way as DEBUG, we can reserve
log level DEBUG for `flatpak -v -v` messages. This means we no longer
need a weird secondary debug domain.

There is a very small behaviour change here: G_MESSAGES_DEBUG=flatpak
is now similar to `flatpak -v -v` (previously `flatpak -v`), and
G_MESSAGES_DEBUG=flatpak2 no longer has any effect. This seems more in
line with what would be expected from a GLib-based application.

In flatpak(1) and the system helper, this does not change behaviour
other than that: the same messages are logged by `-v` and by `-v -v`
as before.

In daemons that do not implement `-v -v` (the OCI authenticator, portal
and session helper), it continues to be necessary to use
G_MESSAGES_DEBUG to see flatpak_debug2() messages.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-15 16:45:35 +00:00
Simon McVittie
86c9d7d4c7 daemons, etc.: Use g_info() for messages that are enabled by -v
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-15 16:45:35 +00:00
Simon McVittie
ea584acf20 daemons: Treat g_info() as equivalent to g_debug()
Same as the previous commit, but for anything that runs in the
background.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-14 20:02:35 +00:00
Simon McVittie
435be4da14 meson: Depend on Meson 0.50.0
This sacrifices compatibility with Debian 10 to let us simplify how
tests are set up.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-24 16:12:14 +01:00
Simon McVittie
9eb824f863 Add a Meson build system
Resolves: https://github.com/flatpak/flatpak/issues/2241
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-24 16:12:14 +01:00
Simon McVittie
ad1dc62f26 testlib: Remove local backport of g_assert_no_errno()
libglnx now provides this.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-24 16:10:49 +01:00
Phaedrus Leeds
600e18567c Add a vim modeline and .editorconfig
To make indentation work with less effort. The modeline was copied from
libostree with minor modification and the .editorconfig from GLib.

The advantage of having both a modeline and an editorconfig is we can
work out of the box on more editor setups, and the modeline allows us to
specify the style with a lot more fine grained control.
2022-08-22 19:48:10 -07:00
Simon McVittie
022be7b6db tests: Add valgrind suppression for ostreedev/ostree#2592
This is fixed in v2022.3, but that version missed the boat for Ubuntu
22.04.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-08-16 13:27:04 +02:00
Simon McVittie
4018419b15 revokefs: Use FUSE version 3 if possible
Based on a change contributed by Léo Stefanesco; but instead of
unconditionally using FUSE 3, leave a fallback code path for FUSE 2 for
older distros.

Co-authored-by: Léo Stefanesco <leo.lveb@gmail.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-08-16 13:27:04 +02:00
Phaedrus Leeds
53a0b528bf Add DeploySideloadCollectionID flatpakref/flatpakrepo key
When Flatpak's P2P updates support was replaced with the "sideloading"
implementation in 1.7.1, a new server side repo config key
"deploy-sideload-collection-id" was added which gets set when you pass
"--deploy-sideload-collection-id" to "flatpak build-update-repo", and
has the effect of setting "xa.deploy-collection-id" in the repo metadata
that is pulled by clients, which itself causes a collection id to be set
on the remote for clients using Flatpak >= 1.7.1.

This commit adds an analogous key in flatpakref and flatpakrepo files,
so the collection id can be set when the remote is configured, rather
than later on when the repo metadata is pulled and acted upon. As before
with DeployCollectionID, it has no difference in function compared to
DeployCollectionID or CollectionID and the only difference is which
Flatpak versions are affected.

It would've been better if this were added in 1.7.1 when the sideload
support was added, but alas here we are.

(Also update the docs and unit tests)
2022-08-16 10:37:36 +02:00
Simon McVittie
0c5e4abbea try-syscall: Cope with old glibc without PR_SET_CHILD_SUBREAPER defined
Originally part of containers/bubblewrap#496 in bubblewrap.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-27 10:02:25 -07:00
Simon McVittie
836b0fb604 try-syscall: Use compiler-predefined macros to detect mips ABI
_MIPS_SIM_ABI32 etc. are defined by Linux <asm/sgidefs.h>, which is
included by glibc <sys/syscall.h> (which defers to Linux headers to
get syscall numbers), but not by musl <sys/syscall.h>.

_ABIO32 etc. are predefined by the compiler, so they are always
available, regardless of libc. References:

https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=27d54b2a6c18ef1ae50f1a5b432d590438445b90
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=0ea339ea4d9c3e04ae17da6bf389617eb0251e57

Originally containers/bubblewrap#492 in bubblewrap.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-27 10:02:25 -07:00
Phaedrus Leeds
6e5fb9dbc7 tests: Skip test-history.sh without libsystemd 2022-06-24 15:11:41 -07:00
Alexander Larsson
0c6bb85cb6 flatpak-http: Restructure the soup http implementation
This miniminzes the soup implementation by moving it out of the
highlevel multiple-retry entry points and simplifying the
lower level part to use only one shared helper.

This will also make it easier to replace the soup specific
parts.
2022-06-16 13:49:45 +02:00
Alexander Larsson
0de4800c3b tests: Don't fail if OSTREE_DEBUG_HTTP is set in the test env 2022-06-16 13:49:45 +02:00
Alexander Larsson
1c9e65d5e4 Move all use of soup APIs into flatpak-utils-http
This will allow us to make the soup dependency optional.
2022-06-16 13:49:45 +02:00
Alexander Larsson
b1083a4c41 http utils: Make a generic FlatpakHttpSession instead of SoupSession
Its still just a SoupSession, but now the implementation is more
centralized and can be something else down the line.
2022-06-16 13:49:45 +02:00
Phaedrus Leeds
d764202ce7 transaction: Add new API for getting an op by ref
This will be useful in gnome-software's flatpak plugin, which currently
iterates over the operations a few times, and it will be useful
internally as well.
2022-06-15 16:44:17 -07:00
Simon McVittie
92ecb7d2d2 libtest.sh: Optionally be more careful what we print on stdout
Meson's TAP parser is more strict than the one in Automake, and will
not accept and ignore arbitrary output.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-05-03 13:54:23 +02:00
Simon McVittie
a6a1e37a8c tests: Avoid printing arbitrary text to stdout
Meson's TAP parser won't accept this, unlike Automake's. At the moment
libtest.sh directs stderr to stdout anyway, so there is no practical
effect for this change, but a subsequent commit will remove that merging.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-05-03 13:54:23 +02:00
Simon McVittie
c652d538eb tests: Redirect stdout to stderr for flatpak_installation_launch
This avoids polluting stdout with the output of the launched app,
which would corrupt the test's TAP output. With Autotools, we get away
with it, because Automake's TAP parser is permissive, but Meson's TAP
parser is more strict.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-05-03 13:54:23 +02:00
Simon McVittie
0728b97e22 test-history: Make it easier to debug on failure
If `flatpak history` fails, let's show the log file before failing
the test.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-05-03 13:54:23 +02:00
Simon McVittie
3e8319c9b4 tests: Factor out generation of test runtime into a script
This will make it easier to invoke from Meson.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-05-03 13:54:23 +02:00
Simon McVittie
1082201be9 tests/update-test-matrix: Move into a standalone script
This will allow the same script to be used to generate
Makefile-test-matrix.am.inc and its Meson equivalent.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-05-03 13:54:23 +02:00
Simon McVittie
f090f1a1f3 tests: Wrap EXTRA_DIST, one file per line
This will reduce conflicts when adding more files.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-05-03 13:54:23 +02:00
Phaedrus Leeds
45d86effce tests: Remove a pointless test
Typo correction has nothing to do with --no-pull or --no-deploy so it
doesn't make sense to test them together when we already test each
separately.

[smcv: Resolve conflict with #4858]
2022-04-23 16:12:53 +01:00
Phaedrus Leeds
c7d262b375 app: Disable fuzzy matching if not on a tty
As discussed in #4848, this disables fuzzy matching entirely if stdin or
stdout is not a tty, meaning that something like "flatpak install
firefox" would be treated as incorrect syntax, since this syntax is
intended for interactive CLI use. Even before this commit, "flatpak
install firefox" would error out if run without a tty, since we don't
automatically choose a matching app ID even if there is only one match.
However "flatpak install -y firefox" could work before, but won't any
more. People should be specifying the full app ID in any context other
than a tty.

This commit also introduces a new env var so the unit tests can continue
to check the fuzzy matching behavior, despite them being run without a
tty.
2022-04-21 20:53:46 +01:00
Phaedrus Leeds
5acb4ee7e4 app: Disable fuzzy ref matching when id has a period
As discussed in #4848, this disables fuzzy matching when the string
given has a period in it. So for example "flatpak install org.mozilla"
would not offer "org.mozilla.firefox" even though the string given is a
substring of the app ID. This is desirable because it helps ensure fuzzy
matching is only used when the user intended to use it.

As with the previous commit that fixed #4829, this does technically
break backwards compatibility, but only in an interface intended for
interactive use by a human, not an interface that's used
programmatically, so it seems okay.
2022-04-21 20:53:46 +01:00
Phaedrus Leeds
23926b7090 app: Disable fuzzy ref matching when id has a slash
Fixes https://github.com/flatpak/flatpak/issues/4829
2022-04-21 20:53:46 +01:00
Simon McVittie
c68f31d86a build: Consistently include libglnx header as "libglnx.h"
Recent Meson versions have warnings if you add the subprojects
directory as an include path, because the way Meson wants to consume
subprojects is by the subproject's build system producing a Meson
dependency object that encapsulates its include directory. Flatpak
doesn't have a Meson build system yet, but I'm working on that.

libglnx seems to be set up to have the libglnx directory be its include
path instead: for example, ostree (by the author of libglnx) already
uses "libglnx.h" or <libglnx.h> everywhere. Do the same here.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-11 10:32:34 +02:00
Simon McVittie
597abdc585 tests: Don't install tap-driver.sh in the installed-tests
This is specifically for running build-time tests in the Autotools build
system, and is not used when running installed-tests.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-03-03 12:33:37 -08:00
Simon McVittie
0deb80efa8 test-history: Skip test if we cannot read from the Journal
In some OS configurations, unprivileged users cannot read back messages
that they have written to the system log. This test cannot succeed if that
happens, so skip it.

In particular, if the Journal is only in-memory rather than persisted
to disk (as it was by default in Debian 10), then there are no per-user
Journal files, only a single system-wide Journal which requires privileges
to read.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Fixes: 8b05f6b3 "Add a unit test for the history command"
2022-02-20 19:01:33 -06:00
Phaedrus Leeds
5d9d03d875 tests: test search command
This is basically what we already have in test-oci-registry.sh but for
the non-OCI case.
2022-02-17 08:29:20 -06:00
Philip Withnall
9c059def69 app: Port to libappstream
libappstream-glib is mostly unmaintained, and libappstream is more
actively developed (and up to date with the AppStream specification).

Port from libappstream-glib to libappstream. Handily, a lot of the APIs
are exactly the same. The main changes are:
 * `AsApp` → `AsComponent`
 * `AsStore` → `AsMetadata`

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

(Mostly done by Philip, then Phaedrus finished this)
2022-02-17 08:29:20 -06:00
Simon McVittie
69f347e58a run: Support parsing non-local X11 addresses
We still don't support rewriting XAUTHORITY for these, but at least we
understand them now.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-02-11 15:25:50 +01:00
Simon McVittie
c3395a0e83 run: Treat DISPLAY=unix:42 the same as :42
xauth and xcb both treat this as a request to use AF_UNIX.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-02-11 15:25:50 +01:00
Simon McVittie
18db8e8713 run: Factor out parsing X11 displays into a helper function
This allows it to be unit-tested.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-02-11 15:25:50 +01:00
Simon McVittie
1def449850 tests/try-syscall.c: Add a note about keeping this in sync with bubblewrap
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-01-31 17:13:31 +00:00
Simon McVittie
4735e3ea90 tests: Use type -P in preference to which
which(1) is neither standardized by POSIX nor built-in to bash, and has
different implementations and behaviour on different distributions.
command -v is standardized by POSIX, but it won't return the path to an
executable if the same command is available as a shell builtin, so it
isn't necessarily suitable here either.

The Flatpak test suite uses bash scripts rather than POSIX shell scripts,
so we can safely make use of bash-specific options for builtins, and
in particular type -P, which has the semantics we want here: search PATH,
even if there is a shell builtin of the same name.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-01-25 10:07:03 +01:00
Simon McVittie
4aa70d2d72 test-override: Exercise --nofilesystem=host:reset
Signed-off-by: Simon McVittie <smcv@collabora.com>
Co-authored-by: Alexander Larsson <alexl@redhat.com>
2022-01-18 15:30:12 +00:00
Simon McVittie
fab0f8ed7c test-context: Exercise some corner cases for merging filesystems
Signed-off-by: Simon McVittie <smcv@collabora.com>
Co-authored-by: Alexander Larsson <alexl@redhat.com>
2022-01-18 15:30:12 +00:00
Simon McVittie
f3d12dc793 test-exports: Exercise host:reset and related filesystem tokens
Signed-off-by: Simon McVittie <smcv@collabora.com>
Co-authored-by: Alexander Larsson <alexl@redhat.com>
2022-01-18 15:30:12 +00:00
Simon McVittie
5709f1aaed context: Introduce new --nofilesystem=host:reset
This reintroduces the special case that existed in Flatpak 1.12.3, but
under a different name, so that it will be backwards-compatible. With
this change, flatpak-builder will be able to resolve CVE-2022-21682 by
using --filesystem=host:reset.

We want to implement this as a suffix rather than as a new keyword,
because unknown suffixes are ignored with a warning, rather than causing
a fatal error. This means that the new version of flatpak-builder will
be able to run against older versions of flatpak: it will still be
vulnerable to CVE-2022-21682 in that situation, but at least it will run.

Co-authored-by: Alexander Larsson <alexl@redhat.com>
2022-01-18 15:30:12 +00:00
Simon McVittie
ab0169ee39 test-override: Assert that --nofilesystem with suffix yields a warning
This was added as part of implementing the :reset suffix.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-01-18 15:30:12 +00:00
Simon McVittie
813e1f0b3b test-override: Assert pre-1.12.3 behaviour of --nofilesystem=home, host
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-01-18 15:30:12 +00:00
Simon McVittie
8a44df04c8 test-override: Assert that unimplemented suffix is ignored with a warning
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-01-17 11:39:34 +01:00
Simon McVittie
4e3d1d8b7b test-override: Assert that only the expected term is negated
We weren't distinguishing here between overrides that should have been
negated (xdg-documents) and overrides that should not have been negated
(everything else).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-01-17 11:39:34 +01:00
Phaedrus Leeds
54ec1a482d Add test for metadata validation
This tests for invalid metadata, missing xa.metadata and mismatched
values in xa.metadata and the real metadata, including the embedded
null leading to the hidden permissions of CVE-2021-43860.
2022-01-12 19:48:16 +01:00
Phaedrus Leeds
3c63cac8f9 Export to share/metainfo not share/appdata
Read metainfo files from both share/appdata and share/metainfo to
support new and old versions of flatpak-builder
(https://github.com/flatpak/flatpak-builder/pull/441) but only export to
the new path.

Fixes https://github.com/flatpak/flatpak/issues/4599
2022-01-10 09:55:26 +01:00
Phaedrus Leeds
45c7f5071c Add a test for the repair command
This should ensure that https://github.com/flatpak/flatpak/issues/4618
stays fixed.
2022-01-10 09:36:49 +01:00