]> git.ipfire.org Git - thirdparty/systemd.git/blame - test/TEST-06-SELINUX/test.sh
user-util: synthesize user records for "nobody" the same way as for "root"
[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
818567fc 4set -e
5c7290b1 5TEST_DESCRIPTION="SELinux tests"
054ee249 6TEST_NO_NSPAWN=1
5c7290b1
EV
7
8# Requirements:
9# Fedora 23
10# selinux-policy-targeted
11# selinux-policy-devel
12
13. $TEST_BASE_DIR/test-functions
14SETUP_SELINUX=yes
a415d436 15KERNEL_APPEND="$KERNEL_APPEND selinux=1 security=selinux"
5c7290b1 16
5c7290b1
EV
17test_setup() {
18 create_empty_image
19 mkdir -p $TESTDIR/root
20 mount ${LOOPDEV}p1 $TESTDIR/root
21
22 # Create what will eventually be our root filesystem onto an overlay
23 (
24 LOG_LEVEL=5
25 eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
26
27 setup_basic_environment
28
29 # setup the testsuite service
30 cat <<EOF >$initdir/etc/systemd/system/testsuite.service
31[Unit]
32Description=Testsuite service
33After=multi-user.target
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 "$@"