| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Copyright 2014--2016 Red Hat Inc., Durham, North Carolina. |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # OpenScap Probes Test Suite. |
| 7 | |
| 8 | set -e -o pipefail |
| 9 | |
| 10 | . $builddir/tests/test_common.sh |
| 11 | |
| 12 | function test_probes_systemdunitproperty_offline_mode { |
| 13 | local VALID=$1 |
| 14 | |
| 15 | probecheck "systemdunitproperty" || return 255 |
| 16 | pidof systemd > /dev/null || return 255 |
| 17 | |
| 18 | local ret_val=0; |
| 19 | local DF="${srcdir}/test_probes_systemdunitproperty_offline_mode.xml" |
| 20 | local RF="results.xml" |
| 21 | local stderr=$(mktemp $1.err.XXXXXX) |
| 22 | echo "stderr file: $stderr" |
| 23 | |
| 24 | [ -f $RF ] && rm -f $RF |
| 25 | |
| 26 | tmpdir=$(mktemp -t -d "test_offline_mode_systemdunitproperty.XXXXXX") |
| 27 | |
| 28 | if [[ "${VALID}" == "true" ]]; then |
| 29 | ln -s /run $tmpdir |
| 30 | fi |
| 31 | |
| 32 | set_chroot_offline_test_mode "$tmpdir" |
| 33 | |
| 34 | $OSCAP oval eval --results $RF $DF 2>$stderr |
| 35 | |
| 36 | unset_chroot_offline_test_mode |
| 37 | |
| 38 | [ -f $RF ] |
| 39 | |
| 40 | result="$RF" |
| 41 | |
| 42 | if [[ "${VALID}" == "true" ]]; then |
| 43 | assert_exists 1 '/oval_results/results/system/tests/test[@result="true"][@test_id="oval:0:tst:1"]' |
| 44 | assert_exists 1 '/oval_results/results/system/tests/test[@result="true"][@test_id="oval:0:tst:2"]' |
| 45 | assert_exists 1 '/oval_results/results/system/tests/test[@result="true"][@test_id="oval:0:tst:3"]' |
| 46 | assert_exists 1 '/oval_results/results/system/tests/test[@result="true"][@test_id="oval:0:tst:4"]' |
| 47 | assert_exists 1 '/oval_results/results/system/tests/test[@result="true"][@test_id="oval:0:tst:5"]' |
| 48 | assert_exists 1 '/oval_results/results/system/tests/test[@result="false"][@test_id="oval:0:tst:6"]' |
| 49 | assert_exists 1 '/oval_results/results/system/tests/test[@result="false"][@test_id="oval:0:tst:7"]' |
| 50 | verify_results "def" $DF $RF 7 |
| 51 | verify_results "tst" $DF $RF 7 |
| 52 | else |
| 53 | assert_exists 1 '/oval_results/results/system/tests/test[@result="unknown"][@test_id="oval:0:tst:1"]' |
| 54 | assert_exists 1 '/oval_results/results/system/tests/test[@result="unknown"][@test_id="oval:0:tst:2"]' |
| 55 | assert_exists 1 '/oval_results/results/system/tests/test[@result="unknown"][@test_id="oval:0:tst:3"]' |
| 56 | assert_exists 1 '/oval_results/results/system/tests/test[@result="unknown"][@test_id="oval:0:tst:4"]' |
| 57 | assert_exists 1 '/oval_results/results/system/tests/test[@result="unknown"][@test_id="oval:0:tst:5"]' |
| 58 | assert_exists 1 '/oval_results/results/system/tests/test[@result="unknown"][@test_id="oval:0:tst:6"]' |
| 59 | assert_exists 1 '/oval_results/results/system/tests/test[@result="unknown"][@test_id="oval:0:tst:7"]' |
| 60 | fi |
| 61 | |
| 62 | grep -Ei "(W: |E: )" $stderr && ret_val=1 && echo "There is an error and/or a warning in the output!" |
| 63 | rm $stderr |
| 64 | |
| 65 | rm $RF |
| 66 | rm -rf ${tmpdir} |
| 67 | |
| 68 | return $ret_val |
| 69 | } |
| 70 | |
| 71 | test_run "Probe systemdunitproperty offline functionality" test_probes_systemdunitproperty_offline_mode "true" |
| 72 | test_run "Probe systemdunitproperty offline functionality (invalid prefix)" test_probes_systemdunitproperty_offline_mode "false" |