Debian Codegraph @

tests/API/XCCDF/tailoring/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 . $builddir/tests/test_common.sh
7
8 set -e -o pipefail
9
10 function test_api_xccdf_tailoring {
11 local INPUT=$srcdir/$1
12 local TAILORING=$srcdir/$2
13 local PROFILE=$3
14 local EXPECTED_PASS=$4
15
16 result=`mktemp`
17 $OSCAP xccdf eval --tailoring-file $TAILORING --profile $PROFILE --results $result $INPUT
18 if [ "$?" != "0" ]; then
19 return 1
20 fi
21
22 assert_exists $EXPECTED_PASS '//result[text()="pass"]'
23 rm -f $result
24 }
25
26 function test_api_xccdf_tailoring_ds {
27 local INPUT=$srcdir/$1
28 local TAILORING_ID=$2
29 local PROFILE=$3
30 local EXPECTED_PASS=$4
31
32 result=`mktemp`
33 $OSCAP xccdf eval --tailoring-id $TAILORING_ID --profile $PROFILE --results $result $INPUT
34 if [ "$?" != "0" ]; then
35 return 1
36 fi
37
38 assert_exists $EXPECTED_PASS '//result[text()="pass"]'
39 rm -f $result
40 }
41
42 function test_api_xccdf_tailoring_ds_hybrid {
43 local INPUT=$srcdir/$1
44 local TAILORING=$srcdir/$2
45 local PROFILE=$3
46 local EXPECTED_PASS=$4
47
48 result=`mktemp`
49 $OSCAP xccdf eval --tailoring-file $TAILORING --profile $PROFILE --results $result $INPUT
50 if [ "$?" != "0" ]; then
51 return 1
52 fi
53
54 assert_exists $EXPECTED_PASS '//result[text()="pass"]'
55 rm -f $result
56 }
57
58 function test_api_xccdf_tailoring_oscap_info {
59 local INPUT=$srcdir/$1
60
61 local INFO_RESULTS=`$OSCAP info $INPUT`
62 if [ "$?" != "0" ]; then
63 return 1
64 fi
65
66 echo "$INFO_RESULTS" | grep "XCCDF Tailoring"
67 if [ "$?" != "0" ]; then
68 return 1
69 fi
70 }
71
72 function test_api_xccdf_tailoring_autonegotiation {
73 local TAILORING=$srcdir/$1
74 local PROFILE=$2
75 local EXPECTED_PASS=$3
76
77 result=`mktemp`
78 $OSCAP xccdf eval --profile $PROFILE --results $result $TAILORING
79 if [ "$?" != "0" ]; then
80 return 1
81 fi
82
83 assert_exists $EXPECTED_PASS '//result[text()="pass"]'
84 rm -f $result
85 }
86
87 function test_api_xccdf_tailoring_simple_include_in_arf {
88 local INPUT=$srcdir/$1
89 local TAILORING=$srcdir/$2
90
91 result=`mktemp`
92 $OSCAP xccdf eval --tailoring-file $TAILORING --results-arf $result $INPUT
93 if [ "$?" != "0" ]; then
94 return 1
95 fi
96
97 assert_exists 1 '/arf:asset-report-collection/arf:report-requests/arf:report-request/arf:content/ds:data-stream-collection/ds:component/Tailoring'
98 rm -f $result
99 }
100
101 function test_api_xccdf_tailoring_simple_include_in_arf_xlink_namespace {
102 # This test case is a regression test for RHEL-34104
103
104 local INPUT=$srcdir/$1
105 local TAILORING=$srcdir/$2
106
107 result=`mktemp`
108 stderr=`mktemp`
109 $OSCAP xccdf eval --tailoring-file $TAILORING --results-arf $result $INPUT 2>"$stderr"
110 if [ "$?" != "0" ]; then
111 return 1
112 fi
113
114 [ ! -s "$stderr" ]
115 assert_exists 1 '/arf:asset-report-collection/arf:report-requests/arf:report-request/arf:content/ds:data-stream-collection/ds:component/Tailoring'
116
117 rm -f "$result"
118 rm -f "$stderr"
119 }
120
121 function test_api_xccdf_tailoring_profile_include_in_arf {
122 local INPUT=$srcdir/$1
123 local TAILORING=$srcdir/$2
124
125 result=`mktemp`
126 # "xccdf_com.example.www_profile_customized" customizes "xccdf_com.example.www_profile_baseline1"
127 $OSCAP xccdf eval --tailoring-file $TAILORING --profile "xccdf_com.example.www_profile_customized" --results-arf $result $INPUT || [ "$?" == "2" ]
128
129 component_xpath='/arf:asset-report-collection/arf:report-requests/arf:report-request/arf:content/ds:data-stream-collection/ds:component'
130 assert_exists 3 $component_xpath
131 assert_exists 3 $component_xpath'/@timestamp'
132 assert_exists 1 $component_xpath'/xccdf:Tailoring'
133 assert_exists 1 $component_xpath'/xccdf:Tailoring/xccdf:Profile'
134 assert_exists 1 $component_xpath'/xccdf:Tailoring/xccdf:Profile[@id="xccdf_com.example.www_profile_customized"]'
135 assert_exists 1 $component_xpath'/xccdf:Tailoring/xccdf:Profile[@extends="xccdf_com.example.www_profile_baseline1"]'
136 rm -f $result
137 }
138
139 function test_api_xccdf_tailoring_profile_generate_fix {
140 local INPUT=$srcdir/$1
141 local TAILORING=$srcdir/$2
142
143 tailoring_result=`mktemp`
144 fix_result=`mktemp`
145 # tailoring profile only with "always fail" rule and generate bash fix
146 $OSCAP xccdf eval --tailoring-file $TAILORING --profile "xccdf_com.example.www_profile_customized" --results-arf $tailoring_result $INPUT || [ "$?" == "2" ]
147 tailoring_id=$($XPATH $tailoring_result 'string(//ds:component-ref[contains(@id, "_tailoring")]/@id)')
148 $OSCAP xccdf generate fix --tailoring-id $tailoring_id --result-id xccdf_org.open-scap_test-result_xccdf-com.example.www_profile_customized --results $fix_result $tailoring_result
149
150 if ! grep -q "echo \"Fix the first rule\"" $fix_result; then
151 return 1
152 fi
153
154 rm -f $tailoring_result $fix_result
155 }
156
157 function test_api_xccdf_tailoring_profile_generate_guide {
158 local INPUT=$srcdir/$1
159 local TAILORING=$srcdir/$2
160
161 guide=`mktemp`
162 # tailoring profile only with "always fail" rule and generate HTML guide
163 $OSCAP xccdf generate guide --tailoring-file $TAILORING --profile "xccdf_com.example.www_profile_customized" --output $guide $INPUT
164
165 grep -q "Baseline Testing Profile 1 \[CUSTOMIZED\]" $guide
166 # profile 'customized' selects first rule and deselects the second
167 grep -q "xccdf_com.example.www_rule_first" $guide
168 grep -v "xccdf_com.example.www_rule_second" $guide
169 rm -f $guide
170 }
171
172 # Testing.
173
174 test_init "test_api_xccdf_tailoring.log"
175
176 test_run "test_api_xccdf_tailoring_default" test_api_xccdf_tailoring simple-xccdf.xml simple-tailoring.xml xccdf_org.open-scap_profile_default 1
177 test_run "test_api_xccdf_tailoring_unselecting" test_api_xccdf_tailoring simple-xccdf.xml simple-tailoring.xml xccdf_org.open-scap_profile_unselecting 0
178 test_run "test_api_xccdf_tailoring_override" test_api_xccdf_tailoring simple-xccdf.xml simple-tailoring.xml xccdf_org.open-scap_profile_override 1
179 test_run "test_api_xccdf_tailoring_unselecting_noop" test_api_xccdf_tailoring simple-xccdf.xml simple-tailoring.xml xccdf_org.open-scap_profile_unselecting_noop 0
180 test_run "test_api_xccdf_tailoring_ds_default" test_api_xccdf_tailoring_ds simple-ds.xml scap_org.open-scap_cref_simple-tailoring.xml xccdf_org.open-scap_profile_default 1
181 test_run "test_api_xccdf_tailoring_ds_unselecting" test_api_xccdf_tailoring_ds simple-ds.xml scap_org.open-scap_cref_simple-tailoring.xml xccdf_org.open-scap_profile_unselecting 0
182 test_run "test_api_xccdf_tailoring_ds_override" test_api_xccdf_tailoring_ds simple-ds.xml scap_org.open-scap_cref_simple-tailoring.xml xccdf_org.open-scap_profile_override 1
183 test_run "test_api_xccdf_tailoring_ds_hybrid_default" test_api_xccdf_tailoring_ds_hybrid simple-ds.xml simple-tailoring.xml xccdf_org.open-scap_profile_default 1
184 test_run "test_api_xccdf_tailoring_ds_hybrid_unselecting" test_api_xccdf_tailoring_ds_hybrid simple-ds.xml simple-tailoring.xml xccdf_org.open-scap_profile_unselecting 0
185 test_run "test_api_xccdf_tailoring_ds_hybrid_override" test_api_xccdf_tailoring_ds_hybrid simple-ds.xml simple-tailoring.xml xccdf_org.open-scap_profile_override 1
186 test_run "test_api_xccdf_tailoring_oscap_info_11" test_api_xccdf_tailoring_oscap_info simple-tailoring11.xml 1
187 test_run "test_api_xccdf_tailoring_oscap_info_12" test_api_xccdf_tailoring_oscap_info simple-tailoring.xml 1
188 test_run "test_api_xccdf_tailoring_autonegotiation" test_api_xccdf_tailoring_autonegotiation simple-tailoring-autonegotiation.xml xccdf_org.open-scap_profile_default 1
189 test_run "test_api_xccdf_tailoring_simple_include_in_arf" test_api_xccdf_tailoring_simple_include_in_arf simple-xccdf.xml simple-tailoring.xml
190 test_run "test_api_xccdf_tailoring_simple_include_in_arf_xlink_namespace" test_api_xccdf_tailoring_simple_include_in_arf_xlink_namespace xlink-test-simple-ds.xml simple-tailoring.xml
191 test_run "test_api_xccdf_tailoring_profile_include_in_arf" test_api_xccdf_tailoring_profile_include_in_arf baseline.xccdf.xml baseline.tailoring.xml
192 test_run "test_api_xccdf_tailoring_profile_generate_fix" test_api_xccdf_tailoring_profile_generate_fix baseline.xccdf.xml baseline.tailoring.xml
193 test_run "test_api_xccdf_tailoring_profile_generate_guide" test_api_xccdf_tailoring_profile_generate_guide baseline.xccdf.xml baseline.tailoring.xml
194
195
196 test_exit