1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
#!/usr/bin/env bash
# Copyright 2012 Red Hat Inc., Durham, North Carolina.
# All Rights Reserved.
set -e -o pipefail
. $srcdir/../../../test_common.sh
function test_api_xccdf_cpe_eval {
local INPUT=$srcdir/$1
local CPE_DICT=$srcdir/$2
local EXPECTED_NA=$3
local TMP_RESULTS=`mktemp`
$OSCAP xccdf eval --cpe $CPE_DICT --results $TMP_RESULTS $INPUT
if [ "$?" != "0" ]; then
return 1
fi
local NOTAPPLICABLE_COUNT=$($XPATH $TMP_RESULTS 'count(//result[text()="notapplicable"])')
rm -f $TMP_RESULTS
if [ "$NOTAPPLICABLE_COUNT" == "$EXPECTED_NA" ]; then
return 0
fi
return 1
}
function test_api_xccdf_cpe2_eval {
local INPUT=$srcdir/$1
local CPE_DICT=$srcdir/$2
local EXPECTED_NA=$3
local TMP_RESULTS=`mktemp`
$OSCAP xccdf eval --cpe $CPE_DICT --results $TMP_RESULTS $INPUT
if [ "$?" != "0" ]; then
return 1
fi
local NOTAPPLICABLE_COUNT=$($XPATH $TMP_RESULTS 'count(//result[text()="notapplicable"])')
rm -f $TMP_RESULTS
if [ "$NOTAPPLICABLE_COUNT" == "$EXPECTED_NA" ]; then
return 0
fi
return 1
}
function test_api_xccdf_embedded_cpe_eval {
local INPUT=$srcdir/$1
local EXPECTED_NA=$2
local TMP_RESULTS=`mktemp`
$OSCAP xccdf eval --results $TMP_RESULTS $INPUT
if [ "$?" != "0" ]; then
return 1
fi
local NOTAPPLICABLE_COUNT=$($XPATH $TMP_RESULTS 'count(//result[text()="notapplicable"])')
rm -f $TMP_RESULTS
if [ "$NOTAPPLICABLE_COUNT" == "$EXPECTED_NA" ]; then
return 0
fi
return 1
}
# Testing.
test_init "test_api_xccdf_applicability.log"
test_run "test_api_xccdf_applicability_cpe_applicable_rule" test_api_xccdf_cpe_eval applicable-rule-xccdf.xml cpe-dict.xml 0
test_run "test_api_xccdf_applicability_cpe_applicable_embedded_rule" test_api_xccdf_embedded_cpe_eval applicable-rule-embedded-xccdf.xml 0
test_run "test_api_xccdf_applicability_cpe_applicable_benchmark" test_api_xccdf_cpe_eval applicable-benchmark-xccdf.xml cpe-dict.xml 0
test_run "test_api_xccdf_applicability_cpe_nonexistant_platforms_rule" test_api_xccdf_cpe_eval nonexistant-platforms-rule-xccdf.xml cpe-dict.xml 1
test_run "test_api_xccdf_applicability_cpe2_applicable_rule" test_api_xccdf_cpe2_eval cpe2-applicable-rule-xccdf.xml cpe2-dict.xml 0
test_run "test_api_xccdf_applicability_cpe2_applicable_embedded_rule" test_api_xccdf_embedded_cpe_eval cpe2-applicable-rule-embedded-xccdf.xml 0
test_run "test_api_xccdf_applicability_cpe2_negated_applicable_embedded_rule" test_api_xccdf_embedded_cpe_eval cpe2-negated-applicable-rule-embedded-xccdf.xml 1
test_run "test_api_xccdf_applicability_cpe2_and_embedded_rule" test_api_xccdf_embedded_cpe_eval cpe2-and-rule-embedded-xccdf.xml 2
test_run "test_api_xccdf_applicability_cpe2_or_embedded_rule" test_api_xccdf_embedded_cpe_eval cpe2-or-rule-embedded-xccdf.xml 0
test_run "test_api_xccdf_applicability_cpe2_applicable_embedded_rule_with_cpe_dict" test_api_xccdf_cpe_eval cpe2-applicable-rule-embedded-xccdf-combined.xml cpe-dict.xml 0
test_run "test_api_xccdf_applicability_cpe2_not_applicable_embedded_rule_with_cpe_dict" test_api_xccdf_cpe_eval cpe2-notapplicable-rule-embedded-xccdf-combined.xml cpe-dict.xml 1
test_run "xccdf:fix applicable and notapplicable" $srcdir/test_remediate_fix_notapplicable.sh
test_run "Complex selection of xccdf:fix based multiple factors" $srcdir/test_remediate_fix_processing.sh
test_run "Complex selection of xccdf:fix + DataStream" $srcdir/test_remediate_fix_processing_ds.sh
test_run "Generate fix just as the Anaconda does + CPE" $srcdir/test_report_anaconda_fixes.sh
test_exit
|