Debian Codegraph @

tests/API/XCCDF/default_cpe/test_cpe_applicability.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/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_setupscip-shell shell shell-project 0.0.0 test_cpe_setup().() {
15 cpscip-shell system . . cp. $srcdir/$CPE_OVAL $builddir/$CPE_OVAL
16 cpscip-shell system . . cp. $srcdir/$CPE_DICT $builddir/$CPE_DICT
17 echoscip-shell system . . echo. "Applicable CPE (set in '$CPE_DICT'): $CPE"
18 }
19
20 function test_cpescip-shell shell shell-project 0.0.0 test_cpe(). {
21 local CPE=$1
22 local EXPECTED_NA=$2
23 local TMP_RESULTS=`mktempscip-shell system . . mktemp.`
24
25 # Create XCCDF file with CPE based on RHEL/FEDORA version.
26 rmscip-shell system . . rm. -f $builddir/$XCCDF
27 cpscip-shell system . . cp. $srcdir/$XCCDF $builddir/$XCCDF
28 xsed -i "s|<<CPE>>|${CPE}|" $builddir/$XCCDF
29
30 echoscip-shell system . . echo. "Tested CPE: $CPE"
31 $OSCAP xccdf eval --cpe $builddir/$CPE_DICT --results $TMP_RESULTS $builddir/$XCCDF
32 if [scip-shell system . . `[`. $? -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 rmscip-shell system . . rm. -f $TMP_RESULTS
39
40 if [scip-shell system . . `[`. "$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_setupscip-shell shell shell-project 0.0.0 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