]> git.ipfire.org Git - thirdparty/systemd.git/blame - test/TEST-06-SELINUX/test.sh
scripts: use 4 space indentation
[thirdparty/systemd.git] / test / TEST-06-SELINUX / test.sh
CommitLineData
5c7290b1 1#!/bin/bash
818567fc 2set -e
5c7290b1 3TEST_DESCRIPTION="SELinux tests"
054ee249 4TEST_NO_NSPAWN=1
5c7290b1
EV
5
6# Requirements:
7# Fedora 23
8# selinux-policy-targeted
9# selinux-policy-devel
10
67321fdf 11# Check if selinux-policy-devel is installed, and if it isn't bail out early instead of failing
cc4338e4 12test -f /usr/share/selinux/devel/include/system/systemd.if || exit 0
67321fdf 13
5c7290b1
EV
14. $TEST_BASE_DIR/test-functions
15SETUP_SELINUX=yes
a415d436 16KERNEL_APPEND="$KERNEL_APPEND selinux=1 security=selinux"
5c7290b1 17
5c7290b1
EV
18test_setup() {
19 create_empty_image
20 mkdir -p $TESTDIR/root
21 mount ${LOOPDEV}p1 $TESTDIR/root
22
23 # Create what will eventually be our root filesystem onto an overlay
24 (
25 LOG_LEVEL=5
26 eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
27
28 setup_basic_environment
29
30 # setup the testsuite service
31 cat <<EOF >$initdir/etc/systemd/system/testsuite.service
32[Unit]
33Description=Testsuite service
5c7290b1
EV
34
35[Service]
36ExecStart=/test-selinux-checks.sh
37Type=oneshot
38EOF
39
40 cat <<EOF >$initdir/etc/systemd/system/hola.service
41[Service]
42Type=oneshot
43ExecStart=/bin/echo Start Hola
44ExecReload=/bin/echo Reload Hola
45ExecStop=/bin/echo Stop Hola
46RemainAfterExit=yes
47EOF
48
49 setup_testsuite
50
51 cat <<EOF >$initdir/etc/systemd/system/load-systemd-test-module.service
52[Unit]
53Description=Load systemd-test module
54DefaultDependencies=no
55Requires=local-fs.target
56Conflicts=shutdown.target
57After=local-fs.target
58Before=sysinit.target shutdown.target autorelabel.service
59ConditionSecurity=selinux
60ConditionPathExists=|/.load-systemd-test-module
61
62[Service]
63ExecStart=/bin/sh -x -c 'echo 0 >/sys/fs/selinux/enforce && cd /systemd-test-module && make -f /usr/share/selinux/devel/Makefile load && rm /.load-systemd-test-module'
64Type=oneshot
65TimeoutSec=0
66RemainAfterExit=yes
67EOF
68
69 touch $initdir/.load-systemd-test-module
70 mkdir -p $initdir/etc/systemd/system/basic.target.wants
71 ln -fs load-systemd-test-module.service $initdir/etc/systemd/system/basic.target.wants/load-systemd-test-module.service
72
73 local _modules_dir=/var/lib/selinux
74 rm -rf $initdir/$_modules_dir
75 if ! cp -ar $_modules_dir $initdir/$_modules_dir; then
76 dfatal "Failed to copy $_modules_dir"
77 exit 1
78 fi
79
80 local _policy_headers_dir=/usr/share/selinux/devel
81 rm -rf $initdir/$_policy_headers_dir
82 inst_dir /usr/share/selinux
83 if ! cp -ar $_policy_headers_dir $initdir/$_policy_headers_dir; then
84 dfatal "Failed to copy $_policy_headers_dir"
85 exit 1
86 fi
87
88 mkdir $initdir/systemd-test-module
89 cp systemd_test.te $initdir/systemd-test-module
90 cp systemd_test.if $initdir/systemd-test-module
91 cp test-selinux-checks.sh $initdir
92 dracut_install -o sesearch
93 dracut_install runcon
94 dracut_install checkmodule semodule semodule_package m4 make /usr/libexec/selinux/hll/pp load_policy sefcontext_compile
95 ) || return 1
96
97 # mask some services that we do not want to run in these tests
98 ln -s /dev/null $initdir/etc/systemd/system/systemd-hwdb-update.service
99 ln -s /dev/null $initdir/etc/systemd/system/systemd-journal-catalog-update.service
100 ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.service
101 ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.socket
102 ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service
103
104 ddebug "umount $TESTDIR/root"
105 umount $TESTDIR/root
106}
107
5c7290b1 108do_test "$@"