| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Copyright 2012 Red Hat Inc., Durham, North Carolina. |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # OpenScap XCCDF Module Test Suite. |
| 7 | # |
| 8 | # Authors: |
| 9 | # Peter Vrabec <[email protected]> |
| 10 | |
| 11 | set -e -o pipefail |
| 12 | |
| 13 | . $builddir/tests/test_common.sh |
| 14 | |
| 15 | # Test cases. |
| 16 | |
| 17 | function test_api_xccdf_export { |
| 18 | local INPUT=$srcdir/$1 |
| 19 | local OUTPUT=$1.out |
| 20 | |
| 21 | ./test_api_xccdf --export $INPUT $OUTPUT |
| 22 | |
| 23 | # Workaround libxml2 on rhel5 which exports namespace declarations in different order. |
| 24 | xsed -i 's|<cpe-list xmlns="http://cpe.mitre.org/XMLSchema/cpe/1.0" xmlns:meta="http://scap.nist.gov/schema/cpe-dictionary-metadata/0.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"|<cpe-list xmlns:meta="http://scap.nist.gov/schema/cpe-dictionary-metadata/0.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://cpe.mitre.org/XMLSchema/cpe/1.0"|' $OUTPUT |
| 25 | |
| 26 | if [ $? -eq 0 ]; then |
| 27 | if ! $XMLDIFF $INPUT $OUTPUT; then |
| 28 | echo "Exported file differs from what is expected!" |
| 29 | return 1 |
| 30 | fi |
| 31 | else |
| 32 | echo "Cannot export xccdf content!" |
| 33 | return 1 |
| 34 | fi |
| 35 | |
| 36 | rm $OUTPUT |
| 37 | return 0 |
| 38 | } |
| 39 | |
| 40 | function test_api_xccdf_validate { |
| 41 | local INPUT=$1 |
| 42 | local VER=$2 |
| 43 | |
| 44 | bash $builddir/run ./test_api_xccdf --validate $VER $srcdir/$INPUT |
| 45 | return $([ $? -eq 0 ]) |
| 46 | } |
| 47 | |
| 48 | # Testing. |
| 49 | |
| 50 | test_init |
| 51 | |
| 52 | if [ -z ${CUSTOM_OSCAP+x} ] ; then |
| 53 | test_run "export xccdf 1.1" test_api_xccdf_export xccdf11.xml |
| 54 | test_run "validate xccdf 1.1" test_api_xccdf_validate xccdf11.xml "1.1" |
| 55 | test_run "export xccdf 1.2" test_api_xccdf_export xccdf12.xml |
| 56 | test_run "validate xccdf 1.2" test_api_xccdf_validate xccdf12.xml "1.2" |
| 57 | test_run "export xccdf results 1.1" test_api_xccdf_export xccdf11-results.xml |
| 58 | fi |
| 59 | |
| 60 | test_exit |