Skip to content

Commit

Permalink
Test collected items limit
Browse files Browse the repository at this point in the history
This commit adds a simple test that covers a situation when
the probe collects more items than the limit for a single OVAL object.
  • Loading branch information
jan-cerny committed Nov 14, 2023
1 parent b20fca6 commit 5e3d8bc
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ add_subdirectory("curl")
add_subdirectory("CPE")
add_subdirectory("DS")
add_subdirectory("mitre")
add_subdirectory("memory")
add_subdirectory("nist")
add_subdirectory("oscap_string")
add_subdirectory("oval_details")
Expand Down
1 change: 1 addition & 0 deletions tests/memory/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_oscap_test("collect_limit.sh")
37 changes: 37 additions & 0 deletions tests/memory/collect_limit.oval.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0"?>
<oval_definitions xmlns:oval-def="http://oval.mitre.org/XMLSchema/oval-definitions-5" xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5" xmlns:ind="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ind-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" xmlns:unix-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix" xmlns:lin-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux" 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#linux linux-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">
<generator>
<oval:schema_version>5.10.1</oval:schema_version>
<oval:timestamp>0001-01-01T00:00:00+00:00</oval:timestamp>
</generator>

<definitions>
<definition class="compliance" version="1" id="oval:x:def:1">
<metadata>
<title>x</title>
<description>x</description>
<affected family="unix">
<platform>x</platform>
</affected>
</metadata>
<criteria>
<criterion test_ref="oval:x:tst:1" comment="always pass"/>
</criteria>
</definition>
</definitions>

<tests>
<ind:textfilecontent54_test id="oval:x:tst:1" version="1" comment="Test" check="all">
<ind:object object_ref="oval:x:obj:1"/>
</ind:textfilecontent54_test>
</tests>

<objects>
<ind:textfilecontent54_object id="oval:x:obj:1" version="1" comment="The object matches each line in /tmp/longfile.">
<ind:filepath>/tmp/longfile</ind:filepath>
<ind:pattern operation="pattern match">^.*$</ind:pattern>
<ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
</ind:textfilecontent54_object>
</objects>

</oval_definitions>
18 changes: 18 additions & 0 deletions tests/memory/collect_limit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -e -o pipefail

. $builddir/tests/test_common.sh

# PROBE_ITEM_COLLECT_MAX limit is 1000
seq 1010 > /tmp/longfile
result=$(mktemp)
$OSCAP oval eval --results "$result" $srcdir/collect_limit.oval.xml
assert_exists 1 '/oval_results/results/system/oval_system_characteristics/collected_objects/object'
assert_exists 1 '/oval_results/results/system/oval_system_characteristics/collected_objects/object[@flag="incomplete"]'
assert_exists 1 '/oval_results/results/system/oval_system_characteristics/collected_objects/object/message[@level="warning"]'
text="Object is incomplete because the object matches more than 1000 items."
assert_exists 1 "/oval_results/results/system/oval_system_characteristics/collected_objects/object/message[text()=\"$text\"]"
assert_exists 1000 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:textfilecontent_item'
rm -f /tmp/longfile
rm -f "$result"

0 comments on commit 5e3d8bc

Please sign in to comment.