Debian Codegraph @

tests/API/XCCDF/report/all.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 # Copyright 2012 Red Hat Inc., Durham, North Carolina.
4 # All Rights Reserved.
5
6 set -e -o pipefail
7
8 . $builddir/tests/test_common.sh
9
10 function test_generate_report {
11 local INPUT=$srcdir/$1
12 local EXPECTED_CONTENT=$2
13
14 local GENERATED_CONTENT=$($OSCAP xccdf generate report "$INPUT")
15 if [ "$?" != "0" ]; then
16 return 1
17 fi
18
19 echo "$GENERATED_CONTENT" | grep "$EXPECTED_CONTENT"
20 if [ "$?" == "0" ]; then
21 return 0
22 fi
23
24 echo "Generated content does not contain '$EXPECTED_CONTENT'!"
25 echo "Generated content:"
26 echo "$GENERATED_CONTENT"
27
28 return 1
29 }
30
31 function test_generate_report_custom {
32 local INPUT=$srcdir/$1
33 local EXPECTED_CONTENT=$2
34
35 local GENERATED_CONTENT=$($OSCAP xccdf generate custom --stylesheet $top_srcdir/xsl/xccdf-report.xsl "$INPUT")
36 if [ "$?" != "0" ]; then
37 return 1
38 fi
39
40 echo "$GENERATED_CONTENT" | grep "$EXPECTED_CONTENT"
41 if [ "$?" == "0" ]; then
42 return 0
43 fi
44
45 echo "Generated content does not contain '$EXPECTED_CONTENT'!"
46 echo "Generated content:"
47 echo "$GENERATED_CONTENT"
48
49 return 1
50 }
51
52 # Testing.
53
54 test_init "test_api_xccdf_report.log"
55
56 test_run "test_api_xccdf_report_xccdf11" test_generate_report results-xccdf11.xml xccdf_moc.elpmaxe.www_rule_1
57 test_run "test_api_xccdf_report_xccdf12" test_generate_report results-xccdf12.xml xccdf_moc.elpmaxe.www_rule_1
58 # This does not work because the xccdf-report.xsl is made for XCCDF 1.2, the namespace workaround
59 # (see xccdf_ns_xslt_workaround(..) for details) is not used when using custom stylesheets.
60 #test_run "test_api_xccdf_report_custom_xccdf11" test_generate_report_custom results-xccdf11.xml xccdf_moc.elpmaxe.www_rule_1
61 test_run "test_api_xccdf_report_custom_xccdf12" test_generate_report_custom results-xccdf12.xml xccdf_moc.elpmaxe.www_rule_1
62 test_run "test_api_xccdf_report_idents" test_generate_report results-idents-refs.xml identidentident
63 test_run "test_api_xccdf_report_refs" test_generate_report results-idents-refs.xml referencereferencereference
64 test_run "test_api_xccdf_report_no_title" test_generate_report results-xccdf12.xml "ID: xccdf_moc.elpmaxe.www_rule_1"
65 test_run "test_api_xccdf_report_title" test_generate_report results-title.xml "RULETITLE"
66
67 test_exit