Commit Graph

653 Commits

Author SHA1 Message Date
Phaedrus Leeds
49d9052d22 Ensure refs are updated from their origin
It can happen that a related ref is installed from a different remote
than the thing it's related to. We always want to update things from
their origin remote. However as of now FlatpakTransaction resolves the
commit of a related ref to the one available from the main ref origin,
and later sets the remote for the operation to the installed origin (see
commit 6793d90b8). In case there is a newer commit in the main ref
origin than the installed origin, this leads to an update operation
being erroneously created, only to then error out with an HTTP 404
error, because the commit from the main ref origin is being pulled from
the installed ref origin. For specific steps to reproduce see
https://github.com/flatpak/flatpak/issues/3128#issuecomment-948948040

So, ensure that when a FLATPAK_TRANSACTION_OPERATION_INSTALL_OR_UPDATE
operation is created for something that's installed, whether it's a
related ref or something else, the remote used is always the origin. And
ensure that the remote is set correctly before the stage where the op is
resolved to a commit, to avoid the situation described above. This is
essentially a re-implementation of the fix in commit 6793d90b8.

Also, add a unit test for this behavior.

This commit also makes a few changes to documentation to make it clear
that this related-ref-different-origin situation is possible.

Fixes #3128
2021-11-15 11:18:58 +01:00
Simon McVittie
e2b36d3f1c tests: Assert that XDG_foo_HOME directories are all created
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-11-15 11:07:57 +01:00
Simon McVittie
a3464bebb7 tests: Check that we handle XDG_foo_HOME as intended
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-11-15 11:07:57 +01:00
Lionir
0fda062c96 Add XDG_STATE_HOME and HOST_XDG_STATE_HOME env variables
This gives new support for the new XDG_STATE_HOME addition to XDG_BASE_DIRS
which allows applications to use this without breaking because they would
assume $HOME/.local/state which may be unavailable to the flatpak

This adds it as .local/state as to make --persist=.local/state the same behaviour
as in new flatpak. This in turn means that the transition should be seamless between
old and new flatpak.

This also has the benefit of working if the application doesn't follow XDG spec thanks
to --persist=.local/state.

This fixes https://github.com/flatpak/flatpak/issues/4477

[smcv: Don't call nonexistent g_get_user_state_dir(); fix a reference
to XDG_STATE_DIR]
2021-11-15 11:07:57 +01:00
Phaedrus Leeds
1a95a1ec90 tests: Drop some unneeded CFLAGS/LDADD 2021-11-09 11:33:10 -08:00
Philip Withnall
cd2f796ba9 Merge pull request #4487 from flatpak/dont-mask-noenumerate-main-refs
dir: Don't mask the main ref of a noenumerate remote
2021-11-02 11:14:37 +00:00
Phaedrus Leeds
89876b1a8d test-update-portal: Fix warn_unused_result warning 2021-10-27 10:58:38 +01:00
Simon McVittie
7c5aec474c tests: Add basic test coverage for our seccomp filters
In particular, this checks that CVE-2017-5226, CVE-2019-10063 and
CVE-2021-41133 are still prevented.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-10-25 23:33:46 +01:00
Simon McVittie
4ce251882c tests: Add try-syscall helper
This exercises various syscalls. It's heavily based on the one from
<https://github.com/containers/bubblewrap/pull/459>, but with the
addition of a mode to output the numeric values of various expected
errno codes, which are not otherwise available to shell scripts.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-10-25 23:32:00 +01:00
Phaedrus Leeds
2ae3631fc2 Merge pull request #4504 from smcv/regen-test-matrix
tests: Generate Makefile-test-matrix.am.inc in $(srcdir)
2021-10-22 18:37:05 -07:00
Phaedrus Leeds
df3d85e753 testlibrary: Add test for remote nodeps option
Always good to expand the test coverage
2021-10-21 11:32:05 -07:00
Phaedrus Leeds
6de22f0e62 Include extensions in listing origin remote refs
In a recent commit I changed flatpak_dir_list_remote_refs() to make main
refs (xa.main-ref) visible for noenumerate remotes (xa.noenumerate),
meaning that an origin remote created for a flatpakref file can be used
to get information about the ref from the file even before it is
installed. This commit extends that work to include extensions of the
main ref, and updates the unit test to check for this. The reasoning is
that if GNOME Software wants to show the user information about, say,
VLC from a flatpakref file before installing it, Software would want to
also show the available plugins so the user can decide if they want to
install those as well. I haven't checked if Software actually does that;
I'm only focusing on making libflatpak do the right thing.
2021-10-21 11:32:05 -07:00
Phaedrus Leeds
7f3556d92c Fix implementation of xa.noenumerate remote option
Currently the xa.noenumerate option on a remote is documented as causing
the remote not to be used when presenting available apps/runtimes or
when searching for dependencies. The idea is that the remote is only
used for providing updates for things installed from it, and this
functionality is used when creating an origin remote for something
installed via a flatpakref file.

However, the implementation of this in flatpak_dir_list_remote_refs() is
buggy. It returns an empty set of refs even if something is both locally
installed and available from the remote. This is because it is using
hash table comparisons of FlatpkDecomposed objects (via
flatpak_decomposed_hash()) which take into account both the ref (or
refspec) and the collection ID, and the local refs' FlatpakDecomposed
objects are created from a refspec whereas the remote refs'
FlatpakDecomposed objects are created from a ref alone. We could fix
this by having them both use refspecs, but it is better to use a
collection-ref tuple for the following reasons:
(1) Changing flatpak_dir_list_all_remote_refs() to use a refspec to
create the FlatpakDecomposed objects would be a breaking change for the
other users of that function.
(2) Both the local and remote refs are from the same remote so we don't
need to use the remote name to disambiguate them, even if no collection
ID is configured.
(3) The whole point of collection IDs is to make refs uniquely
identifiable, so we're using them for the intended purpose.

In addition to fixing this bug, this commit adds a unit test in
testlibrary.c so it stays fixed.
2021-10-21 11:32:05 -07:00
Phaedrus Leeds
ef05925700 dir: Don't mask the main ref of a noenumerate remote
When we create origin remotes for apps installed via .flatpakref files,
we set xa.noenumerate=true and
xa.main-ref=app/com.example.App/arch/branch so that the remote is only
used for the app it was intended for. This is implemented in
flatpak_dir_list_remote_refs() by only listing refs in the remote which
are already installed. This works fine after the ref is installed but in
the short timespan between when the origin remote is created and the app
is installed from it, it means that the remote appears as empty.

The use case where I ran into this is in attempting to use
flatpak_installation_fetch_remote_ref_sync() in the gnome-software
flatpak plugin, in the handling of flatpakref files, which is intended
to just display information to the user and let them decide whether to
install the app. But I was not able to create a FlatpakRemoteRef due to
the behavior described above; see #4453 for more details.

So, change the behavior so that the main ref for an origin remote is
visible even before it is installed. This technically could be a
breaking change for some consumer of libflatpak but that seems very
unlikely, and the new behavior makes more sense.

Also add a unit test for this behavior.
2021-10-21 11:32:05 -07:00
Phaedrus Leeds
dd48e78652 testlibrary: Make remote existence assertions more friendly
Currently the output produced when assert_remote_in_installation() or
assert_remote_not_in_installation() fails is not helpful: it doesn't
mention the remote name or where the assertion was called from. Fix
those problems by rewriting it as a #define.
2021-10-21 18:14:21 +01:00
Phaedrus Leeds
f753dd214c testlibrary: Add missing cleanup
It's easier to reason about the tests if they don't leave state behind.
2021-10-21 18:14:21 +01:00
Phaedrus Leeds
8f85f77ff9 testlibrary: Tweak some helper functions
This will make the next commit simpler, and in my opinion this makes the
code more readable.
2021-10-21 18:14:21 +01:00
Phaedrus Leeds
0258fc82bb testlibrary: Don't use g_assert()
Per the documentation, g_assert_null() is meant for unit tests.
2021-10-21 18:14:21 +01:00
Simon McVittie
647c51380c tests: Generate Makefile-test-matrix.am.inc in $(srcdir)
Files that are generated manually by a maintainer and committed to git
should be in the srcdir, not the builddir.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-10-21 17:44:44 +01:00
Jan Tojnar
96dbe28cfa tests: Allow FLATPAK_BINARY=flatpak for exports
a99b748931 introduced an environment variable for changing the flatpak path for exports.
On NixOS, we do not have a stable path we could use so we used to patch Flatpak to use `flatpak` program from `PATH`.
With the recent change, we drop our downstream patch in favour of setting the environment variable to `flatpak` but the tests do not expect that.

This is the test part of our former downstream patch so that tests can pass with exports using `flatpak` instead of an absolute path.
It still expects the binary path to end with `flatpak` so arbitrary `$FLATPAK_BINARY` will not work but we do not pass the environment variable to tests so we cannot do much better.
2021-10-17 20:49:22 +02:00
Phaedrus Leeds
b098191252 Fix capitalization of "false" in flatpakref keyfiles
g_key_file_get_boolean() only accepts lower case "true" and "false", so
correct some instances of "False" in key files. This makes no functional
difference as long as the error pointer isn't checked since
g_key_file_get_boolean() also returns false when it can't parse the
value as a boolean. But it still seems good to be correct, and someone
could interpret the existence of "IsRuntime=False" as implying that
"IsRuntime=True" will work, which it doesn't.
2021-10-15 00:38:15 +01:00
Alexander Larsson
9914dff925 tests: Fix test-sideload.sh if ostree is built with curl backend
The soup backend and the curl backend give slightly different error
messages, so we need to tweak the 404 assert check to match both.
2021-10-08 12:05:22 +02:00
Richard Maw
a96e9af37f Handle /var/tmp mounts when it is a symlink
In Yocto systems /var/tmp is a symlink to /var/volatile/tmp
because in its implementation of read-only rootfs /var is read-only
so /var/volatile is mounted as a tmpfs
and a subset of the paths point into it.

This would result in flatpak emitting mount arguments of
`--symlink ../var/volatile/tmp /var/tmp --bind /var/volatile/tmp /var/volatile/tmp`
which fails because flatpak has already added `--dir /var/tmp`
and the call to symlink fails with EEXIST.

This is fixed by blacklisting /var/tmp from symlink exports
in the same way /tmp is, so the bind is emitted as
`--bind /var/tmp /var/tmp`, which results in /var/volatile/tmp
being mounted into /var/tmp.
2021-09-23 09:57:33 +02:00
Simon McVittie
7bf6ecfaa2 tests: Don't reset XDG_RUNTIME_DIR locally
If we do, it interferes with xdg-dbus-proxy, causing test failure under
some circumstances: the test passes on a development system, but fails
when run on a qemu virtual machine in Debian's autopkgtest framework.

Fixes: 6e5b02e2 "run: Don't let XDG_RUNTIME_DIR from user override the value we set"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-26 21:40:16 +01:00
Simon McVittie
21a5fe5ff1 libtest: Make sure ldconfig and capsh are in the PATH
This gives us better test coverage on Debian derivatives.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-26 12:55:46 +01:00
a1346054
844ad9ad79 fix spelling
Signed-off-by: a1346054 <36859588+a1346054@users.noreply.github.com>
2021-08-23 12:19:03 +02:00
Simon McVittie
6e5b02e2d4 run: Don't let XDG_RUNTIME_DIR from user override the value we set
We use `bwrap --setenv XDG_RUNTIME_DIR` to set it to `/run/user/UID`,
regardless of what it is on the host system, but the changes made
to resolve CVE-2021-21261 unintentionally broke this by overwriting it
with the user's XDG_RUNTIME_DIR.

In practice this worked for most people, who either have
XDG_RUNTIME_DIR set to the same value we use (which is the conventional
setup from systemd-logind and elogind), or entirely unset (if they do not
have systemd-logind or elogind). However, it broke Wayland and other
XDG_RUNTIME_DIR-based protocols for people who intentionally set up an
XDG_RUNTIME_DIR that is different.

Fixes: 6d1773d2 "run: Convert all environment variables into bwrap arguments"
Resolves: https://github.com/flatpak/flatpak/issues/4372
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-20 15:28:58 +02:00
Simon McVittie
c392e5adf6 tests: Exercise attempting to export a nonexistent directory
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 08:37:25 +02:00
Simon McVittie
0f755d9fa8 tests: Exercise refusal to export a self-recursive symlink
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 08:37:25 +02:00
Simon McVittie
1297127eeb tests: Exercise exporting a directory whose parent is a symlink
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 08:37:25 +02:00
Simon McVittie
a5047e7f8e tests: Test the special case for --filesystem=/tmp if /tmp is a symlink
If /tmp is a symlink, we mount the target directory on /tmp instead of
replicating the symlink, so that it will not interfere with "--dir /tmp".

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 08:37:25 +02:00
Simon McVittie
2a61cfee5b tests: Exercise failure to export a non-absolute path
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 08:37:25 +02:00
Simon McVittie
7fbb165c81 tests: Exercise failure to export a broken autofs
To achieve this, add a flag to FlatpakExports to make it fake a broken
autofs.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 08:37:25 +02:00
Simon McVittie
f59d28b4cf tests: Add a skeleton for testing unusual/corner-case situations
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 08:37:25 +02:00
Simon McVittie
4c8264fc0e tests: Add test coverage for a mock Fedora-like system
In particular this tests commit 3aaea7d2 "Expose /var/usrlocal if
"--filesystem=host" is specified" and checks that /var/usrlocal is
counted as part of --filesystem=host-usr.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 08:37:25 +02:00
Simon McVittie
0f4296b5b5 build: Don't include gdbus-codegen-generated files in tarball
To be excluded from tarball releases, generated files need to be in
nodist_ lists of sources every time they appear.

Fixes: 412c1577 "portal: Add some test coverage"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-06-17 09:39:21 +01:00
Simon McVittie
412c15772f portal: Add some test coverage
This exercises Spawn() and reproduces #4286.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-05-25 11:11:03 +02:00
Simon McVittie
0a44aaff8d tests: Test environment block parsing
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-05-25 11:11:03 +02:00
Simon McVittie
3d5725f9d3 testcommon: Use unusual architectures where it doesn't matter
If we use x86_64 and i386 in places where any architecture would do,
it's harder to recognise whether the test is assuming every machine
is x86 and would fail elsewhere (e.g. as fixed in #4142). When just
parsing abstract strings where any syntactically valid architecture
would do, let's use rare/niche architectures that none of the maintainers
are running on, so that hard-coding x86_64 or i386 stands out more.

I've used mips64 and m68k because they happen to be the same length as
x86_64 and i386, avoiding re-indentation.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-05-25 10:31:38 +02:00
Philip Withnall
d5daaa537d tests: Fix test-summaries.sh when running tests as root
If the tests are run as root, the system helper is not used even when
commands are run with `--system`. This means a different cache path is
used (see `_flatpak_dir_ensure_repo()`). The tests did not accommodate
for that.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-05-17 10:00:33 +02:00
Alexander Larsson
283a3b93a5 tests: Add test for the flatpak prune implementation 2021-04-26 10:30:14 +02:00
Simon McVittie
686af7d3b8 test-instance: Add more assertions
scan-build points out that bytes isn't read after it is assigned. While
this is not actually true (scan-build doesn't understand
__attribute__((__cleanup__)), which frees bytes), it's true that we
should ideally have an assertion here.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-19 09:09:04 +02:00
Simon McVittie
bd5c2762cf testcommon: Assert that parse_datetime succeeds
scan-build detected that ret was written but never read.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-19 09:09:04 +02:00
Simon McVittie
3a85ceecfc testlibrary: Fix an assertion
scan-build detected that res was written but never read. Presumably
the use of ref here (carried over from the previous test) is a
copy/paste error.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-19 09:09:04 +02:00
Simon McVittie
c26a48a9aa Fix various unused variables detected by scan-build
scan-build has a lot of false positives for this codebase because it
doesn't understand __attribute__((__cleanup__)) or GLib's GError
convention, but it seems to have been right about these.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-19 09:09:04 +02:00
Simon McVittie
cb47d83b72 run: Add option to share /dev/shm between instances of an app-ID
Similar to /tmp, applications might well use /dev/shm as an IPC
rendezvous between instances, which wouldn't have worked without
--device=shm until now.

Because /dev/shm has specific characteristics (in particular it's
meant to always be a tmpfs), we offload the actual storage into a
subdirectory of the real /dev/shm. Because /dev/shm is a shared
directory between all uids, we have to be extra-careful how we
do this, which is why the test coverage here is important.

This is done on an opt-in basis because of its extra complexity.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-16 08:57:20 +02:00
Simon McVittie
70a3e44fb5 portal: Define constants for the D-Bus names and path
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-15 18:05:16 +02:00
Simon McVittie
b65b3f6ead run: Share /tmp between all instances of an app-ID
This allows apps that use /tmp as an IPC rendezvous point, such as those
that embed Chromium-derived browsers, to communicate between instances;
this would not previously have worked without --filesystem=/tmp, which
is a significant weakening of the sandbox.

It also allows /tmp to be shared with subsandboxes (if they are not
sandboxed more strictly).

The temporary directory is actually created in XDG_RUNTIME_DIR,
to avoid it becoming visible to unrelated apps that happen to have
--filesystem=/tmp.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-15 18:00:47 +02:00
Simon McVittie
574ff50cf4 common: Separate creation of FlatpakExports from append_bwrap_filesystem
A subsequent commit will need to look at the FlatpakExports before
we are ready to append their arguments to the FlatpakBwrap.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-15 18:00:47 +02:00
Simon McVittie
712efd3156 instance: Create and destroy per-app-ID subdirs of XRD/.flatpak
If we want to provide a per-app-ID XDG_RUNTIME_DIR (#4120) or a
per-app-ID /tmp or /dev/shm (#4093) then we'll need somewhere to put
them. Unlike $XDG_RUNTIME_DIR/app/$FLATPAK_ID, this should be somewhere
that is *not* accessible to the app, so that we can trust its contents.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-15 18:00:47 +02:00