Commit Graph

628 Commits

Author SHA1 Message Date
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
Simon McVittie
c8a4248eb4 test-instance: Provide app-IDs for our mock apps
Previously, this only had to consider two situations: either an instance
is still running (alive), or it is not (dead).

When we start sharing directories between all instances of a particular
app-ID (#4120, #4093), we'll also need to consider whether instances
share an app-ID, expanding the test to three situations: either an
instance is still running (alive), or it has exited but shares its
app-ID with a different instance that is still running (the app is
alive but the instance is dead, abbreviated here as alive_dead),
or it has exited and does not share its app-ID with any running
instances (dead).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-15 18:00:47 +02:00
Simon McVittie
3787db00e0 utils: Add flatpak_str_is_integer()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-15 18:00:47 +02:00
Simon McVittie
d8a8ac2edb tests: Test flatpak_quote_argv and flatpak_argument_needs_quoting
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-13 14:14:10 +02:00
Simon McVittie
e9c217adc1 test-basic: Don't fail if head -2 exits before flatpak does
The output might be written to the pipe by `flatpak --help` and/or read
from the pipe by `head -2` in more than one batch. If `head -2` reads
the first two lines before `flatpak --help` has written everything, it
will exit, causing the pipe to have no process at the read end. This
results in `flatpak --help` being killed by `SIGPIPE` next time it tries
to write to the pipe, because it has not opted out of this behaviour
(as shell tools usually shouldn't).

We're running under `set -o pipefail`, so this causes a nonzero exit
status that makes the test fail. Worse, this failure is intermittent,
because `head -2` *usually* doesn't exit until `flatpak --help` has
already written out everything it is going to write - it depends on
the precise behaviour of read(), write() and kernel scheduling.

We know that `flatpak --help` output is not *that* long, so it's OK
for `flatpak --help` not to be terminated early: we can send it all
into an intermediate file, and then run `head` on the file.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-12 11:07:10 +02:00
Simon McVittie
494feacb77 run: Sort environment before serializing it into bwrap arguments
This has no practical effect (assuming environment variables are unique),
but it makes it easier to find an environment variable of interest
in a very long bwrap command-line.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-06 16:19:09 +02:00
Simon McVittie
f2b2a12f56 tests: Add basic test coverage for GC'ing unused instance directories
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-06 11:53:23 +02:00
Simon McVittie
6b2cb74a94 tests: Improve error handling for isolated directory setup
If these simple libc function wrappers fail during setup, we want to
crash out.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-06 11:53:23 +02:00
Simon McVittie
a5960d4e7b tests: Factor out test setup from test-exports
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-06 11:53:23 +02:00
Arnaud Ferraris
6996580bb8 tests: web-server: fix an issue with the web server cache
On a decently fast system, some files may be fetched, modified and then
fetched again within the same second. In that case, the web server
replies with a code 304 ("Not modified") to the 2nd query, causing some
tests to fail.

This commit forces the web server to ignore `If-Modified-Since` HTTP
headers, effectively disabling caching in order to mitigate the problem.
2021-03-11 13:31:17 +01:00
Simon McVittie
ba381ae936 tests: Remove hard-coded references to x86_64
Distributions run these tests on other architectures, but hard-coding
x86_64 to look for in output dooms that to failure.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-03-10 10:35:18 +01:00
Phaedrus Leeds
7224809bc1 testlibrary: Fix memory leaks 2021-02-10 09:17:53 +01:00
Phaedrus Leeds
2a111e5042 common: Add API for listing related refs of installed ref
Currently if a user of libflatpak wants to list the related refs (such
as extensions and plugins) of something, they have three options:
1. They can parse the metadata manually with e.g.
   flatpak_remote_ref_get_metadata() and then key-file operations, but
   this means re-implementing parts of libflatpak and using key file
   strings that are not actually public (FLATPAK_METADATA_KEY_...).
2. They can use flatpak_installation_list_installed_related_refs_sync()
   but this only works for installed related refs not remote ones.
3. They can use flatpak_installation_list_remote_related_refs_sync() but
   this lists all remotely available related refs, including ones that
   may not be compatible with the installed version of the main ref
   (because they don't match any of the values in the "versions"
   metadata key).

So since none of these provide a way to get the remote related refs
corresponding to an installed application, add new API for that. For the
motivation of this see
https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1132
2021-02-10 09:17:53 +01:00
Simon McVittie
a926776cf4 tests: Disable revokefs if FUSE doesn't work
There are various reasons why distro autobuilder environments might not
be able to use FUSE in build-time tests: they might not have
fusermount(1), they might be locked-down to be unable to load the FUSE
kernel module as a result of security hardening, they might not have the
/etc/mtab symlink, they might not have CAP_SYS_ADMIN in their capability
bounding set, or they might not have write access to /dev/fuse. Try to
check for all of these conditions.

Heavily based on code that I previously contributed to
xdg-desktop-portal. Disabling revokefs, instead of skipping the test
that needs it, is based on the patches applied in @alexlarsson's PPA.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-09 09:33:57 +01:00
Alexander Larsson
c702f92609 Fix tests when installed tests are not enabled
We need a different rpath for libpreload in this case, because
installed_testdir is not set.
2021-01-14 10:32:18 +01:00
Simon McVittie
4108e02245 context: Add --unset-env option and a corresponding override
This follows up from GHSA-4ppf-fxf6-vxg2 to fix missing functionality
that I noticed while resolving that vulnerability, but is not required
for fixing the vulnerability.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-01-14 09:33:24 +01:00
Simon McVittie
b0aea9c053 run: Allow setting environment variables to empty strings
Some consumers of environment variables distinguish between present
with an empty value and absent. For example, if an environment variable
represents a search path like VK_ICD_FILENAMES, unsetting it often
results in use of a default, but setting it to the empty string results
in not searching any locations, which is sometimes what is desired.

The shell syntax "${BAR-unset}" expands to the value of ${BAR} if it
is set to anything (even an empty string), or to "unset" if not.
We can use that in the unit test to check that BAR is set to the
empty string in this case.

This follows up from GHSA-4ppf-fxf6-vxg2 to fix an issue that I noticed
while resolving that vulnerability, but is not required for fixing the
vulnerability.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-01-14 09:33:24 +01:00
Simon McVittie
d19f6c330a tests: Assert that --env= does not go in flatpak run or bwrap environ
For the portal's use of --env-fd= to be safe, we want the environment
variables that it sets to end up in the environment for the program
that is run by `bwrap` as process 2, but they must not go into the
environment that gets used to run `flatpak run` or `bwrap`. Assert
that this is the case.

For completeness, we're testing both --env= and --env-fd= here,
even though the earlier commit
"portal: Do not use caller-supplied variables in environment"
always uses --env-fd=.

Part-of: https://github.com/flatpak/flatpak/security/advisories/GHSA-4ppf-fxf6-vxg2
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-01-14 09:33:24 +01:00
Simon McVittie
39a5621e69 tests: Exercise --env-fd
Signed-off-by: Simon McVittie <smcv@collabora.com>
Part-of: https://github.com/flatpak/flatpak/security/advisories/GHSA-4ppf-fxf6-vxg2
2021-01-14 09:33:24 +01:00
Simon McVittie
821249844b tests: Expand coverage for environment variable overrides
This checks that `flatpak run --env=` takes precedence over
`flatpak override --env=`, and that environment variables don't get
onto the bwrap command-line (which would be information disclosure
if their values are secret).

Signed-off-by: Simon McVittie <smcv@collabora.com>
Part-of: https://github.com/flatpak/flatpak/security/advisories/GHSA-4ppf-fxf6-vxg2
2021-01-14 09:33:24 +01:00
Simon McVittie
8a00d43b22 Skip a test-case if /etc/mtab doesn't exist
fusermount requires /etc/mtab, but not all Debian buildd chroots
have that file, either as a regular file or as a symlink to
/proc/self/mounts.

(This is similar to commit b07b48e2, but for C code.)

Signed-off-by: Simon McVittie <smcv@debian.org>
2020-12-28 08:20:41 +01:00
Philip Withnall
9411fe2bca flatpak: Add --print-updated-env option to print environment
This is the environment needed to use flatpaks; a following commit will
hook this up to the systemd environment generator.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-22 14:21:54 +01:00
Simon McVittie
fe450d54ba test: Return G_DBUS_METHOD_INVOCATION_HANDLED where appropriate
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-12-09 08:34:19 +01:00
Alexander Larsson
07f36b2e90 Fix test-summaries on non-x86-64 2020-11-20 09:27:17 +01:00
Alexander Larsson
a43c617870 tests: Don't hardcode x86-64 2020-11-20 09:27:17 +01:00
Alexander Larsson
c4c57312ba tests: Un-redirect url after trying redirect
After the --redirect-url= test is finished it leaves the remote with a
different url, which is confusing the other tests.

In particular, at some point we remove the remote and add it back,
which gets us back to the old url, but at that point the summary (from
the newer url) has a later mtime than the old one so the old one keeps
getting used.

So, we unset the redirect and set back the old url. Also, the following test
had to be tweaked for this change.
2020-11-17 15:20:43 +01:00