Debian Codegraph @

tests/probes/selinuxsecuritycontext/test_probes_selinuxsecuritycontext_offline_mode.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 . $builddir/tests/test_common.sh
4
5 function test_probes_selinuxsecuritycontext_offline_mode {
6 local VALID=$1
7
8 # if the user doesn't have SELinux enabled we will skip the test
9 selinuxenabled || return 255
10
11 probecheck "selinuxboolean" || return 255
12
13 local ret_val=0;
14 local DF="${srcdir}/test_probes_selinuxsecuritycontext.xml"
15 local RF="test_probes_selinuxsecuritycontext_offline_mode.results.xml"
16 local stderr=$(mktemp $1.err.XXXXXX)
17 echo "stderr file: $stderr"
18
19 [ -f $RF ] && rm -f $RF
20
21 tmpdir=$(mktemp -t -d "test_offline_mode_selinuxsecuritycontext.XXXXXX")
22
23 if [[ "${VALID}" == "true" ]]; then
24 ln -s /dev $tmpdir
25 fi
26
27 set_chroot_offline_test_mode "$tmpdir"
28
29 $OSCAP oval eval --results $RF $DF 2>$stderr
30
31 unset_chroot_offline_test_mode
32
33 [ -f $RF ]
34
35 result="$RF"
36
37 if [[ "${VALID}" == "true" ]]; then
38 assert_exists 1 '/oval_results/results/system/tests/test[@result="true"][@test_id="oval:1:tst:1"]'
39 verify_results "def" $DF $RF 1 && verify_results "tst" $DF $RF 1
40 else
41 assert_exists 1 '/oval_results/results/system/tests/test[@result="false"][@test_id="oval:1:tst:1"]'
42 fi
43
44 grep -Ei "(W: |E: )" $stderr && ret_val=1 && echo "There is an error and/or a warning in the output!"
45 rm $stderr
46
47 rm -rf ${tmpdir}
48
49 return $ret_val
50 }
51
52 test_run "Basic selinuxsecuritycontext probe test for offline mode" test_probes_selinuxsecuritycontext_offline_mode "true"
53 test_run "Basic selinuxsecuritycontext probe test for offline mode (invalid prefix)" test_probes_selinuxsecuritycontext_offline_mode "false"