Skip to content

Commit 8457c92

Browse files
committed
Add a simple test for oscap info
This test tests if `oscap` is able to detect the version of SCAP source datastream (if DS is SCAP 1.2 or 1.3).
1 parent 190ca9d commit 8457c92

File tree

7 files changed

+145
-1
lines changed

7 files changed

+145
-1
lines changed

ac_probes/configure.ac.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ AC_CONFIG_FILES([Makefile
728728
src/DS/Makefile
729729
tests/DS/Makefile
730730
tests/DS/ds_sds_index/Makefile
731+
tests/DS/sds_detect_version/Makefile
731732
tests/DS/signed/Makefile
732733
tests/DS/validate/Makefile
733734

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,7 @@ AC_CONFIG_FILES([Makefile
15481548
src/DS/Makefile
15491549
tests/DS/Makefile
15501550
tests/DS/ds_sds_index/Makefile
1551+
tests/DS/sds_detect_version/Makefile
15511552
tests/DS/signed/Makefile
15521553
tests/DS/validate/Makefile
15531554

tests/DS/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ EXTRA_DIST = test_ds.sh \
6060
sds_subdir/subdir/scap-fedora14-xccdf.xml \
6161
sds_tailoring/sds.ds.xml
6262

63-
SUBDIRS = ds_sds_index signed validate
63+
SUBDIRS = ds_sds_index signed validate sds_detect_version
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
DISTCLEANFILES = *.log *.results oscap_debug.log.*
2+
CLEANFILES = *.log *.results oscap_debug.log.*
3+
4+
TESTS_ENVIRONMENT= \
5+
builddir=$(top_builddir) \
6+
OSCAP_FULL_VALIDATION=1 \
7+
$(top_builddir)/run
8+
9+
TESTS = test_detect_version.sh
10+
11+
EXTRA_DIST = test_detect_version.sh \
12+
scap-1.2-ds.xml \
13+
scap-1.3-ds.xml
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0"?>
2+
<ns0:data-stream-collection xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:ns0="http://scap.nist.gov/schema/scap/source/1.2" xmlns:ns1="http://www.w3.org/1999/xlink" xmlns:ns10="http://checklists.nist.gov/xccdf/1.2" xmlns:ns13="http://cpe.mitre.org/dictionary/2.0" xmlns:ns2="urn:oasis:names:tc:entity:xmlns:xml:catalog" xmlns:ns3="http://scap.nist.gov/schema/ocil/2.0" xmlns:ns4="http://oval.mitre.org/XMLSchema/oval-definitions-5" xmlns:ns6="http://oval.mitre.org/XMLSchema/oval-common-5" xmlns:ns7="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" xmlns:ns8="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix" xmlns:ns9="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="scap_org.open-scap_collection_from_xccdf_ssg-rhel8-xccdf-1.2.xml" schematron-version="1.2">
3+
<ns0:data-stream id="scap_org.open-scap_datastream_from_xccdf_ssg-rhel8-xccdf-1.2.xml" scap-version="1.2" use-case="OTHER">
4+
<ns0:checks>
5+
<ns0:component-ref id="scap_org.open-scap_cref_ssg-rhel8-oval.xml" ns1:href="#scap_org.open-scap_comp_ssg-rhel8-oval.xml"/>
6+
</ns0:checks>
7+
</ns0:data-stream>
8+
<ns0:component id="scap_org.open-scap_comp_ssg-rhel8-oval.xml" timestamp="2019-05-10T08:18:44">
9+
<ns4:oval_definitions xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd 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#unix unix-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#linux linux-definitions-schema.xsd">
10+
<ns4:generator>
11+
<ns6:product_name>combine_ovals.py from SCAP Security Guide</ns6:product_name>
12+
<ns6:product_version>ssg: [0, 1, 44], python: 3.7.3</ns6:product_version>
13+
<ns6:schema_version>5.10</ns6:schema_version>
14+
<ns6:timestamp>2019-05-10T06:18:18</ns6:timestamp>
15+
</ns4:generator>
16+
<ns4:definitions>
17+
<ns4:definition class="inventory" id="oval:ssg-installed_OS_is_rhel8:def:1" version="1">
18+
<ns4:metadata>
19+
<ns4:title>Red Hat Enterprise Linux 8</ns4:title>
20+
<ns4:affected family="unix">
21+
<ns4:platform>Red Hat Enterprise Linux 8</ns4:platform>
22+
</ns4:affected>
23+
<ns4:reference ref_id="cpe:/o:redhat:enterprise_linux:8" source="CPE"/>
24+
<ns4:description>The operating system installed on the system is
25+
Red Hat Enterprise Linux 8</ns4:description>
26+
<ns4:reference ref_id="installed_OS_is_rhel8" source="ssg"/>
27+
</ns4:metadata>
28+
<ns4:criteria>
29+
<ns4:criterion comment="RHEL 8 is installed" test_ref="oval:ssg-test_rhel8:tst:1"/>
30+
</ns4:criteria>
31+
</ns4:definition>
32+
</ns4:definitions>
33+
<ns4:tests>
34+
<ns9:rpminfo_test check="all" check_existence="at_least_one_exists" comment="redhat-release is version 8" id="oval:ssg-test_rhel8:tst:1" version="1">
35+
<ns9:object object_ref="oval:ssg-obj_rhel8:obj:1"/>
36+
<ns9:state state_ref="oval:ssg-state_rhel8:ste:1"/>
37+
</ns9:rpminfo_test>
38+
</ns4:tests>
39+
<ns4:objects>
40+
<ns9:rpminfo_object id="oval:ssg-obj_rhel8:obj:1" version="1">
41+
<ns9:name>redhat-release</ns9:name>
42+
</ns9:rpminfo_object>
43+
</ns4:objects>
44+
<ns4:states>
45+
<ns9:rpminfo_state id="oval:ssg-state_rhel8:ste:1" version="1">
46+
<ns9:version operation="pattern match">^8.*$</ns9:version>
47+
</ns9:rpminfo_state>
48+
</ns4:states>
49+
</ns4:oval_definitions>
50+
</ns0:component>
51+
</ns0:data-stream-collection>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0"?>
2+
<ns0:data-stream-collection xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:ns0="http://scap.nist.gov/schema/scap/source/1.2" xmlns:ns1="http://www.w3.org/1999/xlink" xmlns:ns10="http://checklists.nist.gov/xccdf/1.2" xmlns:ns13="http://cpe.mitre.org/dictionary/2.0" xmlns:ns2="urn:oasis:names:tc:entity:xmlns:xml:catalog" xmlns:ns3="http://scap.nist.gov/schema/ocil/2.0" xmlns:ns4="http://oval.mitre.org/XMLSchema/oval-definitions-5" xmlns:ns6="http://oval.mitre.org/XMLSchema/oval-common-5" xmlns:ns7="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" xmlns:ns8="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix" xmlns:ns9="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="scap_org.open-scap_collection_from_xccdf_ssg-rhel8-xccdf-1.2.xml" schematron-version="1.3">
3+
<ns0:data-stream id="scap_org.open-scap_datastream_from_xccdf_ssg-rhel8-xccdf-1.2.xml" scap-version="1.3" use-case="OTHER">
4+
<ns0:checks>
5+
<ns0:component-ref id="scap_org.open-scap_cref_ssg-rhel8-oval.xml" ns1:href="#scap_org.open-scap_comp_ssg-rhel8-oval.xml"/>
6+
</ns0:checks>
7+
</ns0:data-stream>
8+
<ns0:component id="scap_org.open-scap_comp_ssg-rhel8-oval.xml" timestamp="2019-05-10T08:18:44">
9+
<ns4:oval_definitions xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd 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#unix unix-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#linux linux-definitions-schema.xsd">
10+
<ns4:generator>
11+
<ns6:product_name>combine_ovals.py from SCAP Security Guide</ns6:product_name>
12+
<ns6:product_version>ssg: [0, 1, 44], python: 3.7.3</ns6:product_version>
13+
<ns6:schema_version>5.11</ns6:schema_version>
14+
<ns6:timestamp>2019-05-10T06:18:18</ns6:timestamp>
15+
</ns4:generator>
16+
<ns4:definitions>
17+
<ns4:definition class="inventory" id="oval:ssg-installed_OS_is_rhel8:def:1" version="1">
18+
<ns4:metadata>
19+
<ns4:title>Red Hat Enterprise Linux 8</ns4:title>
20+
<ns4:affected family="unix">
21+
<ns4:platform>Red Hat Enterprise Linux 8</ns4:platform>
22+
</ns4:affected>
23+
<ns4:reference ref_id="cpe:/o:redhat:enterprise_linux:8" source="CPE"/>
24+
<ns4:description>The operating system installed on the system is
25+
Red Hat Enterprise Linux 8</ns4:description>
26+
<ns4:reference ref_id="installed_OS_is_rhel8" source="ssg"/>
27+
</ns4:metadata>
28+
<ns4:criteria>
29+
<ns4:criterion comment="RHEL 8 is installed" test_ref="oval:ssg-test_rhel8:tst:1"/>
30+
</ns4:criteria>
31+
</ns4:definition>
32+
</ns4:definitions>
33+
<ns4:tests>
34+
<ns9:rpminfo_test check="all" check_existence="at_least_one_exists" comment="redhat-release is version 8" id="oval:ssg-test_rhel8:tst:1" version="1">
35+
<ns9:object object_ref="oval:ssg-obj_rhel8:obj:1"/>
36+
<ns9:state state_ref="oval:ssg-state_rhel8:ste:1"/>
37+
</ns9:rpminfo_test>
38+
</ns4:tests>
39+
<ns4:objects>
40+
<ns9:rpminfo_object id="oval:ssg-obj_rhel8:obj:1" version="1">
41+
<ns9:name>redhat-release</ns9:name>
42+
</ns9:rpminfo_object>
43+
</ns4:objects>
44+
<ns4:states>
45+
<ns9:rpminfo_state id="oval:ssg-state_rhel8:ste:1" version="1">
46+
<ns9:version operation="pattern match">^8.*$</ns9:version>
47+
</ns9:rpminfo_state>
48+
</ns4:states>
49+
</ns4:oval_definitions>
50+
</ns0:component>
51+
</ns0:data-stream-collection>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# Copyright 2019 Red Hat Inc., Durham, North Carolina.
4+
# All Rights Reserved.
5+
#
6+
# OpenSCAP Test Suite
7+
#
8+
# Authors:
9+
# Jan Černý <[email protected]>
10+
11+
. $builddir/tests/test_common.sh
12+
13+
set -e -o pipefail
14+
15+
function test_oscap_info {
16+
version="$1"
17+
stdout="$(mktemp)"
18+
stderr="$(mktemp)"
19+
$OSCAP info $srcdir/scap-$version-ds.xml > $stdout 2> $stderr
20+
[ ! -s $stderr ]
21+
grep -q "Version: $version" $stdout
22+
rm $stdout
23+
rm $stderr
24+
}
25+
26+
test_oscap_info "1.2"
27+
test_oscap_info "1.3"

0 commit comments

Comments
 (0)