|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +. $builddir/tests/test_common.sh |
| 4 | + |
| 5 | +set -e -o pipefail |
| 6 | + |
| 7 | +autotailor="$top_srcdir/utils/autotailor" |
| 8 | +tailoring="$(mktemp)" |
| 9 | +ds="$srcdir/data_stream.xml" |
| 10 | +stdout="$(mktemp)" |
| 11 | +original_profile="P1" |
| 12 | +result="$(mktemp)" |
| 13 | + |
| 14 | +# the original profile P1 selects rules R1 and R2 |
| 15 | + |
| 16 | +# select additional rule R3 |
| 17 | +python3 $autotailor --id-namespace "com.example.www" --select R3 $ds $original_profile > $tailoring |
| 18 | +$OSCAP xccdf eval --profile P1_customized --progress --tailoring-file $tailoring --results $result $ds |
| 19 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1"]/result[text()="pass"]' |
| 20 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2"]/result[text()="pass"]' |
| 21 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="pass"]' |
| 22 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="notselected"]' |
| 23 | + |
| 24 | +# select additional rules R3, R4 |
| 25 | +python3 $autotailor --id-namespace "com.example.www" --select R3 --select R4 $ds $original_profile > $tailoring |
| 26 | +$OSCAP xccdf eval --profile P1_customized --progress --tailoring-file $tailoring --results $result $ds |
| 27 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1"]/result[text()="pass"]' |
| 28 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2"]/result[text()="pass"]' |
| 29 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="pass"]' |
| 30 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="pass"]' |
| 31 | + |
| 32 | +# unselect rule R2 |
| 33 | +python3 $autotailor --id-namespace "com.example.www" --unselect R2 $ds $original_profile > $tailoring |
| 34 | +$OSCAP xccdf eval --profile P1_customized --progress --tailoring-file $tailoring --results $result $ds |
| 35 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1"]/result[text()="pass"]' |
| 36 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2"]/result[text()="notselected"]' |
| 37 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="notselected"]' |
| 38 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="notselected"]' |
| 39 | + |
| 40 | +# unselect rule R2 and select R4 |
| 41 | +python3 $autotailor --id-namespace "com.example.www" --unselect R2 --select R4 $ds $original_profile > $tailoring |
| 42 | +$OSCAP xccdf eval --profile P1_customized --progress --tailoring-file $tailoring --results $result $ds |
| 43 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1"]/result[text()="pass"]' |
| 44 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2"]/result[text()="notselected"]' |
| 45 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="notselected"]' |
| 46 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="pass"]' |
| 47 | + |
| 48 | +# select additional rule R3 and change its severity to high |
| 49 | +python3 $autotailor --id-namespace "com.example.www" --select R3 --rule-severity R3=high $ds $original_profile > $tailoring |
| 50 | +$OSCAP xccdf eval --profile P1_customized --progress --tailoring-file $tailoring --results $result $ds |
| 51 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1"]/result[text()="pass"]' |
| 52 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1" and @severity="unknown"]' |
| 53 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2"]/result[text()="pass"]' |
| 54 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2" and @severity="unknown"]' |
| 55 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="pass"]' |
| 56 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3" and @severity="high"]' |
| 57 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="notselected"]' |
| 58 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4" and @severity="unknown"]' |
| 59 | + |
| 60 | +# don't select rules, don't unselect rules, but change severity of all rules to high |
| 61 | +python3 $autotailor --id-namespace "com.example.www" --rule-severity R1=high --rule-severity R2=high --rule-severity R3=high --rule-severity R4=high $ds $original_profile > $tailoring |
| 62 | +$OSCAP xccdf eval --profile P1_customized --progress --tailoring-file $tailoring --results $result $ds |
| 63 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1"]/result[text()="pass"]' |
| 64 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1" and @severity="high"]' |
| 65 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2"]/result[text()="pass"]' |
| 66 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2" and @severity="high"]' |
| 67 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="notselected"]' |
| 68 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3" and @severity="high"]' |
| 69 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="notselected"]' |
| 70 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4" and @severity="high"]' |
| 71 | + |
| 72 | + |
| 73 | +# select additional rule R4 and change its role to "unchecked" |
| 74 | +python3 $autotailor --id-namespace "com.example.www" --select R4 --rule-role R4=unchecked $ds $original_profile > $tailoring |
| 75 | +$OSCAP xccdf eval --profile P1_customized --progress --tailoring-file $tailoring --results $result $ds |
| 76 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1"]/result[text()="pass"]' |
| 77 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1" and @role="full"]' |
| 78 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2"]/result[text()="pass"]' |
| 79 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2" and @role="full"]' |
| 80 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="notselected"]' |
| 81 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3" and @role="full"]' |
| 82 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="notchecked"]' |
| 83 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4" and @role="unchecked"]' |
| 84 | + |
| 85 | + |
| 86 | +# select additional rule R3; the customized profile will have a special profile ID |
| 87 | +customized_profile="xccdf_com.pink.elephant_profile_pineapple" |
| 88 | +python3 $autotailor --new-profile-id $customized_profile --id-namespace "com.example.www" --select R3 $ds $original_profile > $tailoring |
| 89 | +$OSCAP xccdf eval --profile $customized_profile --progress --tailoring-file $tailoring --results $result $ds |
| 90 | +assert_exists 1 '/Benchmark/TestResult[@id="xccdf_org.open-scap_testresult_'$customized_profile'"]' |
| 91 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1"]/result[text()="pass"]' |
| 92 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2"]/result[text()="pass"]' |
| 93 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="pass"]' |
| 94 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="notselected"]' |
| 95 | + |
| 96 | +# refine value v1 to 30 |
| 97 | +python3 $autotailor --id-namespace "com.example.www" --var-value V1=thirty $ds $original_profile > $tailoring |
| 98 | +$OSCAP xccdf eval --profile P1_customized --progress --tailoring-file $tailoring --results $result $ds |
| 99 | +assert_exists 1 '/Benchmark/TestResult/set-value[@idref="xccdf_com.example.www_value_V1" and text()="thirty"]' |
| 100 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1"]/result[text()="pass"]' |
| 101 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2"]/result[text()="pass"]' |
| 102 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="notselected"]' |
| 103 | +assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="notselected"]' |
0 commit comments