Skip to content

Commit 3da4221

Browse files
committed
Add a few unittests for debian_evr_string
1 parent bf08d62 commit 3da4221

6 files changed

+248
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<oval_definitions
2+
xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5"
3+
xmlns:ind="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent"
4+
xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5"
5+
xmlns:unix="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix"
6+
xmlns:linux="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux"
7+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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#macos linux-definitions-schema.xsd">
8+
<generator>
9+
<oval:product_name>Canonical USN OVAL Generator</oval:product_name>
10+
<oval:product_version>1</oval:product_version>
11+
<oval:schema_version>5.11.1</oval:schema_version>
12+
<oval:timestamp>2022-12-19T14:35:51</oval:timestamp>
13+
</generator>
14+
<definitions>
15+
<definition id="oval:com.ubuntu.jammy:def:54471000000" version="1" class="patch">
16+
<metadata>
17+
<title>logrotate vulnerability</title>
18+
<description>none</description>
19+
</metadata>
20+
<criteria operator="OR">
21+
<criterion test_ref="oval:com.ubuntu.jammy:tst:544710000000" comment="logrotate is earlier than 0:3.18.0-2ubuntu1.1" />
22+
</criteria>
23+
</definition>
24+
</definitions>
25+
<tests>
26+
<linux:dpkginfo_test id="oval:com.ubuntu.jammy:tst:544710000000" version="1" check_existence="at_least_one_exists" check="at least one" comment="logrotate is earlier than 0:3.18.0-2ubuntu1.1">
27+
<linux:object object_ref="oval:com.ubuntu.jammy:obj:544710000000"/>
28+
<linux:state state_ref="oval:com.ubuntu.jammy:ste:544710000000"/>
29+
</linux:dpkginfo_test>
30+
</tests>
31+
<objects>
32+
<linux:dpkginfo_object id="oval:com.ubuntu.jammy:obj:544710000000" version="1" comment="logrotate object">
33+
<linux:name var_ref="oval:com.ubuntu.jammy:var:544710000000" var_check="at least one" />
34+
</linux:dpkginfo_object>
35+
</objects>
36+
<states>
37+
<linux:dpkginfo_state id="oval:com.ubuntu.jammy:ste:544710000000" version="1" comment="logrotate version">
38+
<linux:evr datatype="debian_evr_string" operation="less than">0:3.18.0-2ubuntu1.1</linux:evr>
39+
</linux:dpkginfo_state>
40+
</states>
41+
<variables>
42+
<constant_variable id="oval:com.ubuntu.jammy:var:544710000000" version="1" datatype="string" comment="logrotate">
43+
<value>logrotate</value>
44+
</constant_variable>
45+
</variables>
46+
</oval_definitions>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
. $builddir/tests/test_common.sh
3+
4+
set -e -o pipefail
5+
6+
name=$(basename $0 .sh)
7+
result=$(mktemp ${name}.out.XXXXXX)
8+
echo "result file: $result"
9+
stderr=$(mktemp ${name}.err.XXXXXX)
10+
echo "stderr file: $stderr"
11+
12+
echo "Analysing syschar content."
13+
$OSCAP oval analyse --results $result $srcdir/$name.oval.xml $srcdir/$name.syschar.xml 2> $stderr
14+
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr
15+
[ -f $result ]
16+
17+
assert_exists 1 '/oval_results'
18+
assert_exists 1 '/oval_results/generator'
19+
assert_exists 1 '/oval_results/generator/oval:product_name'
20+
assert_exists 1 '/oval_results/generator/oval:product_name[text()="cpe:/a:open-scap:oscap"]'
21+
assert_exists 1 '/oval_results/generator/oval:schema_version'
22+
assert_exists 1 '/oval_results/generator/oval:schema_version[text()="5.11.1"]'
23+
assert_exists 1 '/oval_results/generator/oval:timestamp'
24+
assert_exists 1 '/oval_results/directives'
25+
assert_exists 1 '/oval_results/oval_definitions'
26+
assert_exists 1 '/oval_results/results'
27+
assert_exists 1 '/oval_results/results/system'
28+
assert_exists 1 '/oval_results/results/system/definitions'
29+
assert_exists 1 '/oval_results/results/system/definitions/definition'
30+
assert_exists 1 '/oval_results/results/system/definitions/definition[@result="false"]'
31+
assert_exists 1 '/oval_results/results/system/definitions/definition/criteria'
32+
assert_exists 1 '/oval_results/results/system/definitions/definition/criteria/criterion'
33+
assert_exists 1 '/oval_results/results/system/definitions/definition/criteria/criterion[@result="false"]'
34+
assert_exists 1 '/oval_results/results/system/tests'
35+
assert_exists 1 '/oval_results/results/system/tests/test'
36+
assert_exists 1 '/oval_results/results/system/tests/test[@result="false"]'
37+
assert_exists 1 '/oval_results/results/system/tests/test/tested_item'
38+
assert_exists 1 '/oval_results/results/system/tests/test/tested_item[@result="false"]'
39+
40+
rm $result
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<oval_system_characteristics xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5" xmlns:unix-sys="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#unix" xmlns:ind-sys="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#independent" xmlns:lin-sys="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#linux" xmlns:win-sys="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#windows" xmlns="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5" xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5 oval-system-characteristics-schema.xsd http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#independent independent-system-characteristics-schema.xsd http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#unix unix-system-characteristics-schema.xsd http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#linux linux-system-characteristics-schema.xsd http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd">
3+
<generator>
4+
<oval:product_name>cpe:/a:open-scap:oscap</oval:product_name>
5+
<oval:product_version>1</oval:product_version>
6+
<oval:schema_version>5.11.1</oval:schema_version>
7+
<oval:timestamp>2022-12-19T16:39:11</oval:timestamp>
8+
</generator>
9+
<system_info>
10+
<os_name>Linux</os_name>
11+
<os_version>#59-Ubuntu SMP Mon Oct 17 18:53:30 UTC 2022</os_version>
12+
<architecture>x86_64</architecture>
13+
<primary_host_name>you.know.it</primary_host_name>
14+
<interfaces>
15+
<interface>
16+
<interface_name>lo</interface_name>
17+
<ip_address>127.0.0.1</ip_address>
18+
<mac_address>00:00:00:00:00:00</mac_address>
19+
</interface>
20+
</interfaces>
21+
</system_info>
22+
<collected_objects>
23+
<object id="oval:com.ubuntu.jammy:obj:544710000000" version="1" flag="complete">
24+
<variable_value variable_id="oval:com.ubuntu.jammy:var:544710000000">logrotate</variable_value>
25+
<reference item_ref="101854166"/>
26+
</object>
27+
</collected_objects>
28+
<system_data>
29+
<lin-sys:dpkginfo_item id="101854166" status="exists">
30+
<lin-sys:name>logrotate</lin-sys:name>
31+
<lin-sys:arch>amd64</lin-sys:arch>
32+
<lin-sys:epoch>0</lin-sys:epoch>
33+
<lin-sys:release>2ubuntu1.1</lin-sys:release>
34+
<lin-sys:version>3.18.0</lin-sys:version>
35+
<lin-sys:evr datatype="debian_evr_string">0:3.18.0-2ubuntu1.1</lin-sys:evr>
36+
</lin-sys:dpkginfo_item>
37+
</system_data>
38+
</oval_system_characteristics>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<oval_definitions
2+
xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5"
3+
xmlns:ind="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent"
4+
xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5"
5+
xmlns:unix="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix"
6+
xmlns:linux="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux"
7+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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#macos linux-definitions-schema.xsd">
8+
<generator>
9+
<oval:product_name>Canonical USN OVAL Generator</oval:product_name>
10+
<oval:product_version>1</oval:product_version>
11+
<oval:schema_version>5.11.1</oval:schema_version>
12+
<oval:timestamp>2022-12-19T14:35:51</oval:timestamp>
13+
</generator>
14+
<definitions>
15+
<definition id="oval:com.ubuntu.jammy:def:54471000000" version="1" class="patch">
16+
<metadata>
17+
<title>logrotate vulnerability</title>
18+
<description>none</description>
19+
</metadata>
20+
<criteria operator="OR">
21+
<criterion test_ref="oval:com.ubuntu.jammy:tst:544710000000" comment="logrotate is earlier than 3.19.0-1ubuntu1.1" />
22+
</criteria>
23+
</definition>
24+
</definitions>
25+
<tests>
26+
<linux:dpkginfo_test id="oval:com.ubuntu.jammy:tst:544710000000" version="1" check_existence="at_least_one_exists" check="at least one" comment="logrotate is earlier than 3.19.0-1ubuntu1.1">
27+
<linux:object object_ref="oval:com.ubuntu.jammy:obj:544710000000"/>
28+
<linux:state state_ref="oval:com.ubuntu.jammy:ste:544710000000"/>
29+
</linux:dpkginfo_test>
30+
</tests>
31+
<objects>
32+
<linux:dpkginfo_object id="oval:com.ubuntu.jammy:obj:544710000000" version="1" comment="logrotate object">
33+
<linux:name var_ref="oval:com.ubuntu.jammy:var:544710000000" var_check="at least one" />
34+
</linux:dpkginfo_object>
35+
</objects>
36+
<states>
37+
<linux:dpkginfo_state id="oval:com.ubuntu.jammy:ste:544710000000" version="1" comment="logrotate version">
38+
<linux:evr datatype="debian_evr_string" operation="less than">3.19.0-1ubuntu1.1</linux:evr>
39+
</linux:dpkginfo_state>
40+
</states>
41+
<variables>
42+
<constant_variable id="oval:com.ubuntu.jammy:var:544710000000" version="1" datatype="string" comment="logrotate">
43+
<value>logrotate</value>
44+
</constant_variable>
45+
</variables>
46+
</oval_definitions>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
. $builddir/tests/test_common.sh
3+
4+
set -e -o pipefail
5+
6+
name=$(basename $0 .sh)
7+
result=$(mktemp ${name}.out.XXXXXX)
8+
echo "result file: $result"
9+
stderr=$(mktemp ${name}.err.XXXXXX)
10+
echo "stderr file: $stderr"
11+
12+
echo "Analysing syschar content."
13+
$OSCAP oval analyse --results $result $srcdir/$name.oval.xml $srcdir/$name.syschar.xml 2> $stderr
14+
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr
15+
[ -f $result ]
16+
17+
assert_exists 1 '/oval_results'
18+
assert_exists 1 '/oval_results/generator'
19+
assert_exists 1 '/oval_results/generator/oval:product_name'
20+
assert_exists 1 '/oval_results/generator/oval:product_name[text()="cpe:/a:open-scap:oscap"]'
21+
assert_exists 1 '/oval_results/generator/oval:schema_version'
22+
assert_exists 1 '/oval_results/generator/oval:schema_version[text()="5.11.1"]'
23+
assert_exists 1 '/oval_results/generator/oval:timestamp'
24+
assert_exists 1 '/oval_results/directives'
25+
assert_exists 1 '/oval_results/oval_definitions'
26+
assert_exists 1 '/oval_results/results'
27+
assert_exists 1 '/oval_results/results/system'
28+
assert_exists 1 '/oval_results/results/system/definitions'
29+
assert_exists 1 '/oval_results/results/system/definitions/definition'
30+
assert_exists 1 '/oval_results/results/system/definitions/definition[@result="false"]'
31+
assert_exists 1 '/oval_results/results/system/definitions/definition/criteria'
32+
assert_exists 1 '/oval_results/results/system/definitions/definition/criteria/criterion'
33+
assert_exists 1 '/oval_results/results/system/definitions/definition/criteria/criterion[@result="false"]'
34+
assert_exists 1 '/oval_results/results/system/tests'
35+
assert_exists 1 '/oval_results/results/system/tests/test'
36+
assert_exists 1 '/oval_results/results/system/tests/test[@result="false"]'
37+
assert_exists 1 '/oval_results/results/system/tests/test/tested_item'
38+
assert_exists 1 '/oval_results/results/system/tests/test/tested_item[@result="false"]'
39+
40+
rm $result
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<oval_system_characteristics xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5" xmlns:unix-sys="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#unix" xmlns:ind-sys="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#independent" xmlns:lin-sys="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#linux" xmlns:win-sys="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#windows" xmlns="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5" xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5 oval-system-characteristics-schema.xsd http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#independent independent-system-characteristics-schema.xsd http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#unix unix-system-characteristics-schema.xsd http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#linux linux-system-characteristics-schema.xsd http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd">
3+
<generator>
4+
<oval:product_name>cpe:/a:open-scap:oscap</oval:product_name>
5+
<oval:product_version>1</oval:product_version>
6+
<oval:schema_version>5.11.1</oval:schema_version>
7+
<oval:timestamp>2022-12-19T16:39:11</oval:timestamp>
8+
</generator>
9+
<system_info>
10+
<os_name>Linux</os_name>
11+
<os_version>#59-Ubuntu SMP Mon Oct 17 18:53:30 UTC 2022</os_version>
12+
<architecture>x86_64</architecture>
13+
<primary_host_name>you.know.it</primary_host_name>
14+
<interfaces>
15+
<interface>
16+
<interface_name>lo</interface_name>
17+
<ip_address>127.0.0.1</ip_address>
18+
<mac_address>00:00:00:00:00:00</mac_address>
19+
</interface>
20+
</interfaces>
21+
</system_info>
22+
<collected_objects>
23+
<object id="oval:com.ubuntu.jammy:obj:544710000000" version="1" flag="complete">
24+
<variable_value variable_id="oval:com.ubuntu.jammy:var:544710000000">logrotate</variable_value>
25+
<reference item_ref="101854166"/>
26+
</object>
27+
</collected_objects>
28+
<system_data>
29+
<lin-sys:dpkginfo_item id="101854166" status="exists">
30+
<lin-sys:name>logrotate</lin-sys:name>
31+
<lin-sys:arch>amd64</lin-sys:arch>
32+
<lin-sys:epoch>0</lin-sys:epoch>
33+
<lin-sys:release>1ubuntu1.1</lin-sys:release>
34+
<lin-sys:version>3.19.0</lin-sys:version>
35+
<lin-sys:evr datatype="debian_evr_string">0:3.19.0-1ubuntu1.1</lin-sys:evr>
36+
</lin-sys:dpkginfo_item>
37+
</system_data>
38+
</oval_system_characteristics>

0 commit comments

Comments
 (0)