Skip to content

Commit 9f83ba0

Browse files
authored
Merge pull request #1991 from jan-cerny/issue1817
Fix issues when parsing profiles
2 parents 2fb46d9 + 953ecd9 commit 9f83ba0

7 files changed

+216
-1
lines changed

src/XCCDF/profile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,15 @@ struct xccdf_item *xccdf_profile_parse(xmlTextReaderPtr reader, struct xccdf_ite
287287
}
288288
case XCCDFE_SET_VALUE:{
289289
oscap_list_add(prof->sub.profile.setvalues, xccdf_setvalue_new_parse(reader));
290+
xmlTextReaderRead(reader);
290291
break;
291292
}
292293
default:
293294
if (!xccdf_item_process_element(prof, reader))
294295
dW("Encountered an unknown element '%s' while parsing XCCDF profile.",
295296
xmlTextReaderConstLocalName(reader));
297+
xmlTextReaderRead(reader);
296298
}
297-
xmlTextReaderRead(reader);
298299
}
299300

300301
return prof;

tests/API/XCCDF/unittests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,5 @@ add_oscap_test("test_generate_fix_ansible_vars.sh")
106106
add_oscap_test("test_xccdf_requires_conflicts.sh")
107107
add_oscap_test("test_results_hostname.sh")
108108
add_oscap_test("test_skip_rule.sh")
109+
add_oscap_test("test_no_newline_between_select_elements.sh")
110+
add_oscap_test("test_single_line_tailoring.sh")
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
. $builddir/tests/test_common.sh
3+
4+
set -e
5+
set -o pipefail
6+
7+
stdout=$(mktemp)
8+
9+
$OSCAP xccdf eval --progress --profile "xccdf_com.example.www_profile_test" "$srcdir/test_no_newline_between_select_elements.xml" > "$stdout" || true
10+
11+
# test if both rules selected in the profile were evaluated
12+
grep -q "xccdf_com.example.www_rule_first:pass" "$stdout"
13+
grep -q "xccdf_com.example.www_rule_second:fail" "$stdout"
14+
15+
rm -f "$stdout"
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<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" id="scap_org.open-scap_collection_from_xccdf_test_single_rule.xccdf.xml" schematron-version="1.2">
3+
<ds:data-stream id="scap_org.open-scap_datastream_from_xccdf_test_single_rule.xccdf.xml" scap-version="1.2" use-case="OTHER">
4+
<ds:checklists>
5+
<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">
6+
<cat:catalog>
7+
<cat:uri name="test_single_rule.oval.xml" uri="#scap_org.open-scap_cref_test_single_rule.oval.xml"/>
8+
</cat:catalog>
9+
</ds:component-ref>
10+
</ds:checklists>
11+
<ds:checks>
12+
<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"/>
13+
</ds:checks>
14+
</ds:data-stream>
15+
<ds:component id="scap_org.open-scap_comp_test_single_rule.xccdf.xml" timestamp="2017-06-09T09:15:45">
16+
<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">
17+
<status>accepted</status>
18+
<version>1.0</version>
19+
<Profile id="xccdf_com.example.www_profile_test">
20+
<title>xccdf_test_profile</title>
21+
<description>This profile is for testing.</description>
22+
<select idref="xccdf_com.example.www_rule_first" selected="true"/><select idref="xccdf_com.example.www_rule_second" selected="true"/>
23+
</Profile>
24+
<Rule selected="false" id="xccdf_com.example.www_rule_first">
25+
<title>This rule always pass</title>
26+
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
27+
<check-content-ref href="test_single_rule.oval.xml" name="oval:x:def:1"/>
28+
</check>
29+
</Rule>
30+
<Rule selected="false" id="xccdf_com.example.www_rule_second">
31+
<title>This rule always fails</title>
32+
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
33+
<check-content-ref href="test_single_rule.oval.xml" name="oval:x:def:2"/>
34+
</check>
35+
</Rule>
36+
</Benchmark>
37+
</ds:component>
38+
<ds:component id="scap_org.open-scap_comp_test_single_rule.oval.xml" timestamp="2017-06-09T07:07:38">
39+
<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">
40+
<generator>
41+
<oval:schema_version>5.11</oval:schema_version>
42+
<oval:timestamp>2009-01-12T10:41:00-05:00</oval:timestamp>
43+
</generator>
44+
<definitions>
45+
<definition class="compliance" id="oval:x:def:1" version="1">
46+
<metadata>
47+
<title>PASS</title>
48+
<description>pass</description>
49+
</metadata>
50+
<criteria>
51+
<criterion comment="PASS test" test_ref="oval:x:tst:1"/>
52+
</criteria>
53+
</definition>
54+
<definition class="compliance" id="oval:x:def:2" version="1">
55+
<metadata>
56+
<title>PASS</title>
57+
<description>pass</description>
58+
</metadata>
59+
<criteria>
60+
<criterion negate="true" comment="PASS test" test_ref="oval:x:tst:1"/>
61+
</criteria>
62+
</definition>
63+
</definitions>
64+
<tests>
65+
<variable_test xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" id="oval:x:tst:1" check="all" comment="always pass" version="1">
66+
<object object_ref="oval:x:obj:1"/>
67+
</variable_test>
68+
</tests>
69+
<objects>
70+
<variable_object xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" id="oval:x:obj:1" version="1" comment="x">
71+
<var_ref>oval:x:var:1</var_ref>
72+
</variable_object>
73+
</objects>
74+
<variables>
75+
<constant_variable id="oval:x:var:1" version="1" comment="x" datatype="int">
76+
<value>100</value>
77+
</constant_variable>
78+
</variables>
79+
</oval_definitions>
80+
</ds:component>
81+
</ds:data-stream-collection>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
. $builddir/tests/test_common.sh
3+
4+
set -e
5+
set -o pipefail
6+
7+
result=$(mktemp)
8+
9+
$OSCAP xccdf eval --profile "xccdf_com.example.www_profile_custom" --results "$result" --tailoring-file "$srcdir/test_single_line_tailoring.tailoring.xml" "$srcdir/test_single_line_tailoring.xml"
10+
11+
assert_exists 1 '//rule-result[@idref="xccdf_com.example.www_rule_R1"]/result[text()="pass"]'
12+
assert_exists 1 '//rule-result[@idref="xccdf_com.example.www_rule_R2"]/result[text()="notselected"]'
13+
assert_exists 1 '//rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="notselected"]'
14+
assert_exists 1 '//rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="notselected"]'
15+
16+
rm -f "$result"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<xccdf-1.2:Tailoring xmlns:xccdf-1.2="http://checklists.nist.gov/xccdf/1.2" id="xccdf_auto_tailoring_default"><xccdf-1.2:benchmark href="file:///home/jcerny/work/git/openscap/tests/API/XCCDF/unittests/tests/API/XCCDF/unittests/test_single_line_tailoring.xml" /><xccdf-1.2:version time="2023-06-20T13:57:09.735106">1</xccdf-1.2:version><xccdf-1.2:Profile id="xccdf_com.example.www_profile_custom" extends="xccdf_com.example.www_profile_P1"><xccdf-1.2:title override="false" /><xccdf-1.2:select idref="xccdf_com.example.www_rule_R2" selected="false" /><xccdf-1.2:select idref="xccdf_com.example.www_rule_R3" selected="false" /><xccdf-1.2:select idref="xccdf_com.example.www_rule_R4" selected="false" /></xccdf-1.2:Profile></xccdf-1.2:Tailoring>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<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">
3+
<ds:data-stream id="scap_org.open-scap_datastream_simple" scap-version="1.3" use-case="OTHER">
4+
<ds:checklists>
5+
<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">
6+
<cat:catalog>
7+
<cat:uri name="test_single_rule.oval.xml" uri="#scap_org.open-scap_cref_test_single_rule.oval.xml"/>
8+
</cat:catalog>
9+
</ds:component-ref>
10+
</ds:checklists>
11+
<ds:checks>
12+
<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"/>
13+
</ds:checks>
14+
</ds:data-stream>
15+
<ds:component id="scap_org.open-scap_comp_test_single_rule.oval.xml" timestamp="2021-02-01T08:07:06+01:00">
16+
<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">
17+
<generator>
18+
<oval:schema_version>5.11.2</oval:schema_version>
19+
<oval:timestamp>2021-02-01T08:07:06+01:00</oval:timestamp>
20+
</generator>
21+
<definitions>
22+
<definition class="compliance" id="oval:x:def:1" version="1">
23+
<metadata>
24+
<title>PASS</title>
25+
<description>pass</description>
26+
</metadata>
27+
<criteria>
28+
<criterion comment="PASS test" test_ref="oval:x:tst:1"/>
29+
</criteria>
30+
</definition>
31+
</definitions>
32+
<tests>
33+
<variable_test xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" id="oval:x:tst:1" check="all" comment="always pass" version="1">
34+
<object object_ref="oval:x:obj:1"/>
35+
</variable_test>
36+
</tests>
37+
<objects>
38+
<variable_object xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" id="oval:x:obj:1" version="1" comment="x">
39+
<var_ref>oval:x:var:1</var_ref>
40+
</variable_object>
41+
</objects>
42+
<variables>
43+
<constant_variable id="oval:x:var:1" version="1" comment="x" datatype="int">
44+
<value>100</value>
45+
</constant_variable>
46+
</variables>
47+
</oval_definitions>
48+
</ds:component>
49+
<ds:component id="scap_org.open-scap_comp_test_single_rule.xccdf.xml" timestamp="2021-02-01T08:07:06+01:00">
50+
<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">
51+
<status date="2021-01-21">accepted</status>
52+
<title>Test Benchmark</title>
53+
<description>Description</description>
54+
<version>1.0</version>
55+
<metadata>
56+
<dc:contributor xmlns:dc="http://purl.org/dc/elements/1.1/">OpenSCAP</dc:contributor>
57+
<dc:publisher xmlns:dc="http://purl.org/dc/elements/1.1/">OpenSCAP</dc:publisher>
58+
<dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">OpenSCAP</dc:creator>
59+
<dc:source xmlns:dc="http://purl.org/dc/elements/1.1/">http://scap.nist.gov</dc:source>
60+
</metadata>
61+
<Profile id="xccdf_com.example.www_profile_P1">
62+
<title>xccdf_test_profile</title>
63+
<description>This profile is for testing.</description>
64+
<select idref="xccdf_com.example.www_rule_R1" selected="true"/>
65+
<select idref="xccdf_com.example.www_rule_R2" selected="true"/>
66+
<select idref="xccdf_com.example.www_rule_R3" selected="true"/>
67+
<select idref="xccdf_com.example.www_rule_R4" selected="true"/>
68+
</Profile>
69+
<Rule selected="false" id="xccdf_com.example.www_rule_R1">
70+
<title>Rule R1</title>
71+
<description>Description</description>
72+
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
73+
<check-content-ref href="test_single_rule.oval.xml" name="oval:x:def:1"/>
74+
</check>
75+
</Rule>
76+
<Rule selected="false" id="xccdf_com.example.www_rule_R2">
77+
<title>Rule R2</title>
78+
<description>Description</description>
79+
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
80+
<check-content-ref href="test_single_rule.oval.xml" name="oval:x:def:1"/>
81+
</check>
82+
</Rule>
83+
<Rule selected="false" id="xccdf_com.example.www_rule_R3">
84+
<title>Rule R3</title>
85+
<description>Description</description>
86+
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
87+
<check-content-ref href="test_single_rule.oval.xml" name="oval:x:def:1"/>
88+
</check>
89+
</Rule>
90+
<Rule selected="false" id="xccdf_com.example.www_rule_R4">
91+
<title>Rule R4</title>
92+
<description>Description</description>
93+
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
94+
<check-content-ref href="test_single_rule.oval.xml" name="oval:x:def:1"/>
95+
</check>
96+
</Rule>
97+
</Benchmark>
98+
</ds:component>
99+
</ds:data-stream-collection>

0 commit comments

Comments
 (0)