Skip to content

Commit 6788f85

Browse files
committed
Add offline mode tests for yamlfilecontent
1 parent 97a19ac commit 6788f85

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
if(ENABLE_PROBES_INDEPENDENT)
22
add_oscap_test("test_probes_yamlfilecontent_key.sh")
33
add_oscap_test("test_probes_yamlfilecontent_array.sh")
4+
add_oscap_test("test_probes_yamlfilecontent_offline_mode.sh")
45
endif()
56

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
3+
. $builddir/tests/test_common.sh
4+
5+
function test_probes_yamlfilecontent_offline_mode {
6+
7+
probecheck "yamlfilecontent" || return 255
8+
9+
local ret_val=0
10+
local DF="${srcdir}/test_probes_yamlfilecontent_offline_mode.xml"
11+
local RF="results.xml"
12+
local YAML_FILE="openshift-logging.yaml"
13+
14+
[ -f $RF ] && rm -f $RF
15+
16+
tmpdir=$(mktemp -t -d "test_offline_mode_yamlfilecontent.XXXXXX")
17+
18+
# Setup chroot fs and host with test files in different states
19+
mkdir $tmpdir/tmp
20+
cp "${srcdir}/${YAML_FILE}" "${tmpdir}/tmp"
21+
22+
cp "${srcdir}/${YAML_FILE}" /tmp
23+
sed -i 's/name: instance/name: outstance/' "${tmpdir}/tmp/${YAML_FILE}"
24+
cp "${srcdir}/${YAML_FILE}" "/tmp/host-${YAML_FILE}"
25+
26+
set_chroot_offline_test_mode "$tmpdir"
27+
28+
$OSCAP oval eval --results $RF $DF
29+
30+
unset_chroot_offline_test_mode
31+
32+
if [ -f $RF ]; then
33+
verify_results "def" $DF $RF 3 && verify_results "tst" $DF $RF 3
34+
ret_val=$?
35+
else
36+
ret_val=1
37+
fi
38+
39+
rm -f /tmp/$YAML_FILE
40+
rm -rf ${tmpdir}
41+
42+
return $ret_val
43+
}
44+
45+
test_probes_yamlfilecontent_offline_mode
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?xml version="1.0"?>
2+
<oval_definitions xmlns:oval-def="http://oval.mitre.org/XMLSchema/oval-definitions-5" xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ind-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" xmlns:unix-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix" xmlns:lin-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5" xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix unix-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#independent independent-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#linux linux-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5 oval-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd">
3+
4+
<generator>
5+
<oval:product_name>yamlfilecontent</oval:product_name>
6+
<oval:product_version>1.0</oval:product_version>
7+
<oval:schema_version>5.11.3</oval:schema_version>
8+
<oval:timestamp>2020-02-13T00:00:00-00:00</oval:timestamp>
9+
</generator>
10+
11+
<definitions>
12+
13+
<definition class="compliance" version="1" id="oval:0:def:1"> <!-- comment="true" -->
14+
<metadata>
15+
<title></title>
16+
<description></description>
17+
</metadata>
18+
<criteria operator="AND">
19+
<criterion comment="check file in chroot" test_ref="oval:0:tst:1"/>
20+
</criteria>
21+
</definition>
22+
23+
<definition class="compliance" version="1" id="oval:0:def:2"> <!-- comment="false" -->
24+
<metadata>
25+
<title></title>
26+
<description></description>
27+
</metadata>
28+
<criteria operator="AND">
29+
<criterion comment="make sure file in host doesnt match" test_ref="oval:0:tst:2"/>
30+
</criteria>
31+
</definition>
32+
33+
<definition class="compliance" version="1" id="oval:0:def:3"> <!-- comment="false" -->
34+
<metadata>
35+
<title></title>
36+
<description></description>
37+
</metadata>
38+
<criteria operator="AND">
39+
<criterion comment="try to check file in host" test_ref="oval:0:tst:3"/>
40+
</criteria>
41+
</definition>
42+
43+
</definitions>
44+
45+
<tests>
46+
47+
<ind-def:yamlfilecontent_test version="1" id="oval:0:tst:1" check="all" comment="true">
48+
<ind-def:object object_ref="oval:0:obj:1"/>
49+
<ind-def:state state_ref="oval:0:ste:1"/>
50+
</ind-def:yamlfilecontent_test>
51+
52+
<ind-def:yamlfilecontent_test version="1" id="oval:0:tst:2" check="all" comment="false">
53+
<ind-def:object object_ref="oval:0:obj:2"/>
54+
<ind-def:state state_ref="oval:0:ste:2"/>
55+
</ind-def:yamlfilecontent_test>
56+
57+
<ind-def:yamlfilecontent_test version="1" id="oval:0:tst:3" check="all" comment="false">
58+
<ind-def:object object_ref="oval:0:obj:3"/>
59+
</ind-def:yamlfilecontent_test>
60+
61+
</tests>
62+
63+
<objects>
64+
65+
<ind-def:yamlfilecontent_object version="1" id="oval:0:obj:1">
66+
<ind-def:path>/tmp</ind-def:path>
67+
<ind-def:filename>openshift-logging.yaml</ind-def:filename>
68+
<ind-def:yamlpath>.metadata.namespace</ind-def:yamlpath>
69+
</ind-def:yamlfilecontent_object>
70+
71+
<ind-def:yamlfilecontent_object version="1" id="oval:0:obj:2">
72+
<ind-def:path>/tmp</ind-def:path>
73+
<ind-def:filename>openshift-logging.yaml</ind-def:filename>
74+
<ind-def:yamlpath>.metadata.namespace</ind-def:yamlpath>
75+
</ind-def:yamlfilecontent_object>
76+
77+
<ind-def:yamlfilecontent_object version="1" id="oval:0:obj:3">
78+
<ind-def:path>/tmp</ind-def:path>
79+
<ind-def:filename>host-openshift-logging.yaml</ind-def:filename>
80+
<ind-def:yamlpath>.metadata.namespace</ind-def:yamlpath>
81+
</ind-def:yamlfilecontent_object>
82+
83+
</objects>
84+
85+
<states>
86+
87+
<ind-def:yamlfilecontent_state version="1" id="oval:0:ste:1">
88+
<ind-def:value_of datatype="string">instance</ind-def:value_of>
89+
</ind-def:yamlfilecontent_state>
90+
91+
<ind-def:yamlfilecontent_state version="1" id="oval:0:ste:2">
92+
<ind-def:value_of datatype="string">outstance</ind-def:value_of>
93+
</ind-def:yamlfilecontent_state>
94+
95+
<ind-def:yamlfilecontent_state version="1" id="oval:0:ste:3">
96+
<ind-def:value_of datatype="string">instance</ind-def:value_of>
97+
</ind-def:yamlfilecontent_state>
98+
99+
</states>
100+
101+
</oval_definitions>

0 commit comments

Comments
 (0)