Skip to content

Commit 55ab772

Browse files
committed
Add simple tests for yamlprobe
1 parent 79a06d4 commit 55ab772

File tree

5 files changed

+210
-0
lines changed

5 files changed

+210
-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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
if(ENABLE_PROBES_INDEPENDENT)
2+
add_oscap_test("test_probes_yamlfilecontent.sh")
3+
endif()
4+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
secret:
13+
name: fluentd
14+
- type: "elasticsearch"
15+
name: elasticsearch-insecure
16+
endpoint: elasticsearch-insecure.svc.messaging.cluster.local
17+
insecure: true
18+
- type: "forward"
19+
name: secureforward-offcluster
20+
endpoint: https://secureforward.offcluster.com:9200
21+
secret:
22+
name: secureforward
23+
pipelines:
24+
- name: container-logs
25+
inputSource: logs.app
26+
outputRefs:
27+
- elasticsearch
28+
- secureforward-offcluster
29+
- name: infra-logs
30+
inputSource: logs.infra
31+
outputRefs:
32+
- elasticsearch-insecure
33+
- name: audit-logs
34+
inputSource: logs.audit
35+
outputRefs:
36+
- 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 {
6+
7+
probecheck "yamlfilecontent" || return 255
8+
9+
local ret_val=0;
10+
local DF="${srcdir}/test_probes_yamlfilecontent.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 5
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
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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.10</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+
<criterion comment="filtered_get" test_ref="oval:0:tst:3"/>
22+
<criterion comment="filtered_get_multiple" test_ref="oval:0:tst:4"/>
23+
</criteria>
24+
</definition>
25+
26+
<definition class="compliance" version="1" id="oval:0:def:2"> <!-- comment="error" -->
27+
<metadata>
28+
<title></title>
29+
<description></description>
30+
</metadata>
31+
<criteria operator="AND">
32+
<criterion comment="non_scalar_get" test_ref="oval:0:tst:5"/>
33+
</criteria>
34+
</definition>
35+
36+
</definitions>
37+
38+
<tests>
39+
40+
<ind-def:yamlfilecontent_test version="1" id="oval:0:tst:1" check="all" comment="true">
41+
<ind-def:object object_ref="oval:0:obj:1"/>
42+
<ind-def:state state_ref="oval:0:ste:1"/>
43+
</ind-def:yamlfilecontent_test>
44+
45+
<ind-def:yamlfilecontent_test version="1" id="oval:0:tst:2" check="all" comment="true">
46+
<ind-def:object object_ref="oval:0:obj:2"/>
47+
<ind-def:state state_ref="oval:0:ste:2"/>
48+
</ind-def:yamlfilecontent_test>
49+
50+
<ind-def:yamlfilecontent_test version="1" id="oval:0:tst:3" check="all" comment="true">
51+
<ind-def:object object_ref="oval:0:obj:3"/>
52+
<ind-def:state state_ref="oval:0:ste:3"/>
53+
</ind-def:yamlfilecontent_test>
54+
55+
<ind-def:yamlfilecontent_test version="1" id="oval:0:tst:4" check="all" comment="true">
56+
<ind-def:object object_ref="oval:0:obj:4"/>
57+
<ind-def:state state_ref="oval:0:ste:4"/>
58+
</ind-def:yamlfilecontent_test>
59+
60+
<ind-def:yamlfilecontent_test version="1" id="oval:0:tst:5" check="all" comment="error">
61+
<ind-def:object object_ref="oval:0:obj:5"/>
62+
</ind-def:yamlfilecontent_test>
63+
64+
</tests>
65+
66+
<objects>
67+
68+
<ind-def:yamlfilecontent_object version="1" id="oval:0:obj:1">
69+
<ind-def:path>/tmp</ind-def:path>
70+
<ind-def:filename>openshift-logging.yaml</ind-def:filename>
71+
<ind-def:yamlpath>/kind</ind-def:yamlpath>
72+
<ind-def:instance operation="greater than or equal" datatype="int">0</ind-def:instance>
73+
</ind-def:yamlfilecontent_object>
74+
75+
<ind-def:yamlfilecontent_object version="1" id="oval:0:obj:2">
76+
<ind-def:path>/tmp</ind-def:path>
77+
<ind-def:filename>openshift-logging.yaml</ind-def:filename>
78+
<ind-def:yamlpath>/metadata/namespace</ind-def:yamlpath>
79+
<ind-def:instance operation="greater than or equal" datatype="int">0</ind-def:instance>
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>/spec/outputs[type=forward]/name</ind-def:yamlpath>
86+
<ind-def:instance operation="greater than or equal" datatype="int">0</ind-def:instance>
87+
</ind-def:yamlfilecontent_object>
88+
89+
<ind-def:yamlfilecontent_object version="1" id="oval:0:obj:4">
90+
<ind-def:path>/tmp</ind-def:path>
91+
<ind-def:filename>openshift-logging.yaml</ind-def:filename>
92+
<ind-def:yamlpath>/spec/outputs[type=elasticsearch]/name</ind-def:yamlpath>
93+
<ind-def:instance operation="greater than or equal" datatype="int">0</ind-def:instance>
94+
</ind-def:yamlfilecontent_object>
95+
96+
<ind-def:yamlfilecontent_object version="1" id="oval:0:obj:5">
97+
<ind-def:path>/tmp</ind-def:path>
98+
<ind-def:filename>openshift-logging.yaml</ind-def:filename>
99+
<ind-def:yamlpath>/spec/outputs[type=elasticsearch]</ind-def:yamlpath>
100+
<ind-def:instance operation="greater than or equal" datatype="int">0</ind-def:instance>
101+
</ind-def:yamlfilecontent_object>
102+
103+
</objects>
104+
105+
<states>
106+
107+
<ind-def:yamlfilecontent_state version="1" id="oval:0:ste:1">
108+
<ind-def:value-of datatype="string">LogForwarding</ind-def:value-of>
109+
</ind-def:yamlfilecontent_state>
110+
111+
<ind-def:yamlfilecontent_state version="1" id="oval:0:ste:2">
112+
<ind-def:value-of datatype="string">openshift-logging</ind-def:value-of>
113+
</ind-def:yamlfilecontent_state>
114+
115+
<ind-def:yamlfilecontent_state version="1" id="oval:0:ste:3">
116+
<ind-def:value-of datatype="string">secureforward-offcluster</ind-def:value-of>
117+
</ind-def:yamlfilecontent_state>
118+
119+
<ind-def:yamlfilecontent_state version="1" id="oval:0:ste:4">
120+
<ind-def:value-of datatype="string" var_ref="oval:0:var:4"/>
121+
</ind-def:yamlfilecontent_state>
122+
123+
</states>
124+
125+
<variables>
126+
127+
<local_variable comment="oval:0:var:3" datatype="string" version="1" id="">
128+
<!-- The use of split should force creation of a local variable with two values
129+
NOTE: Wildly untested! -->
130+
<split delimiter="|">
131+
<literal_component>elasticsearch|elasticsearch-insecure</literal_component>
132+
</split>
133+
</local_variable>
134+
135+
</variables>
136+
</oval_definitions>

0 commit comments

Comments
 (0)