From 6aa77f9284070229f73063e15cb4b4aa59cb6020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Wed, 25 Oct 2023 17:19:35 +0100 Subject: [PATCH 1/3] test-blockdev-util: avoid abort when /home is a symlink MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On rpm-ostree distributions like Fedora SilverBlue /home (and various other well known locations) are symlinks to somewhere beneath /var. The path_is_encrypted() method uses O_NOFOLLOW and as a result will return ELOOP on /home. This causes test-blockdev-util to abort. Add ELOOP to the ignorable set of errnos for testing. Signed-off-by: Daniel P. Berrangé --- src/test/test-blockdev-util.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/test-blockdev-util.c b/src/test/test-blockdev-util.c index b97783b41f..134386c3f6 100644 --- a/src/test/test-blockdev-util.c +++ b/src/test/test-blockdev-util.c @@ -8,12 +8,14 @@ static void test_path_is_encrypted_one(const char *p, int expect) { int r; r = path_is_encrypted(p); - if (r == -ENOENT || ERRNO_IS_NEG_PRIVILEGE(r)) + if (IN_SET(r, -ENOENT, -ELOOP) || ERRNO_IS_NEG_PRIVILEGE(r)) /* This might fail, if btrfs is used and we run in a container. In that case we cannot * resolve the device node paths that BTRFS_IOC_DEV_INFO returns, because the device nodes * are unlikely to exist in the container. But if we can't stat() them we cannot determine * the dev_t of them, and thus cannot figure out if they are encrypted. Hence let's just - * ignore ENOENT here. Also skip the test if we lack privileges. */ + * ignore ENOENT here. Also skip the test if we lack privileges. + * ELOOP might happen if the mount point is a symlink, as seen with under + * some rpm-ostree distros */ return; assert_se(r >= 0); From 8473ece90e53040931c880bcbff623f1a5c037cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Wed, 25 Oct 2023 17:39:04 +0100 Subject: [PATCH 2/3] test-systemd-tmpfiles: skip when /tmp has unexpected ownership MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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é --- test/test-systemd-tmpfiles.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/test-systemd-tmpfiles.py b/test/test-systemd-tmpfiles.py index 77ef53b983..37a5e9ef3e 100755 --- a/test/test-systemd-tmpfiles.py +++ b/test/test-systemd-tmpfiles.py @@ -31,6 +31,14 @@ except AttributeError: exe_with_args = sys.argv[1:] temp_dir = tempfile.TemporaryDirectory(prefix='test-systemd-tmpfiles.') +# If /tmp isn't owned by either 'root' or the current user +# systemd-tmpfiles will exit with "Detected unsafe path transition" +# breaking this test +tmpowner = os.stat("/tmp").st_uid +if tmpowner != 0 and tmpowner != os.getuid(): + print("Skip: /tmp is not owned by 'root' or current user") + sys.exit(EXIT_TEST_SKIP) + def test_line(line, *, user, returncode=EX_DATAERR, extra={}): args = ['--user'] if user else [] print('Running {} on {!r}'.format(' '.join(exe_with_args + args), line)) From 3570ee3688fdeb0ff360ec793cf41e90f00d7729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Wed, 25 Oct 2023 17:52:11 +0100 Subject: [PATCH 3/3] test-fstab-generator: skip test impacted by /mnt symlink MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On rpm-ostree distributions such as Fedora SilverBlue /mnt (and other well known paths) will be a symlink to a location under /var. The fstab generator emits correct output in this case, however, the data does not match the expected output stored in the source tree. Rather than trying to adapt the test data, just skip this single test scenario when we see /mnt is a symlink. Signed-off-by: Daniel P. Berrangé --- test/test-fstab-generator.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/test-fstab-generator.sh b/test/test-fstab-generator.sh index 50ba321b9c..af8fa7c226 100755 --- a/test/test-fstab-generator.sh +++ b/test/test-fstab-generator.sh @@ -128,6 +128,14 @@ test_one() ( ) for f in "$src"/test-*.input; do + # If /mnt is a symlink, then the expected output from this + # test scenario will not match the actual output + if test "$f" = "$src/test-18-options.fstab.input" -a "$(readlink /mnt)" != "/mnt" + then + echo "Skip $f because /mnt is a symlink" + continue + fi + test_one "$f" yes test_one "$f" no done