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