diff --git a/tests/probes/filehash58/check_filehash_simple.xml b/tests/probes/filehash58/check_filehash_simple.xml new file mode 100644 index 000000000..2f6fa877e --- /dev/null +++ b/tests/probes/filehash58/check_filehash_simple.xml @@ -0,0 +1,40 @@ + + + combine_ovals.py from SCAP Security Guide + ssg: [0, 1, 40], python: 3.6.5 + 5.11 + 2018-07-20T09:33:24 + + + + + Verify that hash of a file that should contain just "foo\n". + + Red Hat Enterprise Linux 7 + + This description in OVALs is mandatory, but the most important is to have description in XCCDF. + + + + + + + + + + + + + + + /oval-test + SHA-1 + + + + + SHA-1 + f1d2d2f924e986ac86fdf7b36c94bcdf32beec15 + + + diff -r -U3 op0/tests/probes/filehash58/Makefile.in op1/tests/probes/filehash58/Makefile.in --- op0/tests/probes/filehash58/Makefile.in 2018-08-14 10:45:06.065438575 +0200 +++ op1/tests/probes/filehash58/Makefile.in 2018-08-14 10:53:57.248937836 +0200 @@ -1106,7 +1106,7 @@ $(top_builddir)/run TESTS = test_probes_filehash58.sh -EXTRA_DIST = test_probes_filehash58.sh test_probes_filehash58.xml.sh +EXTRA_DIST = test_probes_filehash58.sh test_probes_filehash58.xml.sh check_filehash_simple.xml all: all-am .SUFFIXES: diff -r -U3 op0/tests/probes/filehash58/test_probes_filehash58.sh op1/tests/probes/filehash58/test_probes_filehash58.sh --- op0/tests/probes/filehash58/test_probes_filehash58.sh 2018-08-14 10:36:09.914512125 +0200 +++ op1/tests/probes/filehash58/test_probes_filehash58.sh 2018-08-14 10:53:32.366536647 +0200 @@ -38,15 +38,69 @@ ret_val=1 fi + # The file was created as a side-effect of test_probes_filehash58.xml.sh [ $ret_val -eq 0 ] && rm -f /tmp/test_probes_filehash58.tmp return $ret_val } + +# $1: The chroot directory +function test_probes_filehash58_chroot { + + probecheck "filehash58" || return 255 + require "sha1sum" || return 255 + + local ret_val=0; + local DF="$srcdir/check_filehash_simple.xml" + + absolute_probe_root=$(cd "$1" && pwd) + + # oscap-chroot is not readily available during test run, so we use oscap + env var setting. + result_keyword=$(OSCAP_PROBE_ROOT="$absolute_probe_root" "$OSCAP" oval eval "$DF" | grep oval_test_has_hash | grep -o '\w*$') + + [ "$result_keyword" == "$2" ] && return 0 + # vvv This is more a test error than a failure or "warning" vvv + [ "$result_keyword" == "" ] && return 2 + return 1 +} + + +function test_probes_filehash58_chroot_pass { + local ret_val=0 + + mkdir -p pass + echo foo > pass/oval-test + + test_probes_filehash58_chroot pass true + ret_val=$? + rm -rf pass + + return $ret_val +} + + +function test_probes_filehash58_chroot_fail { + local ret_val=0 + + mkdir -p fail + echo bar > fail/oval-test + + test_probes_filehash58_chroot fail false + ret_val=$? + rm -rf fail + + return $ret_val +} + # Testing. test_init "test_probes_filehash58.log" test_run "test_probes_filehash58" test_probes_filehash58 +test_run "test_probes_filehash58_chroot_fail" test_probes_filehash58_chroot_fail + +test_run "test_probes_filehash58_chroot_pass" test_probes_filehash58_chroot_pass + test_exit