Debian Codegraph @

tests/oval_details/test_oval_details.sh

raw symbols SCIP
1 #!/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 /tmp oval_details)
10
11 # Test cases.
12
13 function 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 [ -f $reportfile ]
22 [ ! -f $resultfile ]
23 [ ! -f $output_dir/$resultfile ]
24 [ ! -f $oval_resultfile ]
25 [ ! -f $output_dir/$oval_resultfile ]
26 grep -i $2 $reportfile >/dev/null && grep -i $3 $reportfile >/dev/null
27 rm $reportfile
28 }
29
30 function 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 grep -i $2 $reportfile >/dev/null && grep -i $3 $reportfile >/dev/null
40 [ -f $reportfile ]
41 [ -f $resultfile ]
42 [ -f $oval_resultfile ]
43 rm $reportfile
44 rm $resultfile
45 rm $oval_resultfile
46 }
47
48 # Testing.
49
50 test_init
51 if ! [ -f countries.xml ] ; then
52 cp $srcdir/countries.src.xml ./countries.xml
53 fi
54 if ! [ -f foo.txt ] ; then
55 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/null"
59 test_run "test_oval_details_file_object_explicit" test_oval_details_explicit file "path.*UID.*permissions" "/dev/null"
60 test_run "test_oval_details_partition_object_implicit" test_oval_details_implicit partition "mount point.*device.*uuid" "/"
61 test_run "test_oval_details_partition_object_explicit" test_oval_details_explicit partition "mount point.*device.*uuid" "/"
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 ! pidof systemd > /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 rm -rf $output_dir
78 rm -f ./foo.txt ./countries.xml
79 test_exit