public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [tests/selinux] pr775-checkpolicy-revdeps: policycoreutils/setfiles: Make the relabel test robust
@ 2026-09-11 13:18 Petr Lautrbach
  0 siblings, 0 replies; only message in thread
From: Petr Lautrbach @ 2026-09-11 13:18 UTC (permalink / raw)
  To: git-commits

            A new commit has been pushed.

            Repo   : tests/selinux
            Branch : pr775-checkpolicy-revdeps
            Commit : e48b62767b4c20bdd9954326bc9c77ce77ba7e04
            Author : Petr Lautrbach <plautrba@redhat.com>
            Date   : 2021-02-05T15:28:21+01:00
            Stats  : +28/-12 in 1 file(s)
            URL    : https://src.fedoraproject.org/tests/selinux/c/e48b62767b4c20bdd9954326bc9c77ce77ba7e04?branch=pr775-checkpolicy-revdeps

            Log:
            policycoreutils/setfiles: Make the relabel test robust

- use directory which is not usually mounted as tmpfs
- use own spec_file
- use -F option
- check context of all directories and files inside chroot

---
diff --git a/policycoreutils/setfiles/runtest.sh b/policycoreutils/setfiles/runtest.sh
index 539eaae..a760694 100755
--- a/policycoreutils/setfiles/runtest.sh
+++ b/policycoreutils/setfiles/runtest.sh
@@ -66,23 +66,39 @@ EOF"
 
     rlPhaseStartTest "setfiles should not abort when it can't label a file - bz#1794518"
         USER=$(mktemp -u userXXXX)
-        USERTMP=$(mktemp -d)
+        USERTMP=$(mktemp -d -p /var/tmp)
         rlRun "useradd ${USER}"
+        rlRun "cat > ${USERTMP}/spec_file <<EOF
+/   -d system_u:object_r:default_t:s0
+/.*  system_u:object_r:default_t:s0
+EOF"
+        DIRS="${USERTMP}/1/1 ${USERTMP}/1/2 ${USERTMP}/2/2 ${USERTMP}/3/4 ${USERTMP}/5/6"
         rlRun "
-chown ${USER} ${USERTMP}
-mkdir -p ${USERTMP}/1/1 ${USERTMP}/1/2
-mkdir -p ${USERTMP}/2/1 ${USERTMP}/2/2
-mkdir -p ${USERTMP}/3/4
-mkdir -p ${USERTMP}/5/6
-touch ${USERTMP}/3/4/i
+for DIR in ${DIRS}; do
+    mkdir -p \${DIR}
+done
+touch ${USERTMP}/1/1/${USER} ${USERTMP}/3/4/chattr
 chown -R ${USER} ${USERTMP}
-chown root: ${USERTMP}/1/2
-chattr +i ${USERTMP}/3/4/i
+mkdir -p ${USERTMP}/2/1
+touch ${USERTMP}/2/1/root
+chattr +i ${USERTMP}/3/4/chattr
 " 0,1 "Prepare directory structure"
-        rlRun "su ${USER} -c '/usr/sbin/setfiles -v -r ${USERTMP} /etc/selinux/targeted/contexts/files/file_contexts ${USERTMP}'"
-        rlRun "userdel -r ${USER}"
-        chattr -i ${USERTMP}/3/4/i
+        rlRun "su ${USER} -c '/usr/sbin/setfiles -F -d -v -r ${USERTMP} ${USERTMP}/spec_file ${USERTMP}'" 0-255
+        for DIR in ${DIRS}; do
+            CONTEXT=$(secon --prompt --file ${DIR})
+            rlAssertEquals "${DIR}" ${CONTEXT} "system_u:object_r:default_t:s0"
+        done
+        CONTEXT=$(secon --prompt --file ${USERTMP}/1/1/${USER})
+        rlAssertEquals "${USERTMP}/1/1/${USER}" ${CONTEXT} "system_u:object_r:default_t:s0"
+        CONTEXT=$(secon --prompt --file ${USERTMP}/2/1)
+        rlAssertNotEquals "${USERTMP}/2/1" ${CONTEXT} "system_u:object_r:default_t:s0"
+        CONTEXT=$(secon --prompt --file ${USERTMP}/2/1/root)
+        rlAssertNotEquals "${USERTMP}/2/1/root" ${CONTEXT} "system_u:object_r:default_t:s0"
+        CONTEXT=$(secon --prompt --file ${USERTMP}/3/4/chattr)
+        rlAssertNotEquals "${USERTMP}/3/4/chattr" ${CONTEXT} "system_u:object_r:default_t:s0"
+        chattr -i ${USERTMP}/3/4/chattr
         rlRun "rm -rf ${USERTMP}"
+        rlRun "userdel -r ${USER}"
     rlPhaseEnd
     rlPhaseStartCleanup
         rlRun "popd"

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-11 13:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-11 13:18 [tests/selinux] pr775-checkpolicy-revdeps: policycoreutils/setfiles: Make the relabel test robust Petr Lautrbach

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox