Skip to content

Commit 97a19ac

Browse files
authored
Merge pull request #1479 from yuumasato/add-yamlfilecontent-test
Add simple tests for yamlprobe
2 parents 949e7b8 + d54d078 commit 97a19ac

7 files changed

+319
-0
lines changed

tests/probes/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ add_subdirectory("systemdunitproperty")
2525
add_subdirectory("textfilecontent54")
2626
add_subdirectory("uname")
2727
add_subdirectory("xinetd")
28+
add_subdirectory("yamlfilecontent")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
if(ENABLE_PROBES_INDEPENDENT)
2+
add_oscap_test("test_probes_yamlfilecontent_key.sh")
3+
add_oscap_test("test_probes_yamlfilecontent_array.sh")
4+
endif()
5+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: "logging.openshift.io/v1alpha1"
2+
kind: "LogForwarding"
3+
metadata:
4+
name: instance
5+
namespace: openshift-logging
6+
spec:
7+
disableDefaultForwarding: true
8+
outputs:
9+
- type: "elasticsearch"
10+
name: elasticsearch
11+
endpoint: elasticsearch.openshift-logging.svc:9200
12+
mode: 066
13+
secret:
14+
name: fluentd
15+
- type: "elasticsearch"
16+
name: elasticsearch-insecure
17+
endpoint: elasticsearch-insecure.svc.messaging.cluster.local
18+
mode: "066"
19+
insecure: true
20+
- type: "forward"
21+
name: secureforward-offcluster
22+
endpoint: https://secureforward.offcluster.com:9200
23+
mode: "067"
24+
secret:
25+
name: secureforward
26+
pipelines:
27+
- inputSource: "hello"
28+
- name: container-logs
29+
inputSource: logs.app
30+
outputRefs:
31+
- elasticsearch
32+
- secureforward-offcluster
33+
- name: infra-logs
34+
inputSource: logs.infra
35+
outputRefs:
36+
- elasticsearch-insecure
37+
- name: audit-logs
38+
inputSource: logs.audit
39+
outputRefs:
40+
- secureforward-offcluster
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
. $builddir/tests/test_common.sh
4+
5+
function test_probes_yamlfilecontent_array {
6+
7+
probecheck "yamlfilecontent" || return 255
8+
9+
local ret_val=0
10+
local DF="${srcdir}/test_probes_yamlfilecontent_array.xml"
11+
local RF="results.xml"
12+
13+
[ -f $RF ] && rm -f $RF
14+
15+
cp "${srcdir}/openshift-logging.yaml" /tmp
16+
17+
local YAML_FILE="/tmp/openshift-logging.yaml"
18+
19+
$OSCAP oval eval --results $RF $DF
20+
21+
if [ -f $RF ]; then
22+
verify_results "def" $DF $RF 2 && verify_results "tst" $DF $RF 3
23+
ret_val=$?
24+
else
25+
ret_val=1
26+
fi
27+
28+
rm -f $YAML_FILE
29+
30+
return $ret_val
31+
}
32+
33+
test_probes_yamlfilecontent_array
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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="get_indexed_array" test_ref="oval:0:tst:1"/>
20+
<criterion comment="get_range_array" test_ref="oval:0:tst:2"/>
21+
</criteria>
22+
</definition>
23+
24+
<definition class="compliance" version="1" id="oval:0:def:2"> <!-- comment="error" -->
25+
<metadata>
26+
<title></title>
27+
<description></description>
28+
</metadata>
29+
<criteria operator="AND">
30+
<criterion comment="get_non_scalar_array" test_ref="oval:0:tst:3"/>
31+
</criteria>
32+
</definition>
33+
34+
</definitions>
35+
36+
<tests>
37+
38+
<ind-def:yamlfilecontent_test version="1" id="oval:0:tst:1" check="all" comment="true">
39+
<ind-def:object object_ref="oval:0:obj:1"/>
40+
<ind-def:state state_ref="oval:0:ste:1"/>
41+
</ind-def:yamlfilecontent_test>
42+
43+
<ind-def:yamlfilecontent_test version="1" id="oval:0:tst:2" check="all" comment="true">
44+
<ind-def:object object_ref="oval:0:obj:2"/>
45+
<ind-def:state state_ref="oval:0:ste:2"/>
46+
</ind-def:yamlfilecontent_test>
47+
48+
<ind-def:yamlfilecontent_test version="1" id="oval:0:tst:3" check="all" comment="error">
49+
<ind-def:object object_ref="oval:0:obj:3"/>
50+
</ind-def:yamlfilecontent_test>
51+
52+
</tests>
53+
54+
<objects>
55+
56+
<ind-def:yamlfilecontent_object version="1" id="oval:0:obj:1">
57+
<ind-def:path>/tmp</ind-def:path>
58+
<ind-def:filename>openshift-logging.yaml</ind-def:filename>
59+
<ind-def:yamlpath>.spec.outputs[2].name</ind-def:yamlpath>
60+
</ind-def:yamlfilecontent_object>
61+
62+
<ind-def:yamlfilecontent_object version="1" id="oval:0:obj:2">
63+
<ind-def:path>/tmp</ind-def:path>
64+
<ind-def:filename>openshift-logging.yaml</ind-def:filename>
65+
<ind-def:yamlpath>.spec.outputs[0:2].name</ind-def:yamlpath>
66+
</ind-def:yamlfilecontent_object>
67+
68+
<ind-def:yamlfilecontent_object version="1" id="oval:0:obj:3">
69+
<ind-def:path>/tmp</ind-def:path>
70+
<ind-def:filename>openshift-logging.yaml</ind-def:filename>
71+
<ind-def:yamlpath>.spec.outputs[0]</ind-def:yamlpath>
72+
</ind-def:yamlfilecontent_object>
73+
74+
</objects>
75+
76+
<states>
77+
78+
<ind-def:yamlfilecontent_state version="1" id="oval:0:ste:1">
79+
<ind-def:value_of datatype="string">secureforward-offcluster</ind-def:value_of>
80+
</ind-def:yamlfilecontent_state>
81+
82+
<ind-def:yamlfilecontent_state version="1" id="oval:0:ste:2">
83+
<ind-def:value_of datatype="string" var_ref="oval:0:var:2"/>
84+
</ind-def:yamlfilecontent_state>
85+
86+
</states>
87+
88+
<variables>
89+
90+
<local_variable comment="variable with two values" datatype="string" version="1" id="oval:0:var:2">
91+
<!-- The use of split should force creation of a local variable with two values
92+
NOTE: Wildly untested! -->
93+
<split delimiter="|">
94+
<literal_component>elasticsearch|elasticsearch-insecure</literal_component>
95+
</split>
96+
</local_variable>
97+
98+
</variables>
99+
</oval_definitions>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
. $builddir/tests/test_common.sh
4+
5+
function test_probes_yamlfilecontent_key {
6+
7+
probecheck "yamlfilecontent" || return 255
8+
9+
local ret_val=0
10+
local DF="${srcdir}/test_probes_yamlfilecontent_key.xml"
11+
local RF="results.xml"
12+
13+
[ -f $RF ] && rm -f $RF
14+
15+
cp "${srcdir}/openshift-logging.yaml" /tmp
16+
17+
local YAML_FILE="/tmp/openshift-logging.yaml"
18+
19+
$OSCAP oval eval --results $RF $DF
20+
21+
if [ -f $RF ]; then
22+
verify_results "def" $DF $RF 3 && verify_results "tst" $DF $RF 4
23+
ret_val=$?
24+
else
25+
ret_val=1
26+
fi
27+
28+
rm -f $YAML_FILE
29+
30+
return $ret_val
31+
}
32+
33+
test_probes_yamlfilecontent_key
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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="get_root_scalar" test_ref="oval:0:tst:1"/>
20+
<criterion comment="get_nested_scalar" test_ref="oval:0:tst:2"/>
21+
</criteria>
22+
</definition>
23+
24+
<definition class="compliance" version="1" id="oval:0:def:2"> <!-- comment="error" -->
25+
<metadata>
26+
<title></title>
27+
<description></description>
28+
</metadata>
29+
<criteria operator="AND">
30+
<criterion comment="get_non_scalar" test_ref="oval:0:tst:3"/>
31+
</criteria>
32+
</definition>
33+
34+
<definition class="compliance" version="1" id="oval:0:def:3"> <!-- comment="false" -->
35+
<metadata>
36+
<title></title>
37+
<description></description>
38+
</metadata>
39+
<criteria operator="AND">
40+
<criterion comment="get_non_existing_scalar" test_ref="oval:0:tst:4"/>
41+
</criteria>
42+
</definition>
43+
44+
</definitions>
45+
46+
<tests>
47+
48+
<ind-def:yamlfilecontent_test version="1" id="oval:0:tst:1" check="all" comment="true">
49+
<ind-def:object object_ref="oval:0:obj:1"/>
50+
<ind-def:state state_ref="oval:0:ste:1"/>
51+
</ind-def:yamlfilecontent_test>
52+
53+
<ind-def:yamlfilecontent_test version="1" id="oval:0:tst:2" check="all" comment="true">
54+
<ind-def:object object_ref="oval:0:obj:2"/>
55+
<ind-def:state state_ref="oval:0:ste:2"/>
56+
</ind-def:yamlfilecontent_test>
57+
58+
<ind-def:yamlfilecontent_test version="1" id="oval:0:tst:3" check="all" comment="error">
59+
<ind-def:object object_ref="oval:0:obj:3"/>
60+
</ind-def:yamlfilecontent_test>
61+
62+
<ind-def:yamlfilecontent_test version="1" id="oval:0:tst:4" check="all" comment="false">
63+
<ind-def:object object_ref="oval:0:obj:4"/>
64+
</ind-def:yamlfilecontent_test>
65+
66+
</tests>
67+
68+
<objects>
69+
70+
<ind-def:yamlfilecontent_object version="1" id="oval:0:obj:1">
71+
<ind-def:path>/tmp</ind-def:path>
72+
<ind-def:filename>openshift-logging.yaml</ind-def:filename>
73+
<ind-def:yamlpath>.kind</ind-def:yamlpath>
74+
</ind-def:yamlfilecontent_object>
75+
76+
<ind-def:yamlfilecontent_object version="1" id="oval:0:obj:2">
77+
<ind-def:path>/tmp</ind-def:path>
78+
<ind-def:filename>openshift-logging.yaml</ind-def:filename>
79+
<ind-def:yamlpath>.metadata.namespace</ind-def:yamlpath>
80+
</ind-def:yamlfilecontent_object>
81+
82+
<ind-def:yamlfilecontent_object version="1" id="oval:0:obj:3">
83+
<ind-def:path>/tmp</ind-def:path>
84+
<ind-def:filename>openshift-logging.yaml</ind-def:filename>
85+
<ind-def:yamlpath>.metadata</ind-def:yamlpath>
86+
</ind-def:yamlfilecontent_object>
87+
88+
<ind-def:yamlfilecontent_object version="1" id="oval:0:obj:4">
89+
<ind-def:path>/tmp</ind-def:path>
90+
<ind-def:filename>openshift-logging.yaml</ind-def:filename>
91+
<ind-def:yamlpath>.doesnt.exist</ind-def:yamlpath>
92+
</ind-def:yamlfilecontent_object>
93+
94+
</objects>
95+
96+
<states>
97+
98+
<ind-def:yamlfilecontent_state version="1" id="oval:0:ste:1">
99+
<ind-def:value_of datatype="string">LogForwarding</ind-def:value_of>
100+
</ind-def:yamlfilecontent_state>
101+
102+
<ind-def:yamlfilecontent_state version="1" id="oval:0:ste:2">
103+
<ind-def:value_of datatype="string">openshift-logging</ind-def:value_of>
104+
</ind-def:yamlfilecontent_state>
105+
106+
</states>
107+
108+
</oval_definitions>

0 commit comments

Comments
 (0)