]>
Commit | Line | Data |
---|---|---|
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 | 4 | set -e |
5c7290b1 | 5 | TEST_DESCRIPTION="SELinux tests" |
054ee249 | 6 | TEST_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 | |
14 | SETUP_SELINUX=yes | |
a415d436 | 15 | KERNEL_APPEND="$KERNEL_APPEND selinux=1 security=selinux" |
5c7290b1 | 16 | |
5c7290b1 EV |
17 | test_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] | |
32 | Description=Testsuite service | |
33 | After=multi-user.target | |
34 | ||
35 | [Service] | |
36 | ExecStart=/test-selinux-checks.sh | |
37 | Type=oneshot | |
38 | EOF | |
39 | ||
40 | cat <<EOF >$initdir/etc/systemd/system/hola.service | |
41 | [Service] | |
42 | Type=oneshot | |
43 | ExecStart=/bin/echo Start Hola | |
44 | ExecReload=/bin/echo Reload Hola | |
45 | ExecStop=/bin/echo Stop Hola | |
46 | RemainAfterExit=yes | |
47 | EOF | |
48 | ||
49 | setup_testsuite | |
50 | ||
51 | cat <<EOF >$initdir/etc/systemd/system/load-systemd-test-module.service | |
52 | [Unit] | |
53 | Description=Load systemd-test module | |
54 | DefaultDependencies=no | |
55 | Requires=local-fs.target | |
56 | Conflicts=shutdown.target | |
57 | After=local-fs.target | |
58 | Before=sysinit.target shutdown.target autorelabel.service | |
59 | ConditionSecurity=selinux | |
60 | ConditionPathExists=|/.load-systemd-test-module | |
61 | ||
62 | [Service] | |
63 | ExecStart=/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' | |
64 | Type=oneshot | |
65 | TimeoutSec=0 | |
66 | RemainAfterExit=yes | |
67 | EOF | |
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 | 108 | do_test "$@" |