Commit Graph
882 Commits
Author SHA1 Message Date
Razze 01c3a02ad4 tests: Move timeouts and parallelism into test definitions 2026-10-19 11:34:50 +00:00
Razze cbe1f2939b pin: Show matching runtime counts
Show how many installed runtimes match each pin when listing interactively.
2026-10-13 16:01:13 +00:00
Razze 347aecefdb pin: Complete patterns for removal
Offer configured pin patterns as completions after --remove.
2026-10-13 16:01:13 +00:00
Razze 3a26b16761 http: Retry dropped and truncated responses
Curl's partial-file, empty-reply and send/receive errors were mapped to
G_IO_ERROR_FAILED, so the existing transient-error retry policy skipped
connection losses. Map them to partial-input and connection-closed errors
without changing the retry limit or retrying streams already written to.

Test recovery from empty and truncated replies, including compressed
cache output, and verify no partial contents survive the retry.
2026-10-12 10:52:23 +00:00
Franklin-Qi a3c67c8347 run: Mount both XDG and legacy ~/.fonts directories
When ~/.local/share/fonts existed, Flatpak only bind-mounted that
directory into the sandbox and ignored ~/.fonts. Users who still have
fonts under the legacy path (common after desktop environments changed
the default install location) therefore lost those fonts in Flatpak
apps.

Mount both directories when present: keep XDG fonts at
/run/host/user-fonts, and expose ~/.fonts at /run/host/user-fonts-legacy
with a matching fontconfig remap. If only ~/.fonts exists, keep the
historical /run/host/user-fonts destination.

Closes: #6869
2026-10-12 10:42:05 +00:00
re:fi.64 35b818b901 run: Write to --instance-id-fd after the pid is written
In commit 21f413f1, flatpak_instance_new was changed to require the pid
file to be written in order to succeed. This causes problems when
calling Spawn with NOTIFY_START, however, because portal expects to be
able to call flatpak_instance_new once the instance ID is retrieved. As
per the comments in the code that writes said instance ID, the idea was
that the instance would be *usable* at the point where the write takes
place (hence it being positioned *after* saving `bwrapinfo.json`), so it
makes sense to now move the write to *after* after the pid file is
written.

Since the pid file write and the instance ID write now go hand-in-hand,
both actions now take place in a separate function, so the logic can be
in one place. Additionally, the write itself is migrated to
`glnx_loop_write`, to shorten the code.

Assisted-by: DeepSeek-V4.1-Flash
2026-10-10 22:43:46 +00:00
re:fi.64 2c3f94f733 tests: Add a new test-spawn for testing spawning via the portal
The only tests for this before were the mocks, which are testing
slightly more specific things.

Assisted-by: DeepSeek-V4.1-Flash
2026-10-10 22:43:46 +00:00
re:fi.64 33ed7f21bb tests: Set FLATPAK to a wrapper script
Including CMD_PREFIX here causes problems for any subcommand that reads
`$FLATPAK` to find the binary path, since then it's no longer actually a
binary path. Instead, we can use a wrapper script, which will then run
flatpak w/ the prefix itself.
2026-10-10 22:43:46 +00:00
Kolja Lampe 9a032b2468 cli: Estimate install ETA from remaining bytes
Flatpak's progress percentage is a heuristic that includes metadata
discovery and write phases. Using it as a time base can produce
misleading remaining times or reach 00:00 while downloads are still
active.

Track the computed transfer total in FlatpakProgress. Use the remaining
bytes and measured transfer rate to calculate the CLI ETA.
2026-10-09 18:03:08 +00:00
Joao Kouznetz Bresser a819741d13 remote-ls: Check deployed alternative IDs when listing updates
OCI remote checksums identify images rather than imported OSTree commits.
Compare against the deployed alternative ID as well, matching the update
transaction's identity check and avoiding false pending updates.

Test OCI update listings after install, after publishing a real update,
and after applying it, using the existing user/system HTTP/HTTPS tests.
2026-10-09 13:14:20 +00:00
Markus Göllnitz 4256580bcc dir: Validate Desktop Entry and D-Bus Service
D-Bus Services and Desktop Entries could be extended
through custom keys. D-Bus daemons and desktop
environments augment Applications this way

Besides validating Exec= and D-Bus Service Name=, these
could lead to denial of service, e.g. X-GNOME-AutoRestart
in Desktop Entries, or even code exection outside the
sandbox, e.g. SystemdService in D-Bus Services.

The only reasonable way to ensure non of these make it
through, is exporting only know acceptable ones, instead
of hoping to aggregate every problematic one.

See: https://specifications.freedesktop.org/desktop-entry/latest/index.html
See: https://dbus.freedesktop.org/doc/dbus-specification.html

Resolves: CVE-2026-97027
Resolves: https://github.com/flatpak/flatpak/security/advisories/GHSA-v64f-hrwr-j4vh
Signed-off-by: Markus Göllnitz <camelcasenick@bewares.it>
[smcv: Added CVE ID]
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-09-28 09:44:36 +01:00
Razze dcfc1368fe tests: Cover document export reply formats
Exercise existing files, directories and nonexistent files against a real
document portal on the private test bus. Verify that --noexist returns a
usable export after the origin is created and preserves its read grant.

The regression fails on the AddNamed reply type mismatch without the fix.
All four checks pass with it.
2026-09-25 11:56:15 +00:00
Kolja Lampe 5f19424bd6 run: Forward documents using the sandbox mount path
The document portal is mounted at /run/flatpak/doc inside the sandbox,
but forwarded arguments used its host mount path. With a nonstandard
host runtime directory, that path is inaccessible to the application.

Keep the host path local to mount setup and return the sandbox destination
to argument forwarding. Preserve NULL when the portal is unavailable.

Add real-portal regression tests for user and isolated system installs.
Check file read/write, escaped URIs, directories and passthrough controls.
Skip the directory subtest on portal interfaces older than version 4.
2026-09-24 12:04:14 +00:00
Razze dec343a0ea user-data: Expose app data deletion in libflatpak
Applications using libflatpak currently have to duplicate the CLI's
private cleanup logic to offer the equivalent of uninstall --delete-data.

Add a standalone API that removes ~/.var/app data and resets permission
store entries without requiring the app to be installed. Keep it separate
from transactions so callers can retry partial failures or reset data for
an installed app.

Validate app IDs before constructing paths, propagate cancellation and
permission table errors, and document partial failure behavior.
2026-09-23 09:28:18 +00:00
Kolja Lampe db7830e049 completion: Validate cursor position
Parse the cursor as a long before narrowing it to the completion
structure's integer field. This lets malformed, negative, and overflowing
positions fail before they can index outside the command-line buffer, while
preserving the existing behavior of clamping positive positions beyond the
line length.
2026-09-21 15:18:35 +00:00
Bruno b4d57ffdce list: Add --bytes for sizes in bytes
g_format_size() output is unit-suffixed and locale-dependent, which
makes it awkward to sort or parse in scripts.

-b/--bytes prints a plain byte count; human-readable remains the
default. Also update the man page, the completion test and the tests.
2026-09-18 15:48:49 +00:00
abhinavmir 7c764d2984 context: Emit valid option names for D-Bus name policies
flatpak_context_to_args() built the D-Bus name options from
flatpak_policy_to_string(). That function gives the values used in the
[Session Bus Policy] and [System Bus Policy] metadata groups. Two of
them, "none" and "see", are not command-line options. A context that
contained such a policy gave --none-name= and --system-none-name=.

flatpak-run(1) writes these arguments to the [Instance] extra-args of
/.flatpak-info. flatpak-portal gives them back to flatpak(1) when a
sandboxed app calls flatpak-spawn(1). flatpak(1) then rejected the whole
command line with "Unknown option --none-name=...", so --no-talk-name
and --system-no-talk-name broke flatpak-spawn(1).

Map each policy to the option that sets it: --no-talk-name for
FLATPAK_POLICY_NONE, --talk-name for FLATPAK_POLICY_TALK, and --own-name
for FLATPAK_POLICY_OWN. FLATPAK_POLICY_SEE has no command-line option,
so emit nothing for it. It cannot occur here: the only caller serializes
a context that comes from the command line.
2026-09-18 14:47:43 +00:00
abhinavmir 915c5917c5 table-printer: Fix alignment of columns next to a decimal column
A decimal-aligned cell padded itself to widths[j], the natural column
width, while the title row and left-aligned cells padded themselves to
len, the width after expansion and ellipsization. In a table with an
expanding decimal column the title row and the cells therefore ended at
different offsets, and every column after the decimal one lost its
alignment. A cell with no decimal point in it used the left-aligned path,
so it stayed with the title row while its neighbours in the same column
moved.

The natural width of a decimal column is also not the width of its widest
cell: the cells split at the decimal point, so the column needs
lwidths[i] characters before the point and rwidths[i] after it. Take that
into account, so the trailing padding can no longer go negative and push
the rest of the row to the right.
2026-09-18 13:30:55 +00:00
Simon McVittie 55ec5bd592 libtest: Fix undefined variable reference if all test-cases are skipped
Fixes: f0ce1311 "tests: Drop plan_tests function, no longer used"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-08-21 16:08:07 +00:00
Simon McVittie 86d10f5f7a Revert "tests: Avoid Meson's strict TAP parsing for now"
Now that our error messages are valid UTF-8, we should no longer need to
do this.

This reverts commit 242e9893e7.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-08-21 16:07:48 +00:00
Simon McVittie 5f3f7a8b98 ref-utils: Always produce valid UTF-8 in validation error messages
While I'm changing the translatable string anyway, this also
incorporates a suggestion from #6753 to quote the invalid character, so
that output is clearer in the case where the invalid character is
whitespace.

Thanks: Christian Stadelmann
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-08-21 16:07:48 +00:00
Simon McVittie 9cd0ef4b0b utils: Avoid corrupting our output if an invalid glob is not UTF-8
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-08-21 16:07:48 +00:00
Simon McVittie ffcb20f781 utils: Add a function to describe invalid characters in strings
Until now we have been using `%c` to show invalid characters, but in
general that will corrupt our output if the input is non-ASCII,
because the individual bytes of a UTF-8 string are not valid UTF-8 alone.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-08-21 16:07:48 +00:00
Simon McVittie f0ce1311af tests: Drop plan_tests function, no longer used
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-08-21 15:34:20 +00:00
Simon McVittie eb240aa067 tests: Consistently Use the "no plan" style for TAP tests
Instead of announcing ahead of time how many tests will be run, just
log 1..32 or similar at the end, from the done_testing function.

This should go some way towards preventing unnecessary cherry-pick
conflicts when tests added to this script get backported.

Resolves: https://github.com/flatpak/flatpak/issues/6793
Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-08-21 15:34:20 +00:00
Simon McVittie f7a88aca00 tests: At the end of each test, explicitly log that we have finished
This is the equivalent of the function of the same name in Perl's
Test::More. If we already emitted a test plan, it asserts that the
number of tests we planned to do equals the number we actually did.

If not, it assumes that however many tests we have done, that's all of
the tests that we intend to do - this can be useful in test scripts
that routinely increase in length, like test-run.sh which is becoming
rather long (and has frequent conflicts for the "plan" line when we
cherry-pick new test coverage to older branches).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-08-21 15:34:20 +00:00
Simon McVittie 724ac88751 tests: Add a function to declare the "plan", instead of direct echo
This is approximately the equivalent of 'plan' in Perl Test::More:
it announces how many tests we plan to run.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-08-21 15:34:20 +00:00
Simon McVittie ea4321912b tests: Track and emit TAP test numbers in shell script tests
This will help us to emit correct TAP syntax, without having to always
declare up-front how many tests we are going to run.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-08-21 15:34:20 +00:00
Simon McVittie 242e9893e7 tests: Avoid Meson's strict TAP parsing for now
Older versions of Meson parsed TAP output very strictly, and would fail
the test when a `g_test_message()` mentions non-UTF-8, which results
in GLib adding a prefix on stdout that is not valid TAP syntax.

Ideally our error messages should all be valid UTF-8 even if the input
is not, but that's a larger refactor that shouldn't block security fix
releases, so for now just tell Meson to get the tests' pass/fail status
from their exit status rather than parsing their stdout.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-08-11 15:29:16 +00:00
Simon McVittie 12b79e1b11 tests: Add some unit tests for ref-utils name component validation
In the fix for GHSA-v2gw-v9h5-9q4x these functions are used to avoid
path traversal, so we'd better assert that they do detect and avoid it.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Helps: https://github.com/flatpak/flatpak/security/advisories/GHSA-v2gw-v9h5-9q4x
2026-08-10 23:06:17 +02:00
Simon McVittie 4fd1d67479 tests: Add a regression test for GHSA-8688-9x26-hhxj
The original reporter used various tricks to find a way for the sandboxed
app to overwrite these locations with symlinks, but for the purposes
of this test, I'm doing the setup outside the sandbox instead: probably
not all of these potential exploit routes are actually possible, but we
defend against all of them symmetrically.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-08-10 23:06:17 +02:00
Simon McVittie 2beb8890dc test-run: Check that the way com.valvesoftware.Steam behaves still works
This use of symlinks to ensure that the canonicalized paths of
`$XDG_CACHE_HOME`, `$XDG_CONFIG_HOME`, `$XDG_DATA_HOME` are
`~/.cache`, `~/.config`, `~/.local/share` is the sort of thing that
could easily regress if not tested.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2026-08-10 23:06:17 +02:00
Luigi Pavan 0717cd1685 cli: Don't set no_interaction for --assumeyes
The --assumeyes (-y) option was setting both the CLI-level
disable_interaction flag and the library-level no_interaction flag to
TRUE. This caused -y to suppress not just confirmation prompts, but
also credential prompts (basic auth, webflow), polkit authorization
dialogs, and parental control consent -- even though -y is documented
as "automatically answer yes to all questions".

Rename disable_interaction to assume_yes to clarify its purpose: it
auto-answers yes/no confirmations and picks default choices. Stop
calling flatpak_transaction_set_no_interaction() from the CLI
transaction constructor, so the library-level no_interaction flag is
only set by --noninteractive (which uses FlatpakQuietTransaction).
Remove the assume_yes guard from basic_auth_start so credential
prompts are always shown when the CLI transaction is in use.

Assisted-by: Cursor
2026-07-29 09:42:26 +00:00
Philip Withnall da47d3b236 tests: Prevent gcov warnings spuriously failing test-history.sh
If flatpak is built with code coverage enabled, libgcov sometimes
helpfully emits messages in the output from programs under test.

If we’re strictly comparing the whole output of a program to an expected
string, as `test-history.sh` does in these two places, this can cause
spurious test failures.

Temporarily tell it to send its error messages to `/dev/null` as we
don’t care about them for those tests.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-07-27 18:55:32 +00:00
Sebastian Wick d82c247cde portal: Test that the different envs get created as expected
Assisted-by: Claude:opus-4.6
2026-07-27 13:51:16 +00:00
Sebastian Wick 21f413f17f flatpak-instance: Make constructing failable
If we created an instance and we failed to get the PID of the instance,
we would still succeed. If one later calls flatpak_instance_is_running
or uses the result of flatpak_instance_get_pid with kill, it's possible
to terminate the entire process group (kill 0).

Let's just error out as early as possible to avoid those weird
half-initialized cases.

That unfortunately means we have to adjust a bunch of callers as well,
but fortunately, this only affects internal API.
2026-07-27 13:41:00 +00:00
John Cardullo f653896b18 tests: Add test cases for file-forwarding in test-run.sh
Add regression tests to verify that remote URIs and local files can
be forwarded correctly, and that empty paths result in an error.
2026-07-03 17:16:06 +00:00
bbhtt 5fcf748ac9 dir: Don't pass temp repo path to flatpak_dir_log during initial pull
During a system install with the system helper enabled, the initial
network pull goes to a temporary repo and then via pull local from that
repo to the final system repo while during user install there is only
one pull from network to the final repo.

c672c55 set the logger to use the temporary repo path as installation
but the history command afc87ad since the same day filters the initial
pull out as the installation name will never match the temporary path.

This causes the initial pull operation to be never show up in flatpak
history when using system installs while they work for user installs as
`INSTALLATION=user`.

This is presumably also broken for custom installations as they
will similarly not match the temp repo path.

So don't pass the path at all to flatpak_dir_log and we can later
fall back via flatpak_dir_get_name_cached() which sets the correct
`INSTALLATION` for system installs ie. `INSTALLATION=system`.

This also allows us to remove the workaround of adding two different
expected history outputs from ad1ff6d as both branches log the pull.

Without system helper `flatpak install` needs to be executed as
priviledged to operate on system install so the initial pull was
always logged correctly for that branch.
2026-06-23 09:11:59 +00:00
bbhtt ad1ff6da68 tests: Fix expected history output when system helper is compiled out
Pulls do not go to the temp repo so they are logged when system
helper is compiled out
2026-06-18 21:15:41 +00:00
bbhtt d820c4bc5e tests: Fix FL_CACHE_DIR when system helper is compiled out
The tests assumed that a system installation always uses the XDG cache
location unless running as root. However, Flatpak only uses that cache
location when the system helper is available at both compile and run
time. [1]

Builds configured with -Dsystem_helper=disabled instead use the
repo-local cache directory [2], causing the tests to look for cached
summaries in the wrong location and fail.

[1]: https://github.com/flatpak/flatpak/blob/96ad6825f3e7115eb95abeba55600b2a39b71178/common/flatpak-dir.c#L4853-L4862
[2]: https://github.com/flatpak/flatpak/blob/96ad6825f3e7115eb95abeba55600b2a39b71178/common/flatpak-dir.c#L4942-L4943
2026-06-18 21:15:41 +00:00
bbhtt 489b3972cb tests: Skip seccomp tests when seccomp is unavailable
Fixes the testsuite with `-Dseccomp=disabled`.
2026-06-18 21:15:41 +00:00
Mia McMahill cebc323966 tests: Add test for building and installing with exported releases.xml
Adds a test that verifies releases.xml metainfo files are not duplicated
at any export stage, and that they are not left unexported either.
2026-06-16 11:20:58 +00:00
Luigi Pavan b9c3cdd7a4 tests: Add test for installing from an auth-protected OCI registry
Add a regression test that installs from an auth-protected OCI registry.
The registry requires a bearer token for all /v2/ requests; the client
authenticates via the mock test authenticator and the installation
completes successfully. The test runs for both user and system install
paths.

Assisted-by: Cursor
2026-06-11 18:26:52 +00:00
Luigi Pavan a5b15b9aa1 tests/oci-registry: Add bearer token auth support to the mock OCI registry
Add infrastructure for testing OCI installations from auth-protected
registries. The mock server now supports requiring a bearer token on all
/v2/ requests, configurable via a new POST /testing-auth/configure admin
endpoint. The client gains a corresponding 'configure-auth' subcommand.

Assisted-by: Cursor
2026-06-11 18:26:52 +00:00
bbhtt a38377eb88 tests: Suppress an unused-result warning
The warning seems to happen with GCC 11 but not with GCC 13 or newer.

A simple void cast still leaves the warning enabled due to a bug
or intentional choice in GCC [1], so it is assigned to a variable first
and then void-ed.

[1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425
2026-05-27 14:32:40 +00:00
Sebastian Wick 17cb1135cb context: Keep fallback-x11 separate from x11 conditionals
If we convert fallback-x11 internally to a conditional x11 permission,
we cannot express current fallback-x11 stacking behavior:

lower: empty + upper: !fallback-x11 -> no x11 access
lower: fallback-x11 + upper: !fallback-x11 -> x11 access

The reason is that conditionals have no view of the lower level.

This changes things in a way that fallback-x11 stays its own socket
permission with two interactions with the x11 socket permission:

* If a upper level resets x11 (--socket=x11, --nosocket=x11), the lower
  level fallback-x11 permission gets dropped
* When computing the allowed sockets, --socket=fallback-x11 gets
  converted to --socket=if:x11:!has-wayland

Fixes: #6556
2026-04-29 10:14:29 +00:00
Sebastian Wick bd75302323 tests/repo: Make a test more robust by checking files for diff
Instead of trying to read them into variables, which could fail if there
were null bytes in the key.

Fixes: 43642337 ("dir: Try to delete the remote if we failed to add it entirely")
2026-04-28 13:18:48 +00:00
Sebastian Wick 3296c9e619 system-helper: Fix checking if the reinstall flag was passed in
Fixes: 919d2922 ("common: support reinstall option on bundle installations")
2026-04-28 13:18:48 +00:00
Sebastian Wick 68343e938f tests: Fix checks where we expect a command to fail
I was convinced that the pattern `! command` with -e aborts when
`command` fails. This is not the case (the result of `false` is the same
as `! true` but somehow this doesn't matter).

Fix the tests and use the newly introduced `assert_not` function. One
could also use `command && assert_not_reached "message"` but who has
time to write error messages for all the cases.
2026-04-28 13:18:48 +00:00
razzeee 6dfe1ad4d0 dir: handle missing remote tracking ref in repo_pull so that Flatpak-Upgrade-From header is sent 2026-04-21 11:28:31 +00:00