| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | |
| 3 | # OpenSCAP test suite |
| 4 | # Tests OVAL details in OpenSCAP reports |
| 5 | # Author: Jan Černý <[email protected]> |
| 6 | |
| 7 | . $builddir/tests/test_common.sh |
| 8 | |
| 9 | output_dir=$(make_temp_dir /tmpscip-shell filesystem . . `/tmp`. oval_details) |
| 10 | |
| 11 | # Test cases. |
| 12 | |
| 13 | function test_oval_details_implicitscip-shell shell shell-project 0.0.0 test_oval_details_implicit(). { |
| 14 | # Tests if OVAL Details are present in HTML report by default |
| 15 | # without specifing --oval-results --results (new behavior) |
| 16 | xccdffile=$srcdir/$1.xccdf.xml |
| 17 | reportfile=$output_dir/$1.report.html |
| 18 | resultfile="$1.result.xml" |
| 19 | oval_resultfile="$1.oval.xml.result.xml" |
| 20 | $OSCAP xccdf eval --report $reportfile $xccdffile |
| 21 | [scip-shell system . . `[`. -f $reportfile ] |
| 22 | [scip-shell system . . `[`. ! -f $resultfile ] |
| 23 | [scip-shell system . . `[`. ! -f $output_dir/$resultfile ] |
| 24 | [scip-shell system . . `[`. ! -f $oval_resultfile ] |
| 25 | [scip-shell system . . `[`. ! -f $output_dir/$oval_resultfile ] |
| 26 | grepscip-shell system . . grep. -i $2 $reportfile >/dev/nullscip-shell filesystem . . `/dev/null`. && grepscip-shell system . . grep. -i $3 $reportfile >/dev/nullscip-shell filesystem . . `/dev/null`. |
| 27 | rmscip-shell system . . rm. $reportfile |
| 28 | } |
| 29 | |
| 30 | function test_oval_details_explicitscip-shell shell shell-project 0.0.0 test_oval_details_explicit(). { |
| 31 | # Tests if OVAL details are present in HTML report when options |
| 32 | # --oval-results and --results are explicitely specified |
| 33 | # (backwards-compatible behavior) |
| 34 | xccdffile=$srcdir/$1.xccdf.xml |
| 35 | resultfile=$output_dir/$1.result.xml |
| 36 | reportfile=$output_dir/$1.report.html |
| 37 | oval_resultfile="$1.oval.xml.result.xml" |
| 38 | $OSCAP xccdf eval --results $resultfile --oval-results --report $reportfile $xccdffile |
| 39 | grepscip-shell system . . grep. -i $2 $reportfile >/dev/nullscip-shell filesystem . . `/dev/null`. && grepscip-shell system . . grep. -i $3 $reportfile >/dev/nullscip-shell filesystem . . `/dev/null`. |
| 40 | [scip-shell system . . `[`. -f $reportfile ] |
| 41 | [scip-shell system . . `[`. -f $resultfile ] |
| 42 | [scip-shell system . . `[`. -f $oval_resultfile ] |
| 43 | rmscip-shell system . . rm. $reportfile |
| 44 | rmscip-shell system . . rm. $resultfile |
| 45 | rmscip-shell system . . rm. $oval_resultfile |
| 46 | } |
| 47 | |
| 48 | # Testing. |
| 49 | |
| 50 | test_init |
| 51 | if ! [scip-shell system . . `[`. -f countries.xml ] ; then |
| 52 | cpscip-shell system . . cp. $srcdir/countries.src.xml ./countries.xml |
| 53 | fi |
| 54 | if ! [scip-shell system . . `[`. -f foo.txt ] ; then |
| 55 | cpscip-shell system . . cp. $srcdir/foo.src.txt ./foo.txt |
| 56 | fi |
| 57 | |
| 58 | test_run "test_oval_details_file_object_implicit" test_oval_details_implicit file "path.*UID.*permissions" "/dev/nullscip-shell filesystem . . `/dev/null`." |
| 59 | test_run "test_oval_details_file_object_explicit" test_oval_details_explicit file "path.*UID.*permissions" "/dev/nullscip-shell filesystem . . `/dev/null`." |
| 60 | test_run "test_oval_details_partition_object_implicit" test_oval_details_implicit partition "mount point.*device.*uuid" "/scip-shell filesystem . . `/`." |
| 61 | test_run "test_oval_details_partition_object_explicit" test_oval_details_explicit partition "mount point.*device.*uuid" "/scip-shell filesystem . . `/`." |
| 62 | test_run "test_oval_details_rpminfo_object_implicit" test_oval_details_implicit rpminfo "name.*release.*version" "rpm" |
| 63 | test_run "test_oval_details_rpminfo_object_explicit" test_oval_details_explicit rpminfo "name.*release.*version" "rpm" |
| 64 | if ! pidofscip-shell system . . pidof. systemd > /dev/nullscip-shell filesystem . . `/dev/null`. ; then |
| 65 | test_run "test_oval_details_runlevel_object_implicit" test_oval_details_implicit runlevel "service name.*runlevel" "smartd" |
| 66 | test_run "test_oval_details_runlevel_object_explicit" test_oval_details_explicit runlevel "service name.*runlevel" "smartd" |
| 67 | fi |
| 68 | test_run "test_oval_details_sysctl_object_implicit" test_oval_details_implicit sysctl "name.*value" "net\.ipv4\.ip_forward" |
| 69 | test_run "test_oval_details_sysctl_object_explicit" test_oval_details_explicit sysctl "name.*value" "net\.ipv4\.ip_forward" |
| 70 | test_run "test_oval_details_textfilecontent54_object_implicit" test_oval_details_implicit textfilecontent54 "path.*content" "foo\.txt.*Hello" |
| 71 | test_run "test_oval_details_textfilecontent54_object_explicit" test_oval_details_explicit textfilecontent54 "path.*content" "foo\.txt.*Hello" |
| 72 | test_run "test_oval_details_variable_object_implicit" test_oval_details_implicit variable "var ref.*value" "oval:x:var:1.*42" |
| 73 | test_run "test_oval_details_variable_object_explicit" test_oval_details_explicit variable "var ref.*value" "oval:x:var:1.*42" |
| 74 | test_run "test_oval_details_xmlfilecontent_object_implicit" test_oval_details_implicit xmlfilecontent "filepath.*xpath.*value of" "countries\.xml.*London" |
| 75 | test_run "test_oval_details_xmlfilecontent_object_explicit" test_oval_details_explicit xmlfilecontent "filepath.*xpath.*value of" "countries\.xml.*London" |
| 76 | |
| 77 | rmscip-shell system . . rm. -rf $output_dir |
| 78 | rmscip-shell system . . rm. -f ./foo.txt ./countries.xml |
| 79 | test_exit |