Skip to content

Commit 9468f96

Browse files
authored
Merge pull request #1438 from pschneiders/debian10
Adjusting unittests for building on Debian10
2 parents f1178f7 + 8a4b89c commit 9468f96

File tree

9 files changed

+55
-12
lines changed

9 files changed

+55
-12
lines changed

tests/API/OVAL/unittests/test_object_component_type.oval.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<ind:object object_ref="oval:oscap:obj:2" />
3131
<ind:state state_ref="oval:oscap:ste:1" />
3232
</ind:variable_test>
33-
<ind:variable_test id="oval:oscap:tst:3" check="all" comment="The value of PASS_MIN_LEN should be set appropriately in /etc/login.defs" version="1">
33+
<ind:variable_test id="oval:oscap:tst:3" check="all" comment="The value of PASS_MIN_DAYS should be set appropriately in /etc/login.defs" version="1">
3434
<ind:object object_ref="oval:oscap:obj:3" />
3535
<ind:state state_ref="oval:oscap:ste:1" />
3636
</ind:variable_test>
@@ -47,11 +47,11 @@
4747
<ind:var_ref>oval:oscap:var:3</ind:var_ref>
4848
</ind:variable_object>
4949
<ind:textfilecontent54_object id="oval:oscap:obj:10" version="1">
50-
<!-- Read whole /etc/login.defs as single line so we can retrieve last PASS_MIN_LEN directive occurrence -->
50+
<!-- Read whole /etc/login.defs as single line so we can retrieve last PASS_MIN_DAYS directive occurrence -->
5151
<ind:behaviors singleline="true" />
5252
<ind:filepath>/etc/login.defs</ind:filepath>
53-
<!-- Retrieve last (uncommented) occurrence of PASS_MIN_LEN directive -->
54-
<ind:pattern operation="pattern match">.*\n[^#]*(PASS_MIN_LEN\s+\d+)\s*\n</ind:pattern>
53+
<!-- Retrieve last (uncommented) occurrence of PASS_MIN_DAYS directive -->
54+
<ind:pattern operation="pattern match">.*\n[^#]*(PASS_MIN_DAYS\s+\d+)\s*\n</ind:pattern>
5555
<ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
5656
</ind:textfilecontent54_object>
5757
</objects>
@@ -64,20 +64,20 @@
6464

6565
<variables>
6666
<!-- variable with a meaningfully specified object_component/@item_field attribute -->
67-
<local_variable id="oval:oscap:var:1" datatype="int" comment="The value of last PASS_MIN_LEN directive in /etc/login.defs" version="1">
68-
<regex_capture pattern="PASS_MIN_LEN\s+(\d+)">
67+
<local_variable id="oval:oscap:var:1" datatype="int" comment="The value of last PASS_MIN_DAYS directive in /etc/login.defs" version="1">
68+
<regex_capture pattern="PASS_MIN_DAYS\s+(\d+)">
6969
<object_component item_field="subexpression" object_ref="oval:oscap:obj:10" />
7070
</regex_capture>
7171
</local_variable>
7272
<!-- variable with a nonsense in the object_component/@item_field attribute -->
7373
<local_variable id="oval:oscap:var:2" datatype="int" comment="Reference to not existing entity within textfilecontent_item. Should report an error when evaluating." version="1">
74-
<regex_capture pattern="PASS_MIN_LEN\s+(\d+)">
74+
<regex_capture pattern="PASS_MIN_DAYS\s+(\d+)">
7575
<object_component item_field="something_bogus" object_ref="oval:oscap:obj:10" />
7676
</regex_capture>
7777
</local_variable>
7878
<!-- variable that requires a record data type in OVAL Item -->
7979
<local_variable id="oval:oscap:var:3" datatype="int" comment="Record_field attribute suggest than an record data type is expected, but actually string data type will be provided. Should report an error when evaluating." version="1">
80-
<regex_capture pattern="PASS_MIN_LEN\s+(\d+)">
80+
<regex_capture pattern="PASS_MIN_DAYS\s+(\d+)">
8181
<object_component item_field="subexpression" record_field="some_record_field_name" object_ref="oval:oscap:obj:10" />
8282
</regex_capture>
8383
</local_variable>

tests/DS/test_ds_misc.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ sds_add_multiple_twice(){
7676
}
7777

7878
function test_eval {
79+
probecheck "rpminfo" || return 255
7980
local stderr=$(mktemp -t ${name}.out.XXXXXX)
8081
$OSCAP xccdf eval "${srcdir}/$1" 2> $stderr
8182
diff /dev/null $stderr; rm $stderr

tests/DS/test_sds_eval.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set -e -o pipefail
1111
# Test Cases.
1212

1313
function test_eval {
14+
probecheck "rpminfo" || return 255
1415
local stderr=$(mktemp -t ${name}.out.XXXXXX)
1516
$OSCAP xccdf eval "${srcdir}/$1" 2> $stderr
1617
diff /dev/null $stderr; rm $stderr

tests/probes/rpm/rpmverifyfile/test_probes_rpmverifyfile.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set -e -o pipefail
1111

1212
function test_probes_rpmverifyfile {
1313
probecheck "rpmverifyfile" || return 255
14+
require "rpm" || return 255
1415

1516
DF="$srcdir/test_probes_rpmverifyfile.xml"
1617
RF="results.xml"

tests/probes/rpm/rpmverifyfile/test_probes_rpmverifyfile_older.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set -e -o pipefail
1111

1212
function test_probes_rpmverifyfile {
1313
probecheck "rpmverifyfile" || return 255
14+
require "rpm" || return 255
1415

1516
DF="$srcdir/test_probes_rpmverifyfile_older.xml"
1617
RF="results.xml"

tests/probes/runlevel/test_probes_runlevel.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ function test_probes_runlevel_A {
8282
function test_probes_runlevel_B {
8383

8484
probecheck "runlevel" || return 255
85+
require "chkconfig" || return 255
8586

8687
local ret_val=0;
8788
local DF="test_probes_runlevel_B.xml"
@@ -109,6 +110,7 @@ function test_probes_runlevel_B {
109110

110111
function test_probes_runlevel_C {
111112
probecheck "runlevel" || return 255
113+
require "chkconfig" || return 255
112114

113115
local ret_val=0;
114116
local definition="test_probes_runlevel_C.xml"

tests/probes/sysctl/test_sysctl_probe_all.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ grep unix-sys:name "$result" | grep -v $SYSCTL_BLACKLIST_REGEX | sed -E 's;.*>(.
5858
# If procps_ver > 3.3.12 we need to filter *stable_secret and vm.stat_refresh
5959
# options from the sysctl output, for more details see
6060
# https://github.com/OpenSCAP/openscap/issues/1152.
61-
procps_ver=$(rpm -q procps-ng --qf="%{version}")
61+
procps_ver="$(package_version procps-ng procps)"
62+
6263
lowest_ver=$(echo -e "3.3.12\n$procps_ver" | sort -V | head -n1)
6364
if [ "$procps_ver" != "$lowest_ver" ]; then
6465
sed -i '/net.ipv6.conf.*stable_secret$/d' "$sysctlNames"

tests/probes/uname/test_probes_uname.xml.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ cat <<EOF
846846
<os_name>`uname -s`</os_name>
847847
<os_release>`uname -r`</os_release>
848848
<os_version>`uname -v`</os_version>
849-
<processor_type>`uname -p`</processor_type>
849+
<processor_type>`uname -m`</processor_type>
850850
</uname_state>
851851
852852
<!-- FULLY FALSE STATE -->
@@ -856,7 +856,7 @@ cat <<EOF
856856
<os_name>X`uname -s`</os_name>
857857
<os_release>X`uname -r`</os_release>
858858
<os_version>X`uname -v`</os_version>
859-
<processor_type>X`uname -p`</processor_type>
859+
<processor_type>X`uname -m`</processor_type>
860860
</uname_state>
861861
862862
<!-- MIXED STATE :-) -->
@@ -866,7 +866,7 @@ cat <<EOF
866866
<os_name>`uname -s`</os_name>
867867
<os_release>`uname -r`</os_release>
868868
<os_version>`uname -v`</os_version>
869-
<processor_type>X`uname -p`</processor_type>
869+
<processor_type>X`uname -m`</processor_type>
870870
</uname_state>
871871
872872
</states>

tests/test_common.sh.in

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,42 @@ function probecheck {
131131
return 0
132132
}
133133

134+
# Check for package names and return a version number
135+
function package_version {
136+
# loop through multiple potential package names
137+
# return first version number found
138+
for package in $@; do
139+
ver=""
140+
141+
# check rpm for package version first
142+
if [ -f "/usr/bin/rpm" ]; then
143+
ver=$(rpm -q $package --qf="%{version}" 2> /dev/null)
144+
145+
# rpm returns error messages on stdout, check return code
146+
if [ ! "$?" -eq "0" ]; then
147+
ver=""
148+
fi
149+
fi
150+
151+
# fall back to dpkg for debian systems
152+
if [ "${ver}" == "" ] && [ -f "/usr/bin/dpkg-query" ]; then
153+
# for Debian-based systems, return the upstream version
154+
ver="$(dpkg-query -f '${source:Upstream-Version}' -W $package 2> /dev/null)"
155+
fi
156+
157+
# return the first match found
158+
if [ "${ver}" != "" ]; then
159+
echo "${ver}"
160+
return 0
161+
fi
162+
done
163+
164+
# package not found
165+
if [ "${ver}" == "" ]; then
166+
return 255
167+
fi
168+
}
169+
134170
function verify_results {
135171

136172
require "grep" || return 255

0 commit comments

Comments
 (0)