| 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 | json_tailoring="$srcdir/custom.json" |
| 11 | stdout="$(mktemp)" |
| 12 | original_profile="P1" |
| 13 | result="$(mktemp)" |
| 14 | |
| 15 | # the original profile P1 selects rules R1 and R2 |
| 16 | |
| 17 | # select additional rule R3 |
| 18 | python3 $autotailor --id-namespace "com.example.www" --select R3 $ds $original_profile > $tailoring |
| 19 | $OSCAP xccdf eval --profile P1_customized --progress --tailoring-file $tailoring --results $result $ds |
| 20 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1"]/result[text()="pass"]' |
| 21 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2"]/result[text()="pass"]' |
| 22 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="pass"]' |
| 23 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="notselected"]' |
| 24 | grep "xccdf-1.2:" $tailoring |
| 25 | |
| 26 | # select additional rules R3, R4 |
| 27 | python3 $autotailor --id-namespace "com.example.www" --select R3 --select R4 $ds $original_profile > $tailoring |
| 28 | $OSCAP xccdf eval --profile P1_customized --progress --tailoring-file $tailoring --results $result $ds |
| 29 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1"]/result[text()="pass"]' |
| 30 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2"]/result[text()="pass"]' |
| 31 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="pass"]' |
| 32 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="pass"]' |
| 33 | |
| 34 | # unselect rule R2 |
| 35 | python3 $autotailor --id-namespace "com.example.www" --unselect R2 $ds $original_profile > $tailoring |
| 36 | $OSCAP xccdf eval --profile P1_customized --progress --tailoring-file $tailoring --results $result $ds |
| 37 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1"]/result[text()="pass"]' |
| 38 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2"]/result[text()="notselected"]' |
| 39 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="notselected"]' |
| 40 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="notselected"]' |
| 41 | |
| 42 | # unselect rule R2 and select R4 |
| 43 | python3 $autotailor --id-namespace "com.example.www" --unselect R2 --select R4 $ds $original_profile > $tailoring |
| 44 | $OSCAP xccdf eval --profile P1_customized --progress --tailoring-file $tailoring --results $result $ds |
| 45 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1"]/result[text()="pass"]' |
| 46 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2"]/result[text()="notselected"]' |
| 47 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="notselected"]' |
| 48 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="pass"]' |
| 49 | |
| 50 | # select additional rule R3 and change its severity to high |
| 51 | python3 $autotailor --id-namespace "com.example.www" --select R3 --rule-severity R3=high $ds $original_profile > $tailoring |
| 52 | $OSCAP xccdf eval --profile P1_customized --progress --tailoring-file $tailoring --results $result $ds |
| 53 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1"]/result[text()="pass"]' |
| 54 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1" and @severity="unknown"]' |
| 55 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2"]/result[text()="pass"]' |
| 56 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2" and @severity="unknown"]' |
| 57 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="pass"]' |
| 58 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3" and @severity="high"]' |
| 59 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="notselected"]' |
| 60 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4" and @severity="unknown"]' |
| 61 | |
| 62 | # don't select rules, don't unselect rules, but change severity of all rules to high |
| 63 | 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 |
| 64 | $OSCAP xccdf eval --profile P1_customized --progress --tailoring-file $tailoring --results $result $ds |
| 65 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1"]/result[text()="pass"]' |
| 66 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1" and @severity="high"]' |
| 67 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2"]/result[text()="pass"]' |
| 68 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2" and @severity="high"]' |
| 69 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="notselected"]' |
| 70 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3" and @severity="high"]' |
| 71 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="notselected"]' |
| 72 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4" and @severity="high"]' |
| 73 | |
| 74 | # select additional rule R4 and change its role to "unchecked" |
| 75 | python3 $autotailor --id-namespace "com.example.www" --select R4 --rule-role R4=unchecked $ds $original_profile > $tailoring |
| 76 | $OSCAP xccdf eval --profile P1_customized --progress --tailoring-file $tailoring --results $result $ds |
| 77 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1"]/result[text()="pass"]' |
| 78 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1" and @role="full"]' |
| 79 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2"]/result[text()="pass"]' |
| 80 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2" and @role="full"]' |
| 81 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="notselected"]' |
| 82 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3" and @role="full"]' |
| 83 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="notchecked"]' |
| 84 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4" and @role="unchecked"]' |
| 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 | # set value v1 to thirty |
| 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"]' |
| 104 | |
| 105 | # refine value v1 to 'thirty' (30) and v2 to 'other' (Other Value) |
| 106 | python3 $autotailor --id-namespace "com.example.www" --var-select V1=thirty --var-select V2=other $ds $original_profile > $tailoring |
| 107 | $OSCAP xccdf eval --profile P1_customized --progress --tailoring-file $tailoring --results $result $ds |
| 108 | assert_exists 1 '/Benchmark/TestResult/set-value[@idref="xccdf_com.example.www_value_V1" and text()="30"]' |
| 109 | assert_exists 1 '/Benchmark/TestResult/set-value[@idref="xccdf_com.example.www_value_V2" and text()="Other Value"]' |
| 110 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1"]/result[text()="pass"]' |
| 111 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2"]/result[text()="pass"]' |
| 112 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="notselected"]' |
| 113 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="notselected"]' |
| 114 | |
| 115 | # use JSON tailoring (P1) |
| 116 | python3 $autotailor $ds --id-namespace "com.example.www" --json-tailoring $json_tailoring > $tailoring |
| 117 | $OSCAP xccdf eval --profile JSON_P1 --progress --tailoring-file $tailoring --results $result $ds |
| 118 | assert_exists 1 '/Benchmark/TestResult/set-value[@idref="xccdf_com.example.www_value_V1" and text()="New Value"]' |
| 119 | assert_exists 1 '/Benchmark/TestResult/set-value[@idref="xccdf_com.example.www_value_V2" and text()="Some Value"]' |
| 120 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R1"]/result[text()="notselected"]' |
| 121 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R2"]/result[text()="pass"]' |
| 122 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="notselected"]' |
| 123 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3" and @severity="unknown"]' |
| 124 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4"]/result[text()="notselected"]' |
| 125 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R4" and @role="unchecked"]' |
| 126 | |
| 127 | # use JSON tailoring (P11) |
| 128 | python3 $autotailor --id-namespace "com.example.www" --json-tailoring $json_tailoring $ds > $tailoring |
| 129 | $OSCAP xccdf eval --profile JSON_P11 --progress --tailoring-file $tailoring --results $result $ds |
| 130 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="pass"]' |
| 131 | |
| 132 | # use JSON tailoring (P11) with command-line override |
| 133 | python3 $autotailor --id-namespace "com.example.www" --json-tailoring $json_tailoring --tailored-profile-id=JSON_P11 --unselect R3 $ds > $tailoring |
| 134 | $OSCAP xccdf eval --profile JSON_P11 --progress --tailoring-file $tailoring --results $result $ds |
| 135 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="notselected"]' |
| 136 | |
| 137 | # use JSON tailoring (P11) with a new profile from the command line |
| 138 | python3 $autotailor --id-namespace "com.example.www" --json-tailoring $json_tailoring --tailored-profile-id=CMDL_P --select R3 $ds $original_profile > $tailoring |
| 139 | $OSCAP xccdf eval --profile CMDL_P --progress --tailoring-file $tailoring --results $result $ds |
| 140 | assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_com.example.www_rule_R3"]/result[text()="pass"]' |