Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 2f14080

Browse files
authored
Merge pull request #216 from Honny1/fix-204
Fix issue with missing system data in the arf report
2 parents 7cb5d42 + 33e227d commit 2f14080

File tree

3 files changed

+305
-0
lines changed

3 files changed

+305
-0
lines changed

oval_graph/arf_xml_parser/_test_info.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def _get_oval_system_characteristics(self):
2323

2424
@staticmethod
2525
def _get_data_by_id(data):
26+
if data is None:
27+
return {}
2628
return {item.attrib.get('id'): item for item in data}
2729

2830
def _get_collected_objects_by_id(self):
@@ -99,6 +101,8 @@ def _get_object_info(self, id_object):
99101

100102
def _get_object_items(self, object_, collected_object):
101103
out = {}
104+
if object_ is None:
105+
return out
102106
for element in object_.iterchildren():
103107
if element.text and element.text.strip():
104108
out[self._get_unique_id_in_dict(element, out)] = element.text
@@ -134,6 +138,8 @@ def _collected_object_is_not_none_and_contain_var_ref(element, collected_object)
134138
def _get_item(self, item_ref):
135139
item = self.system_data.get(item_ref)
136140
out = {}
141+
if item is None:
142+
return out
137143
for element in item.iterchildren():
138144
if element.text and element.text.strip():
139145
out[self._get_unique_id_in_dict(element, out)] = element.text
Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<arf:asset-report-collection xmlns:arf="http://scap.nist.gov/schema/asset-reporting-format/1.1" xmlns:core="http://scap.nist.gov/schema/reporting-core/1.1" xmlns:ai="http://scap.nist.gov/schema/asset-identification/1.1">
3+
<core:relationships xmlns:arfvocab="http://scap.nist.gov/specifications/arf/vocabulary/relationships/1.0#">
4+
<core:relationship type="arfvocab:createdFor" subject="xccdf1">
5+
<core:ref>collection1</core:ref>
6+
</core:relationship>
7+
<core:relationship type="arfvocab:isAbout" subject="xccdf1">
8+
<core:ref>asset0</core:ref>
9+
</core:relationship>
10+
</core:relationships>
11+
<arf:report-requests>
12+
<arf:report-request id="collection1">
13+
<arf:content>
14+
<ds:data-stream-collection xmlns:ds="http://scap.nist.gov/schema/scap/source/1.2" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:cat="urn:oasis:names:tc:entity:xmlns:xml:catalog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="scap_org.open-scap_collection_from_xccdf_test_single_rule.xccdf.xml" schematron-version="1.3" xsi:schemaLocation="http://scap.nist.gov/schema/scap/source/1.2 https://scap.nist.gov/schema/scap/1.3/scap-source-data-stream_1.3.xsd">
15+
<ds:data-stream id="scap_org.open-scap_datastream_simple" scap-version="1.3" use-case="OTHER">
16+
<ds:checklists>
17+
<ds:component-ref id="scap_org.open-scap_cref_test_single_rule.xccdf.xml" xlink:href="#scap_org.open-scap_comp_test_single_rule.xccdf.xml">
18+
<cat:catalog>
19+
<cat:uri name="test_single_rule.oval.xml" uri="#scap_org.open-scap_cref_test_single_rule.oval.xml"/>
20+
</cat:catalog>
21+
</ds:component-ref>
22+
</ds:checklists>
23+
<ds:checks>
24+
<ds:component-ref id="scap_org.open-scap_cref_test_single_rule.oval.xml" xlink:href="#scap_org.open-scap_comp_test_single_rule.oval.xml"/>
25+
</ds:checks>
26+
</ds:data-stream>
27+
<ds:component id="scap_org.open-scap_comp_test_single_rule.oval.xml" timestamp="2021-02-01T08:07:06+01:00">
28+
<oval_definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5" xmlns:ind-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" xmlns:oval-def="http://oval.mitre.org/XMLSchema/oval-definitions-5" xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5" xmlns:win-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#windows" xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval-definitions-5 oval-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#independent independent-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#windows windows-definitions-schema.xsd">
29+
<generator>
30+
<oval:schema_version>5.11.2</oval:schema_version>
31+
<oval:timestamp>2021-02-01T08:07:06+01:00</oval:timestamp>
32+
</generator>
33+
<definitions>
34+
<definition class="compliance" id="oval:x:def:1" version="1">
35+
<metadata>
36+
<title>File not found</title>
37+
<description>File fail</description>
38+
</metadata>
39+
<criteria>
40+
<criterion comment="Fail test" test_ref="oval:x:tst:1"/>
41+
</criteria>
42+
</definition>
43+
</definitions>
44+
<tests>
45+
<textfilecontent54_test xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" id="oval:x:tst:1" version="1" check_existence="all_exist" check="all" comment="is file?">
46+
<object object_ref="oval:x:obj:1"/>
47+
</textfilecontent54_test>
48+
</tests>
49+
<objects>
50+
<textfilecontent54_object xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" id="oval:x:obj:1" version="1">
51+
<filepath>/nonexistent/file/random/nums/0112358132134</filepath>
52+
<pattern operation="pattern match">^0, 1, 1, 2, 3, 5, 8, 13, 21, 34$</pattern>
53+
<instance datatype="int">1</instance>
54+
</textfilecontent54_object>
55+
</objects>
56+
</oval_definitions>
57+
</ds:component>
58+
<ds:component id="scap_org.open-scap_comp_test_single_rule.xccdf.xml" timestamp="2021-02-01T08:07:06+01:00">
59+
<Benchmark xmlns="http://checklists.nist.gov/xccdf/1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="xccdf_com.example.www_benchmark_dummy" xsi:schemaLocation="http://checklists.nist.gov/xccdf/1.1 xccdf-1.1.4.xsd" resolved="false" xml:lang="en-US">
60+
<status date="2021-01-21">accepted</status>
61+
<version>1.0</version>
62+
<Profile xmlns:xhtml="http://www.w3.org/1999/xhtml" id="xccdf_com.example.www_profile_test_single_rule">
63+
<title>xccdf_test_profile</title>
64+
<select idref="xccdf_com.example.www_rule_test-fail" selected="true"/>
65+
</Profile>
66+
<Rule selected="true" id="xccdf_com.example.www_rule_test-fail">
67+
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
68+
<check-content-ref href="test_single_rule.oval.xml" name="oval:x:def:1"/>
69+
</check>
70+
</Rule>
71+
</Benchmark>
72+
</ds:component>
73+
</ds:data-stream-collection>
74+
</arf:content>
75+
</arf:report-request>
76+
</arf:report-requests>
77+
<arf:assets>
78+
<arf:asset id="asset0">
79+
<ai:computing-device>
80+
<ai:connections>
81+
<ai:connection>
82+
<ai:ip-address>
83+
<ai:ip-v4>127.0.0.1</ai:ip-v4>
84+
</ai:ip-address>
85+
</ai:connection>
86+
<ai:connection>
87+
<ai:ip-address>
88+
<ai:ip-v4>192.168.0.59</ai:ip-v4>
89+
</ai:ip-address>
90+
</ai:connection>
91+
<ai:connection>
92+
<ai:ip-address>
93+
<ai:ip-v4>192.168.122.1</ai:ip-v4>
94+
</ai:ip-address>
95+
</ai:connection>
96+
<ai:connection>
97+
<ai:ip-address>
98+
<ai:ip-v6>0:0:0:0:0:0:0:1</ai:ip-v6>
99+
</ai:ip-address>
100+
</ai:connection>
101+
<ai:connection>
102+
<ai:ip-address>
103+
<ai:ip-v6>fe80:0:0:0:33ef:8077:dfe0:4d7c</ai:ip-v6>
104+
</ai:ip-address>
105+
</ai:connection>
106+
<ai:connection>
107+
<ai:ip-address>
108+
<ai:ip-v6>fe80:0:0:0:fc01:f6ff:fe0f:32c8</ai:ip-v6>
109+
</ai:ip-address>
110+
</ai:connection>
111+
<ai:connection>
112+
<ai:mac-address>00:00:00:00:00:00</ai:mac-address>
113+
</ai:connection>
114+
<ai:connection>
115+
<ai:mac-address>00:2B:67:04:65:C0</ai:mac-address>
116+
</ai:connection>
117+
<ai:connection>
118+
<ai:mac-address>74:D8:3E:1A:0C:3E</ai:mac-address>
119+
</ai:connection>
120+
<ai:connection>
121+
<ai:mac-address>52:54:00:E8:16:C5</ai:mac-address>
122+
</ai:connection>
123+
<ai:connection>
124+
<ai:mac-address>FE:01:F6:0F:32:C8</ai:mac-address>
125+
</ai:connection>
126+
</ai:connections>
127+
<ai:fqdn>rh-hony</ai:fqdn>
128+
<ai:hostname>rh-hony</ai:hostname>
129+
</ai:computing-device>
130+
</arf:asset>
131+
</arf:assets>
132+
<arf:reports>
133+
<arf:report id="xccdf1">
134+
<arf:content>
135+
<TestResult xmlns="http://checklists.nist.gov/xccdf/1.2" id="xccdf_org.open-scap_testresult_default-profile" start-time="2021-12-10T16:05:06+01:00" end-time="2021-12-10T16:05:06+01:00" version="1.0" test-system="cpe:/a:redhat:openscap:1.3.5">
136+
<benchmark href="#scap_org.open-scap_comp_test_single_rule.xccdf.xml" id="xccdf_com.example.www_benchmark_dummy"/>
137+
<title>OSCAP Scan Result</title>
138+
<identity authenticated="false" privileged="false">jrodak</identity>
139+
<target>rh-hony</target>
140+
<target-address>127.0.0.1</target-address>
141+
<target-address>192.168.0.59</target-address>
142+
<target-address>192.168.122.1</target-address>
143+
<target-address>0:0:0:0:0:0:0:1</target-address>
144+
<target-address>fe80:0:0:0:33ef:8077:dfe0:4d7c</target-address>
145+
<target-address>fe80:0:0:0:fc01:f6ff:fe0f:32c8</target-address>
146+
<target-facts>
147+
<fact name="urn:xccdf:fact:scanner:name" type="string">OpenSCAP</fact>
148+
<fact name="urn:xccdf:fact:scanner:version" type="string">1.3.5</fact>
149+
<fact name="urn:xccdf:fact:asset:identifier:fqdn" type="string">rh-hony</fact>
150+
<fact name="urn:xccdf:fact:asset:identifier:host_name" type="string">rh-hony</fact>
151+
<fact name="urn:xccdf:fact:ethernet:MAC" type="string">00:00:00:00:00:00</fact>
152+
<fact name="urn:xccdf:fact:asset:identifier:mac" type="string">00:00:00:00:00:00</fact>
153+
<fact name="urn:xccdf:fact:ethernet:MAC" type="string">00:2B:67:04:65:C0</fact>
154+
<fact name="urn:xccdf:fact:asset:identifier:mac" type="string">00:2B:67:04:65:C0</fact>
155+
<fact name="urn:xccdf:fact:ethernet:MAC" type="string">74:D8:3E:1A:0C:3E</fact>
156+
<fact name="urn:xccdf:fact:asset:identifier:mac" type="string">74:D8:3E:1A:0C:3E</fact>
157+
<fact name="urn:xccdf:fact:ethernet:MAC" type="string">52:54:00:E8:16:C5</fact>
158+
<fact name="urn:xccdf:fact:asset:identifier:mac" type="string">52:54:00:E8:16:C5</fact>
159+
<fact name="urn:xccdf:fact:ethernet:MAC" type="string">FE:01:F6:0F:32:C8</fact>
160+
<fact name="urn:xccdf:fact:asset:identifier:mac" type="string">FE:01:F6:0F:32:C8</fact>
161+
<fact name="urn:xccdf:fact:asset:identifier:ipv4" type="string">127.0.0.1</fact>
162+
<fact name="urn:xccdf:fact:asset:identifier:ipv4" type="string">192.168.0.59</fact>
163+
<fact name="urn:xccdf:fact:asset:identifier:ipv4" type="string">192.168.122.1</fact>
164+
<fact name="urn:xccdf:fact:asset:identifier:ipv6" type="string">::1</fact>
165+
<fact name="urn:xccdf:fact:asset:identifier:ipv6" type="string">fe80::33ef:8077:dfe0:4d7c</fact>
166+
<fact name="urn:xccdf:fact:asset:identifier:ipv6" type="string">fe80::fc01:f6ff:fe0f:32c8</fact>
167+
</target-facts>
168+
<target-id-ref system="http://scap.nist.gov/schema/asset-identification/1.1" name="asset0" href=""/>
169+
<rule-result idref="xccdf_com.example.www_rule_test-fail" role="full" time="2021-12-10T16:05:06+01:00" severity="unknown" weight="1.000000">
170+
<result>fail</result>
171+
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
172+
<check-content-ref name="oval:x:def:1" href="#oval0"/>
173+
</check>
174+
</rule-result>
175+
<score system="urn:xccdf:scoring:default" maximum="100.000000">0.000000</score>
176+
</TestResult>
177+
</arf:content>
178+
</arf:report>
179+
<arf:report id="oval0">
180+
<arf:content>
181+
<oval_results xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5" xmlns="http://oval.mitre.org/XMLSchema/oval-results-5" xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval-results-5 oval-results-schema.xsd http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd">
182+
<generator>
183+
<oval:product_name>cpe:/a:open-scap:oscap</oval:product_name>
184+
<oval:product_version>1.3.5</oval:product_version>
185+
<oval:schema_version>5.11.2</oval:schema_version>
186+
<oval:timestamp>2021-12-10T16:05:06</oval:timestamp>
187+
</generator>
188+
<directives>
189+
<definition_true reported="true" content="full"/>
190+
<definition_false reported="true" content="full"/>
191+
<definition_unknown reported="true" content="full"/>
192+
<definition_error reported="true" content="full"/>
193+
<definition_not_evaluated reported="true" content="full"/>
194+
<definition_not_applicable reported="true" content="full"/>
195+
</directives>
196+
<oval_definitions xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5" xmlns:unix-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix" xmlns:ind-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" xmlns:lin-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux" xmlns:win-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#windows" xmlns:mac-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#macos" 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#unix unix-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#linux linux-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#windows windows-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#macos macos-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">
197+
<generator>
198+
<oval:schema_version>5.11.2</oval:schema_version>
199+
<oval:timestamp>2021-02-01T08:07:06+01:00</oval:timestamp>
200+
</generator>
201+
<definitions>
202+
<definition id="oval:x:def:1" version="1" class="compliance">
203+
<metadata>
204+
<title>File not found</title>
205+
<description>File fail</description>
206+
</metadata>
207+
<criteria>
208+
<criterion test_ref="oval:x:tst:1" comment="Fail test"/>
209+
</criteria>
210+
</definition>
211+
</definitions>
212+
<tests>
213+
<ind-def:textfilecontent54_test id="oval:x:tst:1" version="1" check_existence="all_exist" check="all" comment="is file?">
214+
<ind-def:object object_ref="oval:x:obj:1"/>
215+
</ind-def:textfilecontent54_test>
216+
</tests>
217+
<objects>
218+
<ind-def:textfilecontent54_object id="oval:x:obj:1" version="1">
219+
<ind-def:filepath>/nonexistent/file/random/nums/0112358132134</ind-def:filepath>
220+
<ind-def:pattern operation="pattern match">^0, 1, 1, 2, 3, 5, 8, 13, 21, 34$</ind-def:pattern>
221+
<ind-def:instance datatype="int">1</ind-def:instance>
222+
</ind-def:textfilecontent54_object>
223+
</objects>
224+
</oval_definitions>
225+
<results>
226+
<system>
227+
<definitions>
228+
<definition definition_id="oval:x:def:1" result="false" version="1">
229+
<criteria operator="AND" result="false">
230+
<criterion test_ref="oval:x:tst:1" version="1" result="false"/>
231+
</criteria>
232+
</definition>
233+
</definitions>
234+
<tests>
235+
<test test_id="oval:x:tst:1" version="1" check_existence="all_exist" check="all" result="false"/>
236+
</tests>
237+
<oval_system_characteristics xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5" xmlns:unix-sys="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#unix" xmlns:ind-sys="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#independent" xmlns:lin-sys="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#linux" xmlns:win-sys="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#windows" xmlns="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5" xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5 oval-system-characteristics-schema.xsd http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#independent independent-system-characteristics-schema.xsd http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#unix unix-system-characteristics-schema.xsd http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#linux linux-system-characteristics-schema.xsd http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#windows windows-system-characteristics-schema.xsd http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#macos macos-system-characteristics-schema.xsd http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd">
238+
<generator>
239+
<oval:product_name>cpe:/a:open-scap:oscap</oval:product_name>
240+
<oval:schema_version>5.11.2</oval:schema_version>
241+
<oval:timestamp>2021-12-10T16:05:06</oval:timestamp>
242+
</generator>
243+
<system_info>
244+
<os_name>Fedora</os_name>
245+
<os_version>34 (Workstation Edition)</os_version>
246+
<architecture>x86_64</architecture>
247+
<primary_host_name>rh-hony</primary_host_name>
248+
<interfaces>
249+
<interface>
250+
<interface_name>lo</interface_name>
251+
<ip_address>127.0.0.1</ip_address>
252+
<mac_address>00:00:00:00:00:00</mac_address>
253+
</interface>
254+
<interface>
255+
<interface_name>wlp0s20f3</interface_name>
256+
<ip_address>192.168.0.59</ip_address>
257+
<mac_address>74:D8:3E:1A:0C:3E</mac_address>
258+
</interface>
259+
<interface>
260+
<interface_name>virbr0</interface_name>
261+
<ip_address>192.168.122.1</ip_address>
262+
<mac_address>52:54:00:E8:16:C5</mac_address>
263+
</interface>
264+
<interface>
265+
<interface_name>lo</interface_name>
266+
<ip_address>::1</ip_address>
267+
<mac_address>00:00:00:00:00:00</mac_address>
268+
</interface>
269+
<interface>
270+
<interface_name>wlp0s20f3</interface_name>
271+
<ip_address>fe80::33ef:8077:dfe0:4d7c</ip_address>
272+
<mac_address>74:D8:3E:1A:0C:3E</mac_address>
273+
</interface>
274+
<interface>
275+
<interface_name>tap0</interface_name>
276+
<ip_address>fe80::fc01:f6ff:fe0f:32c8</ip_address>
277+
<mac_address>FE:01:F6:0F:32:C8</mac_address>
278+
</interface>
279+
</interfaces>
280+
</system_info>
281+
<collected_objects>
282+
<object id="oval:x:obj:1" version="1" flag="does not exist"/>
283+
</collected_objects>
284+
</oval_system_characteristics>
285+
</system>
286+
</results>
287+
</oval_results>
288+
</arf:content>
289+
</arf:report>
290+
</arf:reports>
291+
</arf:asset-report-collection>

0 commit comments

Comments
 (0)