Commit Graph

11 Commits

Author SHA1 Message Date
Daniel P. Berrangé
8473ece90e test-systemd-tmpfiles: skip when /tmp has unexpected ownership
The systemd-tmpfiles binary will report a fatal error if /tmp is not owned
either by root, or by the current user:

  Detected unsafe path transition /tmp (owned by nobody) →
    /tmp/test-systemd-tmpfiles.a8qc6n18 (owned by berrange)
    during canonicalization of
    tmp/test-systemd-tmpfiles.a8qc6n18/test-content.7chd7rdi

When doing development inside a 'toolbox' container (which is required
on a Fedora SilverBlue distro), /tmp is owned by 'nobody', because it
has been passed through from the host and host UID 0 gets mapped to
UID 65536 by usernamespaces. This triggers the unsafe path transition
error message.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2023-10-26 14:46:15 +01:00
Yu Watanabe
b0efbe9b81 test: use XDG_STATE_HOME for %S and %L
This fixes the test failure when invoked by a user.
===
Running ./systemd-tmpfiles --user on 'f /tmp/test-systemd-tmpfiles.1foag_ur/test-content.n_9r_xhm/arg - - - - %S'
expect: '/home/watanabe/.config'
actual: '/home/watanabe/.local/state'
Traceback (most recent call last):
  File "/home/watanabe/git/systemd/test/test-systemd-tmpfiles.py", line 233, in <module>
    test_valid_specifiers(user=True)
  File "/home/watanabe/git/systemd/test/test-systemd-tmpfiles.py", line 135, in test_valid_specifiers
    test_content('f {} - - - - %S',
  File "/home/watanabe/git/systemd/test/test-systemd-tmpfiles.py", line 88, in test_content
    assert content == expected
           ^^^^^^^^^^^^^^^^^^^
AssertionError
===

This also makes the test uses fallback paths.

Follow-up for b50aadaff2.
2023-07-20 12:54:54 +01:00
Mike Yuan
f582e61bc3
test: tmpfiles: add tests on conditionalized execute bit 2023-04-27 15:18:31 +08:00
Yu Watanabe
458e8d6dd0 test-systemd-tmpfiles.py: create global temporary directory
For some unknown reasons, the temporary directory created by the test
below is not removed:
```
 # Test the case that a valid symlink is in the path.
 label = 'valid_symlink-deep'
 test_content('f= {} - - - - ' + label, label, user=user, subpath='/deep/1/2', path_cb=valid_symlink)
```
To keep /tmp clean, let's create the global temprary directory.
2023-03-18 22:27:41 +09:00
Yu Watanabe
015ddd4bf0 test-systemd-tmpfiles.py: use test_content() at one more place 2023-03-18 22:27:41 +09:00
Daan De Meyer
60f42f7ec2 test-systemd-tmpfiles: Fix execution when user is not in /etc/passwd
We might be running in a chroot as a uid that doesn't exist in /etc/passwd.
Let's make sure we don't fail in this scenario.

We pass $HOME when resetting the env so that we can find a home directory
and skip tests that depend on user name/group.
2023-01-29 17:49:38 +00:00
Luca Boccassi
b2d896f059 test/test-systemd-tmpfiles.py: do not fail if machine-id is missing
When building in a chroot there might not be any machine-id
2022-10-25 16:00:26 +01:00
Lennart Poettering
708daf42d8 tmpfiles: optionally, decode string to write to files with base64
This is useful to use "f" or "w" to write arbitrary binary files to
disk, or files with newlines and similar (for example to provision SSH
host keys and similar).
2022-07-15 11:55:03 +02:00
Zbigniew Jędrzejewski-Szmek
172e9cc3ee shared/specifier: fix %u/%U/%g/%G when called as unprivileged user
We would resolve those specifiers to the calling user/group. This is mostly OK
when done in the manager, because the manager generally operates as root
in system mode, and a non-root in user mode. It would still be wrong if
called with --test though. But in systemctl, this would be generally wrong,
since we can call 'systemctl --system' as a normal user, either for testing
or even for actual operation with '--root=…'.

When operating in --global mode, %u/%U/%g/%G should return an error.

The information whether we're operating in system mode, user mode, or global
mode is passed as the data pointer to specifier_group_name(), specifier_user_name(),
specifier_group_id(), specifier_user_id(). We can't use userdata, because
it's already used for other things.
2022-03-29 16:17:56 +02:00
Allen Webb
c46c323385 tmpfiles: add '=' action modifier.
Add the '=' action modifier that instructs tmpfiles.d to check the file
type of a path and remove objects that do not match before trying to
open or create the path.

BUG=chromium:1186405
TEST=./test/test-systemd-tmpfiles.py "$(which systemd-tmpfiles)"

Change-Id: If807dc0db427393e9e0047aba640d0d114897c26
2021-06-08 17:23:26 +02:00
Yu Watanabe
0703d2f6c4 test: move test-systemd-tmpfiles.py from src/test to test
As the other test scripts, e.g. test-sysusers.sh, are located under
test rather than src/test.
2021-01-19 07:04:19 +09:00