From 384278919f039f47a06dd257f803ab68e5b48c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20T=C3=BD=C4=8D?= Date: Fri, 1 Jun 2018 12:46:58 +0200 Subject: [PATCH] Fixed test scripts bugs. - Removed an exit inside a function in favor of return - Constructed functions around tests that can be conditionally skipped , so the return statement can be used to perform the skip. --- tests/API/OVAL/unittests/test_object_component_type.sh | 5 +++-- tests/API/XCCDF/unittests/test_xccdf_transformation.sh | 4 ++++ tests/probes/iflisteners/test_probes_iflisteners.sh | 2 +- tests/probes/maskattr/test_object_entity_mask.sh | 4 ++++ tests/probes/maskattr/test_object_entity_mask_oval_5_9.sh | 4 ++++ tests/probes/maskattr/test_object_entity_nomask.sh | 4 ++++ tests/probes/rpmverify/test_not_equals_operation.sh | 4 ++++ tests/probes/sysctl/test_sysctl_probe.sh | 3 +++ tests/probes/sysctl/test_sysctl_probe_all.sh | 4 +++- 9 files changed, 30 insertions(+), 4 deletions(-) diff --git a/tests/API/OVAL/unittests/test_object_component_type.sh b/tests/API/OVAL/unittests/test_object_component_type.sh index f9189c08d3..d6ce76ce1e 100755 --- a/tests/API/OVAL/unittests/test_object_component_type.sh +++ b/tests/API/OVAL/unittests/test_object_component_type.sh @@ -2,10 +2,11 @@ stderr=`mktemp` -set -e set -o pipefail -$OSCAP oval eval $srcdir/test_object_component_type.oval.xml 2> $stderr || ret=$? +$OSCAP oval eval $srcdir/test_object_component_type.oval.xml 2> $stderr +ret=$? +set -e [ $ret -eq 1 ] grep -q "Entity [']something_bogus['] has not been found in textfilecontent_item (id: [0-9]\+) specified by object [']oval:oscap:obj:10[']." $stderr diff --git a/tests/API/XCCDF/unittests/test_xccdf_transformation.sh b/tests/API/XCCDF/unittests/test_xccdf_transformation.sh index bb43f936d7..3a83144080 100755 --- a/tests/API/XCCDF/unittests/test_xccdf_transformation.sh +++ b/tests/API/XCCDF/unittests/test_xccdf_transformation.sh @@ -5,6 +5,7 @@ set -o pipefail . ../../../test_common.sh +function perform_test { # if xsltproc is not installed we will skip the test require xsltproc || return 255 @@ -20,3 +21,6 @@ $OSCAP xccdf validate $result assert_exists 1 '//*[namespace::*="http://checklists.nist.gov/xccdf/1.2"]' rm $result +} + +perform_test diff --git a/tests/probes/iflisteners/test_probes_iflisteners.sh b/tests/probes/iflisteners/test_probes_iflisteners.sh index f0bf3b11c4..26a05720d8 100755 --- a/tests/probes/iflisteners/test_probes_iflisteners.sh +++ b/tests/probes/iflisteners/test_probes_iflisteners.sh @@ -22,7 +22,7 @@ function test_probes_iflisteners { if [ `id -u` -ne 0 ]; then echo you need to be root - exit 255 + return 255 fi local ret_val=0; diff --git a/tests/probes/maskattr/test_object_entity_mask.sh b/tests/probes/maskattr/test_object_entity_mask.sh index beaa44c2f7..518cbab7bd 100755 --- a/tests/probes/maskattr/test_object_entity_mask.sh +++ b/tests/probes/maskattr/test_object_entity_mask.sh @@ -4,6 +4,7 @@ set -e -o pipefail +function perform_test { probecheck "file" || return 255 name=$(basename $0 .sh) @@ -30,3 +31,6 @@ echo "Testing syschar values." [ "$($XPATH $result 'string(/oval_results/results/system/oval_system_characteristics/system_data/unix-sys:file_item/unix-sys:filepath)')" == "" ] rm $result +} + +perform_test diff --git a/tests/probes/maskattr/test_object_entity_mask_oval_5_9.sh b/tests/probes/maskattr/test_object_entity_mask_oval_5_9.sh index 11aa34a014..4da5591e2c 100755 --- a/tests/probes/maskattr/test_object_entity_mask_oval_5_9.sh +++ b/tests/probes/maskattr/test_object_entity_mask_oval_5_9.sh @@ -4,6 +4,7 @@ set -e -o pipefail +function perform_test { probecheck "file" || return 255 name=$(basename $0 .sh) @@ -30,3 +31,6 @@ echo "Testing syschar values." [ "$($XPATH $result 'string(/oval_results/results/system/oval_system_characteristics/system_data/unix-sys:file_item/unix-sys:filepath)')" == "" ] rm $result +} + +perform_test diff --git a/tests/probes/maskattr/test_object_entity_nomask.sh b/tests/probes/maskattr/test_object_entity_nomask.sh index 422ea43845..f3a2df53da 100755 --- a/tests/probes/maskattr/test_object_entity_nomask.sh +++ b/tests/probes/maskattr/test_object_entity_nomask.sh @@ -4,6 +4,7 @@ set -e -o pipefail +function perform_test { probecheck "file" || return 255 name=$(basename $0 .sh) @@ -27,3 +28,6 @@ echo "Testing syschar values." [ "$($XPATH $result 'string(/oval_results/results/system/oval_system_characteristics/system_data/unix-sys:file_item/unix-sys:filepath)')" == "/etc/passwd" ] rm $result +} + +perform_test diff --git a/tests/probes/rpmverify/test_not_equals_operation.sh b/tests/probes/rpmverify/test_not_equals_operation.sh index 5e1334fae6..b57d3a3024 100755 --- a/tests/probes/rpmverify/test_not_equals_operation.sh +++ b/tests/probes/rpmverify/test_not_equals_operation.sh @@ -4,6 +4,7 @@ set -e -o pipefail +function perform_test { probecheck "rpmverify" || return 255 name=$(basename $0 .sh) @@ -23,3 +24,6 @@ echo "Testing syschar values." [ "$($XPATH $result 'count(/oval_results/results/system/oval_system_characteristics/collected_objects/object[@id="oval:x:obj:2"]/reference)')" == "1" ] rm $result +} + +perform_test diff --git a/tests/probes/sysctl/test_sysctl_probe.sh b/tests/probes/sysctl/test_sysctl_probe.sh index b1780dd0c1..678d883e7a 100755 --- a/tests/probes/sysctl/test_sysctl_probe.sh +++ b/tests/probes/sysctl/test_sysctl_probe.sh @@ -4,6 +4,7 @@ set -e -o pipefail +function perform_test { probecheck "sysctl" || return 255 result=`mktemp` @@ -17,4 +18,6 @@ assert_exists 1 "/oval_results/results/system/oval_system_characteristics/system rm $result rm $stderr +} +perform_test diff --git a/tests/probes/sysctl/test_sysctl_probe_all.sh b/tests/probes/sysctl/test_sysctl_probe_all.sh index 42a630a716..073d332ee1 100755 --- a/tests/probes/sysctl/test_sysctl_probe_all.sh +++ b/tests/probes/sysctl/test_sysctl_probe_all.sh @@ -4,6 +4,7 @@ set -e -o pipefail +function perform_test { probecheck "sysctl" || return 255 name=$(basename $0 .sh) @@ -34,5 +35,6 @@ sed -i -E "/^E: lt-probe_sysctl: Can't read sysctl value from /d" "$stderr" [ ! -s $stderr ] rm $stderr $result $ourNames $sysctlNames +} - +perform_test