Skip to content

Commit

Permalink
Extend test_skip_paths
Browse files Browse the repository at this point in the history
Extend test_skip_paths to test the "skip selected paths" feature
also in the xmlfilecontent probe.
  • Loading branch information
jan-cerny committed Dec 18, 2023
1 parent a033aef commit c316bc4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/API/OVAL/skip_paths/test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<parent>
<child>text</child>
</parent>
10 changes: 10 additions & 0 deletions tests/API/OVAL/skip_paths/test_skip_paths.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ result=$(mktemp)
root="/tmp/oscap_test_skip_paths"
mkdir -p "$root/a"
touch "$root/a/x"
cp "$srcdir/test.xml" "$root/a/"
mkdir -p "$root/b"
touch "$root/b/y"
cp "$srcdir/test.xml" "$root/b/"
mkdir -p "$root/c"
touch "$root/c/z"
cp "$srcdir/test.xml" "$root/c/"
# oscap probes will skip directories "b" and "c"
export OSCAP_PROBE_IGNORE_PATHS="$root/b:$root/c"
$OSCAP oval eval --results $result "$srcdir/test_skip_paths.xml"
Expand All @@ -37,5 +40,12 @@ assert_exists 1 '/oval_results/results/system/definitions/definition[@definition
assert_exists 1 '/oval_results/results/system/oval_system_characteristics/collected_objects/object[@id="oval:x:obj:6" and @flag="does not exist"]'
assert_exists 0 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:filehash58_item/ind-sys:filepath[text()="/tmp/oscap_test_skip_paths/b/y"]'
assert_exists 0 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:filehash58_item/ind-sys:filepath[text()="/tmp/oscap_test_skip_paths/c/z"]'
assert_exists 1 '/oval_results/results/system/definitions/definition[@definition_id="oval:x:def:7" and @result="true"]'
assert_exists 1 '/oval_results/results/system/oval_system_characteristics/collected_objects/object[@id="oval:x:obj:7" and @flag="complete"]'
assert_exists 1 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item/ind-sys:filepath[text()="/tmp/oscap_test_skip_paths/a/test.xml"]'
assert_exists 1 '/oval_results/results/system/definitions/definition[@definition_id="oval:x:def:8" and @result="true"]'
assert_exists 1 '/oval_results/results/system/oval_system_characteristics/collected_objects/object[@id="oval:x:obj:8" and @flag="does not exist"]'
assert_exists 0 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item/ind-sys:filepath[text()="/tmp/oscap_test_skip_paths/b/test.xml"]'
assert_exists 0 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item/ind-sys:filepath[text()="/tmp/oscap_test_skip_paths/c/test.xml"]'
rm -f $result
rm -rf "$root"
26 changes: 26 additions & 0 deletions tests/API/OVAL/skip_paths/test_skip_paths.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@
<criterion test_ref="oval:x:tst:6"/>
</criteria>
</definition>
<definition class="compliance" version="1" id="oval:x:def:7">
<metadata><title/><description/></metadata>
<criteria operator="AND">
<criterion test_ref="oval:x:tst:7"/>
</criteria>
</definition>
<definition class="compliance" version="1" id="oval:x:def:8">
<metadata><title/><description/></metadata>
<criteria operator="AND">
<criterion test_ref="oval:x:tst:8"/>
</criteria>
</definition>
</definitions>
<tests>
<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="read file from directory 'a' - should be read">
Expand All @@ -61,6 +73,12 @@
<filehash58_test xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" check_existence="none_exist" version="1" id="oval:x:tst:6" check="all" comment="read file from directory 'b' - should be skip">
<object object_ref="oval:x:obj:6"/>
</filehash58_test>
<xmlfilecontent_test xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" check_existence="at_least_one_exists" version="1" id="oval:x:tst:7" check="all" comment="read file from directory 'a' - should be read">
<object object_ref="oval:x:obj:7"/>
</xmlfilecontent_test>
<xmlfilecontent_test xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" check_existence="none_exist" version="1" id="oval:x:tst:8" check="all" comment="read file from directory 'b' - should be skip">
<object object_ref="oval:x:obj:8"/>
</xmlfilecontent_test>
</tests>
<objects>
<file_object xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix" version="1" id="oval:x:obj:1">
Expand All @@ -87,5 +105,13 @@
<filepath>/tmp/oscap_test_skip_paths/b/y</filepath>
<hash_type>SHA-512</hash_type>
</filehash58_object>
<xmlfilecontent_object xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" version="1" id="oval:x:obj:7">
<filepath>/tmp/oscap_test_skip_paths/a/test.xml</filepath>
<xpath>/parent</xpath>
</xmlfilecontent_object>
<xmlfilecontent_object xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" version="1" id="oval:x:obj:8">
<filepath>/tmp/oscap_test_skip_paths/b/test.xml</filepath>
<xpath>/parent</xpath>
</xmlfilecontent_object>
</objects>
</oval_definitions>

0 comments on commit c316bc4

Please sign in to comment.