| 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 | sds=$srcdir/test_remediate_fix_processing.xccdf.xml |
| 9 | stderr=$(make_temp_file /tmp ${name}.out) |
| 10 | resultx=$(make_temp_file /tmp ${name}.xccdf) |
| 11 | arf=$(make_temp_file /tmp ${name}.arf) |
| 12 | echo "sds file: $sds" |
| 13 | echo "stderr file: $stderr" |
| 14 | echo "results file: $result" |
| 15 | rm -f test_file test_file_cpe_na wrong_test_file |
| 16 | |
| 17 | [ -f $stderr ]; [ ! -s $stderr ] |
| 18 | $OSCAP ds sds-validate $sds |
| 19 | |
| 20 | # First, try to apply a wrong fix due to missing CPE. |
| 21 | ret=0 |
| 22 | $OSCAP xccdf eval --remediate --results $resultx --results-arf $arf $sds 2> $stderr || ret=$? |
| 23 | [ $ret -eq 2 ] |
| 24 | [ -f $stderr ]; [ ! -s $stderr ] |
| 25 | [ ! -f test_file ] |
| 26 | [ ! -f wrong_test_file ] |
| 27 | [ -f test_file_cpe_na ]; rm test_file_cpe_na |
| 28 | |
| 29 | $OSCAP xccdf validate --skip-schematron $resultx |
| 30 | $OSCAP ds rds-validate $arf |
| 31 | |
| 32 | result=$resultx |
| 33 | assert_exists 2 '//TestResult' |
| 34 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]' |
| 35 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result' |
| 36 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result' |
| 37 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result[text()="error"]' |
| 38 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix' |
| 39 | assert_exists 2 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/@*' |
| 40 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/@system' |
| 41 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix[@system="urn:xccdf:fix:script:sh"]' |
| 42 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/@reboot' |
| 43 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix[@reboot="true"]' |
| 44 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/text()[contains(., "touch test_file_cpe_na")]' |
| 45 | assert_exists 2 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/message' |
| 46 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/message[text()="Fix execution completed and returned: 0"]' |
| 47 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/message[text()="Failed to verify applied fix: Checking engine returns: fail"]' |
| 48 | result=$arf |
| 49 | assert_exists 3 '//TestResult' |
| 50 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]' |
| 51 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result' |
| 52 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result' |
| 53 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result[text()="error"]' |
| 54 | |
| 55 | :> $result |
| 56 | :> $arf |
| 57 | $OSCAP xccdf eval --cpe $srcdir/cpe-dict.xml --remediate --results $resultx --results-arf $arf $sds 2> $stderr |
| 58 | [ -f $stderr ]; [ ! -s $stderr ]; rm $stderr |
| 59 | [ -f test_file ]; rm test_file |
| 60 | [ ! -f wrong_test_file ] |
| 61 | [ ! -f test_file_cpe_na ] |
| 62 | |
| 63 | $OSCAP xccdf validate --skip-schematron $resultx |
| 64 | $OSCAP ds rds-validate $arf |
| 65 | |
| 66 | result=$resultx |
| 67 | assert_exists 2 '//TestResult' |
| 68 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]' |
| 69 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result' |
| 70 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result' |
| 71 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result[text()="fixed"]' |
| 72 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix' |
| 73 | assert_exists 3 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/@*' |
| 74 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/@system' |
| 75 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix[@system="urn:xccdf:fix:script:sh"]' |
| 76 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/@disruption' |
| 77 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix[@disruption="low"]' |
| 78 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/@platform' |
| 79 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix[@platform="cpe:/o:example:applicable:5"]' |
| 80 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/text()[contains(., "touch test_file")]' |
| 81 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/message' |
| 82 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/message[text()="Fix execution completed and returned: 0"]' |
| 83 | result=$arf |
| 84 | assert_exists 3 '//TestResult' |
| 85 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]' |
| 86 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result' |
| 87 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result' |
| 88 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result[text()="fixed"]' |
| 89 | |
| 90 | rm $resultx $arf |