Skip to content

Commit 96271c5

Browse files
committed
Add tests for "OVAL details in HTML report by default"
Improves existing test for OVAL details to check both old a new behavior. Test if OVAL details are present in HTML report without specifying --oval-details and --results. At the same time it verifies that the old way still works and the OVAL results XML is created as expected.
1 parent 1aa4af0 commit 96271c5

File tree

1 file changed

+42
-10
lines changed

1 file changed

+42
-10
lines changed

tests/oval_details/test_oval_details.sh

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,37 @@ output_dir=`mktemp -d -t oval_details_XXXXXX`
1010

1111
# Test cases.
1212

13-
function test_oval_details {
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)
1416
xccdffile=$srcdir/$1.xccdf.xml
1517
resultfile=$output_dir/$1.result.xml
1618
reportfile=$output_dir/$1.report.html
19+
oval_resultfile="$1.oval.xml.result.xml"
20+
$OSCAP xccdf eval --report $reportfile $xccdffile
21+
[ -f $reportfile ]
22+
[ ! -f $resultfile ]
23+
[ ! -f $oval_resultfile ]
24+
grep -i $2 $reportfile >/dev/null && grep -i $3 $reportfile >/dev/null
25+
rm $reportfile
26+
}
27+
28+
function test_oval_details_explicit {
29+
# Tests if OVAL details are present in HTML report when options
30+
# --oval-results and --results are explicitely specified
31+
# (backwards-compatible behavior)
32+
xccdffile=$srcdir/$1.xccdf.xml
33+
resultfile=$output_dir/$1.result.xml
34+
reportfile=$output_dir/$1.report.html
35+
oval_resultfile="$1.oval.xml.result.xml"
1736
$OSCAP xccdf eval --results $resultfile --oval-results --report $reportfile $xccdffile
1837
grep -i $2 $reportfile >/dev/null && grep -i $3 $reportfile >/dev/null
19-
rm "$1.oval.xml.result.xml"
38+
[ -f $reportfile ]
39+
[ -f $resultfile ]
40+
[ -f $oval_resultfile ]
41+
rm $reportfile
42+
rm $resultfile
43+
rm $oval_resultfile
2044
}
2145

2246
# Testing.
@@ -29,16 +53,24 @@ if ! [ -f foo.txt ] ; then
2953
cp $srcdir/foo.src.txt ./foo.txt
3054
fi
3155

32-
test_run "test_oval_details_file_object" test_oval_details file "path.*UID.*permissions" "/dev/null"
33-
test_run "test_oval_details_partition_object" test_oval_details partition "mount point.*device.*uuid" "/"
34-
test_run "test_oval_details_rpminfo_object" test_oval_details rpminfo "name.*release.*version" "rpm"
56+
test_run "test_oval_details_file_object_implicit" test_oval_details_implicit file "path.*UID.*permissions" "/dev/null"
57+
test_run "test_oval_details_file_object_explicit" test_oval_details_explicit file "path.*UID.*permissions" "/dev/null"
58+
test_run "test_oval_details_partition_object_implicit" test_oval_details_implicit partition "mount point.*device.*uuid" "/"
59+
test_run "test_oval_details_partition_object_explicit" test_oval_details_explicit partition "mount point.*device.*uuid" "/"
60+
test_run "test_oval_details_rpminfo_object_implicit" test_oval_details_implicit rpminfo "name.*release.*version" "rpm"
61+
test_run "test_oval_details_rpminfo_object_explicit" test_oval_details_explicit rpminfo "name.*release.*version" "rpm"
3562
if ! pidof systemd > /dev/null ; then
36-
test_run "test_oval_details_runlevel_object" test_oval_details runlevel "service name.*runlevel" "smartd"
63+
test_run "test_oval_details_runlevel_object_implicit" test_oval_details_implicit runlevel "service name.*runlevel" "smartd"
64+
test_run "test_oval_details_runlevel_object_explicit" test_oval_details_explicit runlevel "service name.*runlevel" "smartd"
3765
fi
38-
test_run "test_oval_details_sysctl_object" test_oval_details sysctl "name.*value" "net\.ipv4\.ip_forward"
39-
test_run "test_oval_details_textfilecontent54_object" test_oval_details textfilecontent54 "path.*content" "foo\.txt.*Hello"
40-
test_run "test_oval_details_variable_object" test_oval_details variable "var ref.*value" "oval:x:var:1.*42"
41-
test_run "test_oval_details_xmlfilecontent_object" test_oval_details xmlfilecontent "filepath.*xpath.*value of" "countries\.xml.*London"
66+
test_run "test_oval_details_sysctl_object_implicit" test_oval_details_implicit sysctl "name.*value" "net\.ipv4\.ip_forward"
67+
test_run "test_oval_details_sysctl_object_explicit" test_oval_details_explicit sysctl "name.*value" "net\.ipv4\.ip_forward"
68+
test_run "test_oval_details_textfilecontent54_object_implicit" test_oval_details_implicit textfilecontent54 "path.*content" "foo\.txt.*Hello"
69+
test_run "test_oval_details_textfilecontent54_object_explicit" test_oval_details_explicit textfilecontent54 "path.*content" "foo\.txt.*Hello"
70+
test_run "test_oval_details_variable_object_implicit" test_oval_details_implicit variable "var ref.*value" "oval:x:var:1.*42"
71+
test_run "test_oval_details_variable_object_explicit" test_oval_details_explicit variable "var ref.*value" "oval:x:var:1.*42"
72+
test_run "test_oval_details_xmlfilecontent_object_implicit" test_oval_details_implicit xmlfilecontent "filepath.*xpath.*value of" "countries\.xml.*London"
73+
test_run "test_oval_details_xmlfilecontent_object_explicit" test_oval_details_explicit xmlfilecontent "filepath.*xpath.*value of" "countries\.xml.*London"
4274

4375
rm -rf $output_dir
4476
rm -f ./foo.txt ./countries.xml

0 commit comments

Comments
 (0)