| 1 | #!/usr/bin/env bash |
| 2 | . $builddir/tests/test_common.sh |
| 3 | |
| 4 | set -e |
| 5 | set -o pipefail |
| 6 | |
| 7 | name=$(basename $0 .sh) |
| 8 | stderr=$(mktemp -t ${name}.out.XXXXXX) |
| 9 | result=$(mktemp -t ${name}.out.XXXXXX) |
| 10 | echo "Stderr file = $stderr" |
| 11 | echo "Result file = $stderr" |
| 12 | rm -f test_file |
| 13 | |
| 14 | $OSCAP xccdf remediate --skip-validation --results $result $srcdir/${name}.xccdf.xml 2> $stderr |
| 15 | [ -f $stderr ]; [ ! -s $stderr ]; rm $stderr |
| 16 | [ -f test_file ]; rm test_file |
| 17 | |
| 18 | assert_exists 1 '//Rule' |
| 19 | assert_exists 1 '//Rule/fix' |
| 20 | assert_exists 1 '//Rule/fix[@system="urn:xccdf:fix:script:python3"]' |
| 21 | assert_exists 0 '//Rule/fix/sub' |
| 22 | assert_exists 3 '//Rule/fix/xhtml:object' |
| 23 | assert_exists 2 '//TestResult' |
| 24 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]' |
| 25 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result' |
| 26 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result' |
| 27 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result[text()="fixed"]' |
| 28 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix' |
| 29 | assert_exists 0 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/sub' |
| 30 | assert_exists 0 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/object' |
| 31 | assert_exists 0 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/xhtml:object' |
| 32 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix[contains(text(), "import os")]' |
| 33 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix[contains(text(), "touch('"'"'test_file'"'"')")]' |
| 34 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/message' |
| 35 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/message[text()="Fix execution completed and returned: 0"]' |
| 36 | |
| 37 | rm $result |