| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Copyright 2012 Red Hat Inc., Durham, North Carolina. |
| 4 | # All Rights Reserved. |
| 5 | |
| 6 | set -e -o pipefail |
| 7 | |
| 8 | . $builddir/tests/test_common.sh |
| 9 | |
| 10 | function test_api_xccdf_cpe_eval { |
| 11 | local INPUT=$srcdir/$1 |
| 12 | local CPE_DICT=$srcdir/$2 |
| 13 | local EXPECTED_NA=$3 |
| 14 | |
| 15 | result=$(make_temp_file /tmp tmp) |
| 16 | $OSCAP xccdf eval --cpe $CPE_DICT --results $result $INPUT |
| 17 | if [ "$?" != "0" ]; then |
| 18 | return 1 |
| 19 | fi |
| 20 | |
| 21 | assert_exists $EXPECTED_NA '//result[text()="notapplicable"]' |
| 22 | rm -f $result |
| 23 | } |
| 24 | |
| 25 | # Testing. |
| 26 | |
| 27 | test_init "test_api_xccdf_applicability.log" |
| 28 | |
| 29 | test_run "test_api_xccdf_applicability_cpe_applicable_rule" test_api_xccdf_cpe_eval applicable-rule-xccdf.xml cpe-dict.xml 0 |
| 30 | test_run "test_api_xccdf_applicability_cpe_applicable_benchmark" test_api_xccdf_cpe_eval applicable-benchmark-xccdf.xml cpe-dict.xml 0 |
| 31 | test_run "test_api_xccdf_applicability_cpe_nonexistant_platforms_rule" test_api_xccdf_cpe_eval nonexistant-platforms-rule-xccdf.xml cpe-dict.xml 1 |
| 32 | 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 |
| 33 | 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 |
| 34 | |
| 35 | test_exit |