Skip to content

Commit 63d2a79

Browse files
committed
Add a simple test for the skip paths feature
1 parent 1e4b8ae commit 63d2a79

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

tests/API/OVAL/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ add_oscap_test("test_api_oval.sh")
88
add_subdirectory("glob_to_regex")
99
add_subdirectory("report_variable_values")
1010
add_subdirectory("schema_version")
11+
add_subdirectory("skip_paths")
1112
add_subdirectory("unittests")
1213
add_subdirectory("validate")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_oscap_test("test_skip_paths.sh")
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
. $builddir/tests/test_common.sh
4+
5+
set -e -o pipefail
6+
7+
result=$(mktemp)
8+
root="/tmp/oscap_test_skip_paths"
9+
mkdir -p "$root/a"
10+
touch "$root/a/x"
11+
mkdir -p "$root/b"
12+
touch "$root/b/y"
13+
mkdir -p "$root/c"
14+
touch "$root/c/z"
15+
# oscap probes will skip directories "b" and "c"
16+
export OSCAP_PROBE_IGNORE_PATHS="$root/b:$root/c"
17+
$OSCAP oval eval --results $result "$srcdir/test_skip_paths.xml"
18+
assert_exists 1 '/oval_results/results/system/definitions/definition[@definition_id="oval:x:def:1" and @result="true"]'
19+
assert_exists 1 '/oval_results/results/system/oval_system_characteristics/collected_objects/object[@id="oval:x:obj:1" and @flag="complete"]'
20+
assert_exists 1 '/oval_results/results/system/oval_system_characteristics/system_data/unix-sys:file_item'
21+
assert_exists 1 '/oval_results/results/system/oval_system_characteristics/system_data/unix-sys:file_item/unix-sys:filepath[text()="/tmp/oscap_test_skip_paths/a/x"]'
22+
assert_exists 1 '/oval_results/results/system/definitions/definition[@definition_id="oval:x:def:2" and @result="true"]'
23+
assert_exists 1 '/oval_results/results/system/oval_system_characteristics/collected_objects/object[@id="oval:x:obj:2" and @flag="does not exist"]'
24+
assert_exists 0 '/oval_results/results/system/oval_system_characteristics/system_data/unix-sys:file_item/unix-sys:filepath[text()="/tmp/oscap_test_skip_paths/b/y"]'
25+
assert_exists 0 '/oval_results/results/system/oval_system_characteristics/system_data/unix-sys:file_item/unix-sys:filepath[text()="/tmp/oscap_test_skip_paths/c/z"]'
26+
assert_exists 1 '/oval_results/results/system/definitions/definition[@definition_id="oval:x:def:3" and @result="true"]'
27+
assert_exists 1 '/oval_results/results/system/oval_system_characteristics/collected_objects/object[@id="oval:x:obj:3" and @flag="complete"]'
28+
assert_exists 1 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:textfilecontent_item/ind-sys:filepath[text()="/tmp/oscap_test_skip_paths/a/x"]'
29+
assert_exists 1 '/oval_results/results/system/definitions/definition[@definition_id="oval:x:def:4" and @result="true"]'
30+
assert_exists 1 '/oval_results/results/system/oval_system_characteristics/collected_objects/object[@id="oval:x:obj:4" and @flag="does not exist"]'
31+
assert_exists 0 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:textfilecontent_item/ind-sys:filepath[text()="/tmp/oscap_test_skip_paths/b/y"]'
32+
assert_exists 0 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:textfilecontent_item/ind-sys:filepath[text()="/tmp/oscap_test_skip_paths/c/z"]'
33+
rm -f $result
34+
rm -rf "$root"
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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" 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">
3+
<generator>
4+
<oval:schema_version>5.11.1</oval:schema_version>
5+
<oval:timestamp>2009-05-21T11:46:00-04:00</oval:timestamp>
6+
</generator>
7+
<definitions>
8+
<definition class="compliance" version="1" id="oval:x:def:1">
9+
<metadata><title/><description/></metadata>
10+
<criteria operator="AND">
11+
<criterion test_ref="oval:x:tst:1"/>
12+
</criteria>
13+
</definition>
14+
<definition class="compliance" version="1" id="oval:x:def:2">
15+
<metadata><title/><description/></metadata>
16+
<criteria operator="AND">
17+
<criterion test_ref="oval:x:tst:2"/>
18+
</criteria>
19+
</definition>
20+
<definition class="compliance" version="1" id="oval:x:def:3">
21+
<metadata><title/><description/></metadata>
22+
<criteria operator="AND">
23+
<criterion test_ref="oval:x:tst:3"/>
24+
</criteria>
25+
</definition>
26+
<definition class="compliance" version="1" id="oval:x:def:4">
27+
<metadata><title/><description/></metadata>
28+
<criteria operator="AND">
29+
<criterion test_ref="oval:x:tst:4"/>
30+
</criteria>
31+
</definition>
32+
</definitions>
33+
<tests>
34+
<file_test xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix" check_existence="at_least_one_exists" version="1" id="oval:x:tst:1" check="all" comment="a file">
35+
<object object_ref="oval:x:obj:1"/>
36+
</file_test>
37+
<file_test xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix" check_existence="none_exist" version="1" id="oval:x:tst:2" check="all" comment="a file">
38+
<object object_ref="oval:x:obj:2"/>
39+
</file_test>
40+
<textfilecontent54_test xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" check_existence="at_least_one_exists" version="1" id="oval:x:tst:3" check="all" comment="a file">
41+
<object object_ref="oval:x:obj:3"/>
42+
</textfilecontent54_test>
43+
<textfilecontent54_test xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" check_existence="none_exist" version="1" id="oval:x:tst:4" check="all" comment="a file">
44+
<object object_ref="oval:x:obj:4"/>
45+
</textfilecontent54_test>
46+
</tests>
47+
<objects>
48+
<file_object xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix" version="1" id="oval:x:obj:1">
49+
<filepath>/tmp/oscap_test_skip_paths/a/x</filepath>
50+
</file_object>
51+
<file_object xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix" version="1" id="oval:x:obj:2">
52+
<filepath>/tmp/oscap_test_skip_paths/b/y</filepath>
53+
</file_object>
54+
<textfilecontent54_object xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" version="1" id="oval:x:obj:3">
55+
<filepath>/tmp/oscap_test_skip_paths/a/x</filepath>
56+
<pattern>^.*$</pattern>
57+
<instance datatype="int" operation="greater than or equal">1</instance>
58+
</textfilecontent54_object>
59+
<textfilecontent54_object xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" version="1" id="oval:x:obj:4">
60+
<filepath>/tmp/oscap_test_skip_paths/b/y</filepath>
61+
<pattern>^.*$</pattern>
62+
<instance datatype="int" operation="greater than or equal">1</instance>
63+
</textfilecontent54_object>
64+
</objects>
65+
</oval_definitions>

0 commit comments

Comments
 (0)