Commit Graph

595 Commits

Author SHA1 Message Date
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
Alexander Larsson
7043093a5f tests: Avoid unnecessarily recreating the summary file
We enforce --no-update-summary when we create test apps and
runtimes, and then we ensure we always manually call update_repo
after all modifications are done.

This means we save work avoiding summary updates, but it also means we
can do special handling in update_summary and guarantee that this is
the only place this happens. For example, we want this to work around
the mtime handling of summary updates.
2020-11-17 15:20:43 +01:00
Alexander Larsson
7eb5f4ddc8 cli-transaction: Better handling of EOL refs
We remember what action we took for EOLs, and for sub-refs (ie .Locale)
we reuse that.

Also, we show if eol:ed refs are pinned (as that makes them not be
auto-uninstalled), and we list the apps that use the eol:ed runtime
ref.

Example run:
```
Looking for updates…
Info: (pinned) org.gnome.Sdk.Compat.i386 is end-of-life, with reason:
   The GNOME 3.34 runtime is no longer supported as of 14th August 2020. Please ask your application developer to migrate to a supported platform.
Info: org.gnome.Platform is end-of-life, with reason:
   The GNOME 3.32 runtime is no longer supported as of 11th March 2020. Please ask your application developer to migrate to a supported platform.
Applications using this runtime:
   org.gnome.HexGL
```
2020-11-16 11:23:10 +01:00
Alexander Larsson
7b1b706f80 decomposed: Add flatpak_decomposed_id_is_subref_of()
This checks if e.g. `org.app.App.Locale` is a subref of `org.app.App`.
2020-11-16 11:23:10 +01:00
Alexander Larsson
e6c0374939 tests: Add basic testing of subsets 2020-11-13 10:32:19 +01:00
Phaedrus Leeds
d406cf0ed7 installation: Include renamed apps when listing updates
Currently if an app has been renamed and you run "flatpak update" you
will be prompted to decide whether to install the new name of the app
(and uninstall the existing one). However, in such a situation
flatpak_installation_list_installed_refs_for_update() does not return
the app, and therefore gnome-software doesn't see any updates available
(except in the case where the installed commit is older than the commit
with the eol-rebase metadata).

So include end-of-life-rebased apps in the returned list. Patches to
make gnome-software update such apps properly are forthcoming.

I checked that the included unit test only passes with this patch to
libflatpak.
2020-11-11 09:00:39 +01:00
Alexander Larsson
105edb64f5 decomposed: Add flatpak_decomposed_new_from_pref()
This is useful as we have partial refs in the metadata files, like
the app runtime dependency.
2020-11-10 14:32:13 +01:00
Alexander Larsson
db11607016 installation: Use the FlatpakDecomposed APIs to create FlatpakRef:s
This means we do a bit less string operations, but it also allows us
to pick up the collection-id when listing refs from a file: uri, fixing
the issues described in https://github.com/flatpak/flatpak/pull/3909

This slightly changes the behaviour of collection ids and remotes.
When listing regular remotes we only ever return the refs with the
collection id specified by the configuration of that remote. However,
when specifying a file: uri for the remote name we return all the refs
in the repo, with their corresponding collection id.

This means the test suite has to change a bit as before we returned
all the collrefs from the remote, not just the one matching the configured
collection id.
2020-11-05 10:43:10 +01:00
Alexander Larsson
3b63c51ce6 decomposed: Add support for FlatpakRefKind 2020-11-05 10:43:10 +01:00
Alexander Larsson
7465ba0f18 Various FlatpakDecomposed API updates
getters now have three forms:
  const char *foo_peek() returns pointer into data and length
  const char* foo_get() returns zero terminated pointer into data
  char *foo_dup() returns allocated zero terminated pointer

Not everything has all of these (as that is not always possible), but
it is clear what each one does.

We also now support storing a collection id for a
FlatpakDecomposed. This is not typically done (as we use the source
remote to define the collecion id and don't expose this concept to the
user). However, for the case when directly listing a local repo (such as
a side-load repo) we need this.

We now validate the arch string. The valid chars are a-z, A-Z, 0-9 and
_. This was't previously verified, but no arches in existance have other
chars.

There is a new flatpak_decomposed_new_from_decomposed() which lets you
modify part of another ref. Say replace the arch or the branch and
keep the rest the same.
2020-11-05 10:43:10 +01:00
Phaedrus Leeds
835d2c78e6 testlibrary: Tweak one of the tests to avoid CLI
It seems cleaner to use library API than the CLI here.
2020-10-29 16:08:39 +01:00
Alexander Larsson
b8db46d0e2 tests: Add some tests for subsummaries 2020-10-29 15:30:35 +01:00
Alexander Larsson
472939f538 utils: Add FlatpakDecomposed helper
This is a ref-counted version of a ref string that is guaranteed
to be in the proper form, and is pre-decomposed for efficient partial
matches.
2020-10-29 15:30:35 +01:00
Alexander Larsson
7483a98769 utils: Allow passing sizes to more utils
These now take (optional) string length args:
  flatpak_id_has_subref_suffix()
  flatpak_levenshtein_distance()
  flatpak_is_valid_name()
  flatpak_is_valid_branch()
2020-10-29 15:30:35 +01:00
Alexander Larsson
12fd8332da tests: Test stuff with the old (non-indexed) summary format too 2020-10-29 15:30:35 +01:00
Alexander Larsson
a32fb1e333 tests: Silence assert_remote_has_no_config
This is meant to fail, so redirect its stderr to get less confusing test
logs.
2020-10-29 15:30:35 +01:00
Alexander Larsson
67d3443999 tests: Fix unnecessary rebuilds of the test platform
The code to use the pre-generated test platform was buggy so it wasn't
used. Also, generate a "stable" branch of it too as that is used
by test-run.sh.
2020-10-29 15:30:35 +01:00
Alexander Larsson
95ba6c77b4 tests: Better logging of which tests are succeeding
This makes it easier to spot where things go wrong in the logs.
2020-10-29 15:30:35 +01:00
Alexander Larsson
d98943b400 tests: Use "flatpak build-update-repo" instead of ostree summary -u
As we tweak the summary generation code we want to use our code, not
the ostree one.
2020-10-29 15:30:35 +01:00
Alexander Larsson
3169fa58ed tests: Convert some flatpak calls to $FLATPAK
This allows these to run under valgrind when testing in valgrind.
2020-10-29 15:30:35 +01:00
Alexander Larsson
3001cb3174 Fix some clang errors 2020-10-08 09:14:51 +02:00
Alexander Larsson
a5d86b8acb transaction: inject eol status to flatpak_dir_list_unused_refs()
This way we can get the proper eol status for the new to-be-installed
refs, rather than whatever was previously installed. This allows us to
detect when a runtime is updated and the new one is eol, and nothing
uses it, so it can be auto-uninstalled.
2020-10-08 09:14:51 +02:00
Alexander Larsson
05a7bda140 transaction: Simplify add_uninstall_unused_ops()
Rather than trying to figure out which runtimes are affected byt
the current setup of ops we run flatpak_dir_list_unused_refs() twice,
once with and once without the changes the transaction will cause.

Any unused refs after the transaction that were not unused before are
caused by the transaction and we start uninstall ops for those.

Also rename flatpak_dir_list_unused_refs_with_options() to
flatpak_dir_list_unused_refs() as it need not be so long.
2020-10-08 09:14:51 +02:00
Alexander Larsson
356b7fb346 tests: Add basic test for flatpak_dir_list_unused_refs_with_options()
This is currently failing, but I believe that is caused by actual
bugs.
2020-10-08 09:14:51 +02:00
Phaedrus Leeds
7691fc77eb app: Remove EOL unused runtimes in update command
In case a runtime becomes unused and then later becomes End-Of-Life, it
is currently not removed. So this commit removes such runtimes in the
update command, as discussed in #2639. A unit test is included.

I am planning to propose to use the FlatpakTransaction API added here in
gnome-software, so that users don't have to use the CLI at all for
runtimes to be cleaned up. KDE Discover already removes unused runtimes
periodically.
2020-10-08 09:14:51 +02:00
Phaedrus Leeds
617f614d50 Remove EOL runtimes upon app uninstall/upgrade
We normally don't remove a runtime when the last app using it is
uninstalled, since runtimes are large and re-downloading it in the
future may be difficult. But if the runtime is end-of-life, there's a
reasonable chance it won't be used again, so uninstall it in that case.

Similarly, if the last app using a runtime is upgraded to a different
runtime, and the runtime is EOL, uninstall it.

A unit test is included, and the subsequent unit test also had to be
modified. Otherwise we get a "Update is older than current version"
error, since the runtime is installed from test-repo but
setup_repo_no_add() calls make_runtime() which uses the one in
runtime-repo instead, which is older than the one in test-repo.
2020-10-08 09:14:51 +02:00
Phaedrus Leeds
55f6abe578 Avoid string duplication in FlatpakRef
Allocate a full ref string once per object rather than once per call.
This is similar to what we do in flatpak_dir_get_name_cached().
2020-10-02 15:30:58 +02:00
Kalev Lember
34bb5592c9 common: Allow skewered to camelcase DConf path conversion both ways
commit 6b46d9a0ed that added DConf path
skewering to camelcase conversion only allowed it in one direction
(skewered path1 and camelcase path2).

That turned out to be not enough to allow /org/gnome/sound-juicer/ to
/org/gnome/SoundJuicer/ conversion as the caller had the
flatpak_dconf_path_is_similar() arguments the other way around.

This commit implements it both ways to avoid confusion which way it
should be called.

F: Ignoring D-Conf migrate-path setting /org/gnome/sound-juicer/
2020-10-01 11:15:54 +02:00
Bastien Nocera
6b46d9a0ed common: Allow skewering when converting in app-id for DConf migration
Allow a snake-case in the app-id to convert to a '-' or '_' in the
DConf path to be considered similar enough for DConf migration purposes.

This allows the org.gnome.SoundJuicer app-id to migrate its
/org/gnome/sound-juicer DConf path.

F: Ignoring D-Conf migrate-path setting /org/gnome/sound-juicer/
2020-09-15 08:59:53 +02:00
Phaedrus Leeds
08f692962e Avoid shadowing local variables
Avoid shadowing variables that are already declared in a previous scope,
and make such occurrences compile-time errors. These are not functional
changes.

In a few places do related code cleanup.

A similar ostree PR is here:
https://github.com/ostreedev/ostree/pull/2195
2020-09-15 08:58:49 +02:00
Simon McVittie
5ce60b5e54 tests: Exercise host-os, host-etc and os-release in fake system roots
Now that FlatpakExports can be told to look for /etc and /usr in a
fake directory hierarchy, we can assert that systems resembling
particular OSs' layouts still work, even if we are not running on that
OS right now. In particular, this provides unit tests for commits
12e3dc05, 08d65c54, 7872935e and fe2536b8.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-09-14 11:12:25 +02:00
Simon McVittie
1b28b5395d tests: Assert that symlinks point to the right place
The previous implementation was rather simplistic, and assumed that
all symlinks that get exported are in /tmp/something/test_full/.
Tighten up the assertions, while also coping with symlinks that are
created at top level, such as /bin -> usr/bin.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-09-14 11:12:25 +02:00
Simon McVittie
89a4e330b4 tests: Allow asserting that a bind-mount has a different target
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-09-14 11:12:25 +02:00
Phaedrus Leeds
7cd1990196 Automatically pin explicitly installed runtimes
If a runtime is installed explicitly rather than as a dependency, pin it
so it doesn't get automatically removed when unused runtimes are being
removed. We do this because the runtime might be installed for
development or other uses.

This commit also rearranges some code in the mask and pin commands, and
adds a unit test.
2020-08-31 16:29:03 +02:00