summaryrefslogtreecommitdiffstats
path: root/test/TEST-06-SELINUX/test.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
commit55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch)
tree33f869f55a1b149e9b7c2b7e201867ca5dd52992 /test/TEST-06-SELINUX/test.sh
parentInitial commit. (diff)
downloadsystemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz
systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/TEST-06-SELINUX/test.sh')
-rwxr-xr-xtest/TEST-06-SELINUX/test.sh43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/TEST-06-SELINUX/test.sh b/test/TEST-06-SELINUX/test.sh
new file mode 100755
index 0000000..3841015
--- /dev/null
+++ b/test/TEST-06-SELINUX/test.sh
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -e
+
+TEST_DESCRIPTION="SELinux tests"
+IMAGE_NAME="selinux"
+TEST_NO_NSPAWN=1
+
+if [[ -e /etc/selinux/config ]]; then
+ SEPOLICY="$(awk -F= '/^SELINUXTYPE=/ {print $2; exit}' /etc/selinux/config)"
+
+ # C8S doesn't set SELINUXTYPE in /etc/selinux/config, so default to 'targeted'
+ if [[ -z "$SEPOLICY" ]]; then
+ echo "Failed to parse SELinux policy from /etc/selinux/config, falling back to 'targeted'"
+ SEPOLICY="targeted"
+ fi
+
+ if [[ ! -d "/etc/selinux/$SEPOLICY" ]]; then
+ echo "Missing policy directory /etc/selinux/$SEPOLICY, skipping the test"
+ exit 0
+ fi
+
+ echo "Using SELinux policy '$SEPOLICY'"
+else
+ echo "/etc/selinux/config is missing, skipping the test"
+ exit 0
+fi
+
+# shellcheck source=test/test-functions
+. "${TEST_BASE_DIR:?}/test-functions"
+
+SETUP_SELINUX=yes
+KERNEL_APPEND="${KERNEL_APPEND:-} selinux=1 enforcing=0 lsm=selinux"
+
+test_append_files() {
+ local workspace="${1:?}"
+
+ setup_selinux
+ # Config file has (unfortunately) always precedence, so let's switch it there as well
+ sed -i '/^SELINUX=disabled$/s/disabled/permissive/' "$workspace/etc/selinux/config"
+}
+
+do_test "$@"