Debian Codegraph @

tests/API/XCCDF/default_cpe/test_cpe_applicability.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 # Copyright 2012 Red Hat Inc., Durham, North Carolina.
4 # All Rights Reserved.
5
6 . $builddir/tests/test_common.sh
7
8 CPE_OVAL="cpe-oval.xml"
9 CPE_DICT="cpe-dict.xml"
10 XCCDF="xccdf.xml"
11 CPE="cpe:/o:example:applicable:1"
12 NA_CPE="cpe:/o:example:not_applicable:5"
13
14 function test_cpe_setup() {
15 cp $srcdir/$CPE_OVAL $builddir/$CPE_OVAL
16 cp $srcdir/$CPE_DICT $builddir/$CPE_DICT
17 echo "Applicable CPE (set in '$CPE_DICT'): $CPE"
18 }
19
20 function test_cpe {
21 local CPE=$1
22 local EXPECTED_NA=$2
23 local TMP_RESULTS=`mktemp`
24
25 # Create XCCDF file with CPE based on RHEL/FEDORA version.
26 rm -f $builddir/$XCCDF
27 cp $srcdir/$XCCDF $builddir/$XCCDF
28 xsed -i "s|<<CPE>>|${CPE}|" $builddir/$XCCDF
29
30 echo "Tested CPE: $CPE"
31 $OSCAP xccdf eval --cpe $builddir/$CPE_DICT --results $TMP_RESULTS $builddir/$XCCDF
32 if [ $? -ne 0 ]; then
33 return 1
34 fi
35
36 local NOTAPPLICABLE_COUNT=$($XPATH $TMP_RESULTS \
37 'count(//result[text()="notapplicable"])' 2>/dev/null)
38 rm -f $TMP_RESULTS
39
40 if [ "$NOTAPPLICABLE_COUNT" == "$EXPECTED_NA" ]; then
41 return 0
42 fi
43 return 1
44 }
45
46 # Testing.
47
48 test_init "test_api_xccdf_cpe_applicability.log"
49 test_cpe_setup
50
51 test_run "test_api_xccdf_cpe_applicable" test_cpe \
52 $CPE 0
53 test_run "test_api_xccdf_cpe_notapplicable" test_cpe \
54 $NA_CPE 1
55
56 test_exit