| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | |
| 3 | # Copyright 2009 Red Hat Inc., Durham, North Carolina. |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # OpenScap Probes Test Suite. |
| 7 | # |
| 8 | # Created on: Nov 30, 2009 |
| 9 | # |
| 10 | # Authors: |
| 11 | # Peter Vrabec, <[email protected]> |
| 12 | # David Niemoller |
| 13 | # Ondrej Moris, <[email protected]> |
| 14 | |
| 15 | . $builddir/tests/test_common.sh |
| 16 | |
| 17 | . ${srcdir}/runlevel_helper.sh |
| 18 | |
| 19 | # Test Cases. |
| 20 | |
| 21 | function test_probes_runlevel_Ascip-shell shell shell-project 0.0.0 test_probes_runlevel_A(). { |
| 22 | |
| 23 | probecheck "runlevel" || return 255 |
| 24 | require "chkconfig" || return 255 |
| 25 | require "egrep" || return 255 |
| 26 | require "awk" || return 255 |
| 27 | |
| 28 | local services_list="$(get_services_list)" |
| 29 | [scip-shell system . . `[`. -n "$services_list" ] || return 255 |
| 30 | |
| 31 | local ret_val=0; |
| 32 | local DF="test_probes_runlevel_A.xml" |
| 33 | local RF="results_A.xml" |
| 34 | |
| 35 | [scip-shell system . . `[`. -f $RF ] && rmscip-shell system . . rm. -f $RF |
| 36 | |
| 37 | bashscip-shell system . . bash. ${srcdir}/test_probes_runlevel_A.xml.sh > $DF |
| 38 | $OSCAP oval eval --results $RF $DF |
| 39 | |
| 40 | if [scip-shell system . . `[`. -f $RF ]; then |
| 41 | |
| 42 | for S in `get_services_list`; do |
| 43 | for L in `get_service_runlevels ${S}`; do |
| 44 | LEVEL=`echoscip-shell system . . echo. $L | awkscip-shell system . . awk. -F: '{print $1}'` |
| 45 | STATE=`echoscip-shell system . . echo. $L | awkscip-shell system . . awk. -F: '{print $2}'` |
| 46 | |
| 47 | for SUFFIX in T F; do |
| 48 | TEST_DEF=`grepscip-shell system . . grep. "id=\"oval:${S}-${LEVEL}-${STATE}-${SUFFIX}:tst:1\"" $DF` |
| 49 | TEST_RES=`grepscip-shell system . . grep. "test_id=\"oval:${S}-${LEVEL}-${STATE}-${SUFFIX}:tst:1\"" $RF` |
| 50 | |
| 51 | if (echoscip-shell system . . echo. $TEST_RES | grepscip-shell system . . grep. "result=\"true\"" >/dev/nullscip-shell filesystem . . `/dev/null`.); then |
| 52 | RES="TRUE" |
| 53 | elif (echoscip-shell system . . echo. $TEST_RES | grepscip-shell system . . grep. "result=\"false\"" >/dev/nullscip-shell filesystem . . `/dev/null`.); then |
| 54 | RES="FALSE" |
| 55 | else |
| 56 | RES="ERROR" |
| 57 | fi |
| 58 | |
| 59 | if (echoscip-shell system . . echo. $TEST_DEF | grepscip-shell system . . grep. "comment=\"true\"" >/dev/nullscip-shell filesystem . . `/dev/null`.); then |
| 60 | CMT="TRUE" |
| 61 | elif (echoscip-shell system . . echo. $TEST_DEF | grepscip-shell system . . grep. "comment=\"false\"" >/dev/nullscip-shell filesystem . . `/dev/null`.); then |
| 62 | CMT="FALSE" |
| 63 | else |
| 64 | CMT="ERROR" |
| 65 | fi |
| 66 | |
| 67 | if [scip-shell system . . `[`. ! $RES = $CMT ]; then |
| 68 | echoscip-shell system . . echo. "Result of oval:${S}-${LEVEL}-${STATE}-${SUFFIX}:tst:1 should be ${CMT}!" |
| 69 | ret_val=$[$ret_val + 1] |
| 70 | fi |
| 71 | |
| 72 | done |
| 73 | done |
| 74 | done |
| 75 | else |
| 76 | ret_val=1 |
| 77 | fi |
| 78 | |
| 79 | return $ret_val |
| 80 | } |
| 81 | |
| 82 | function test_probes_runlevel_Bscip-shell shell shell-project 0.0.0 test_probes_runlevel_B(). { |
| 83 | |
| 84 | probecheck "runlevel" || return 255 |
| 85 | require "chkconfig" || return 255 |
| 86 | |
| 87 | local ret_val=0; |
| 88 | local DF="test_probes_runlevel_B.xml" |
| 89 | local RF="results_B.xml" |
| 90 | |
| 91 | local SERVICE_A=`get_services_matching 3 on | headscip-shell system . . head. -1` |
| 92 | local SERVICE_B=`get_services_matching 3 off | headscip-shell system . . head. -1` |
| 93 | |
| 94 | if [scip-shell system . . `[`. -z "$SERVICE_A" -o -z "$SERVICE_B" ]; then |
| 95 | return 255 #SKIPPED |
| 96 | fi |
| 97 | |
| 98 | bashscip-shell system . . bash. ${srcdir}/test_probes_runlevel_B.xml.sh $SERVICE_A $SERVICE_B > $DF |
| 99 | $OSCAP oval eval --results $RF $DF |
| 100 | |
| 101 | if [scip-shell system . . `[`. -f $RF ]; then |
| 102 | verify_results "def" $DF $RF 13 && verify_results "tst" $DF $RF 40 |
| 103 | ret_val=$? |
| 104 | else |
| 105 | ret_val=1 |
| 106 | fi |
| 107 | |
| 108 | return $ret_val |
| 109 | } |
| 110 | |
| 111 | function test_probes_runlevel_Cscip-shell shell shell-project 0.0.0 test_probes_runlevel_C(). { |
| 112 | probecheck "runlevel" || return 255 |
| 113 | require "chkconfig" || return 255 |
| 114 | |
| 115 | local ret_val=0; |
| 116 | local definition="test_probes_runlevel_C.xml" |
| 117 | declare -x result="results_C.xml" |
| 118 | |
| 119 | local SERVICE_A=`get_services_matching 3 on | headscip-shell system . . head. -1` |
| 120 | local SERVICE_B=`get_services_matching 3 off | headscip-shell system . . head. -1` |
| 121 | |
| 122 | if [scip-shell system . . `[`. -z "$SERVICE_A" -o -z "$SERVICE_B" ]; then |
| 123 | return 255 # SKIPPED |
| 124 | fi |
| 125 | |
| 126 | bashscip-shell system . . bash. ${srcdir}/test_probes_runlevel_C.xml.sh $SERVICE_A $SERVICE_B > $definition |
| 127 | $OSCAP oval eval --results $result $definition |
| 128 | |
| 129 | assert_exists 2 '/oval_results/results/system/oval_system_characteristics/system_data/unix-sys:runlevel_itemscip-shell filesystem . . `/oval_results/results/system/oval_system_characteristics/system_data/unix-sys:runlevel_item`.' |
| 130 | ret_val=$? |
| 131 | |
| 132 | return $ret_val |
| 133 | } |
| 134 | |
| 135 | # Testing. |
| 136 | |
| 137 | test_init |
| 138 | |
| 139 | test_run "test_probes_runlevel_A" test_probes_runlevel_A |
| 140 | test_run "test_probes_runlevel_B" test_probes_runlevel_B |
| 141 | test_run "test_probes_runlevel_C" test_probes_runlevel_C |
| 142 | |
| 143 | test_exit |