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