| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | . $builddir/tests/test_common.sh |
| 3 | |
| 4 | set -e |
| 5 | set -o pipefail |
| 6 | |
| 7 | name=$(basenamescip-shell system . . basename. $0 .sh) |
| 8 | stderr=$(make_temp_file /tmpscip-shell filesystem . . `/tmp`. ${name}.out) |
| 9 | tmpdir=$(make_temp_dir /tmpscip-shell filesystem . . `/tmp`. ${name}.out) |
| 10 | result=$(make_temp_file ${tmpdir} ${name}.out) |
| 11 | |
| 12 | echoscip-shell system . . echo. "Stderr file = $stderr" |
| 13 | echoscip-shell system . . echo. "Result file = $stderr" |
| 14 | rmscip-shell system . . rm. -f test_file |
| 15 | |
| 16 | # |
| 17 | # First, ensure that fix is not applied if it is not applicable |
| 18 | # |
| 19 | ret=0 |
| 20 | $OSCAP xccdf remediate --results $result $srcdir/${name}.xccdf.xml 2> $stderr || ret=$? |
| 21 | [scip-shell system . . `[`. $ret -eq 2 ] |
| 22 | [scip-shell system . . `[`. -f $stderr ]; [scip-shell system . . `[`. ! -s $stderr ]; :> $stderr |
| 23 | [scip-shell system . . `[`. ! -f test_file ] |
| 24 | |
| 25 | $OSCAP xccdf validate --skip-schematron $result |
| 26 | assert_exists 2 '//TestResult' |
| 27 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile"]' |
| 28 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]' |
| 29 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result' |
| 30 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result' |
| 31 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result[text()="fail"]' |
| 32 | assert_exists 0 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix' |
| 33 | |
| 34 | # one message expected signalling no suitable fix found. |
| 35 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/message' |
| 36 | |
| 37 | |
| 38 | # |
| 39 | # Second, make sure that the fix is applied, when CPE is recognized as appplicable |
| 40 | # |
| 41 | :> $result |
| 42 | $OSCAP xccdf remediate --cpe $srcdir/cpe-dict.xml --results $result $srcdir/${name}.xccdf.xml 2> $stderr |
| 43 | [scip-shell system . . `[`. -f $stderr ]; [scip-shell system . . `[`. ! -s $stderr ]; :> $stderr |
| 44 | [scip-shell system . . `[`. -f test_file ]; rmscip-shell system . . rm. test_file |
| 45 | |
| 46 | $OSCAP xccdf validate --skip-schematron $result |
| 47 | assert_exists 2 '//TestResult' |
| 48 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]' |
| 49 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]' |
| 50 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result' |
| 51 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result' |
| 52 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result[text()="fixed"]' |
| 53 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix' |
| 54 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix[@platform]' |
| 55 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix[@platform="cpe:/o:example:applicable:5"]' |
| 56 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/message' |
| 57 | |
| 58 | # Assert that input data was not modified. |
| 59 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile"]' |
| 60 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile"]/title' |
| 61 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile"]/title[text()="OSCAP Scan Result"]' |
| 62 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile"]/target' |
| 63 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile"]/target[text()="x.x.example.com"]' |
| 64 | assert_exists 2 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile"]/target-address' |
| 65 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile"]/target-address[text()="127.0.0.1"]' |
| 66 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile"]/target-address[text()="0:0:0:0:0:0:0:1"]' |
| 67 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile"]/target-facts' |
| 68 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile"]/target-facts/fact' |
| 69 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile"]/rule-result' |
| 70 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile"]/rule-result/result' |
| 71 | assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile"]/rule-result/result[text()="fail"]' |
| 72 | assert_exists 0 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile"]/rule-result/fix' |
| 73 | assert_exists 0 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile"]/rule-result/message' |
| 74 | |
| 75 | rmscip-shell system . . rm. $result |