| 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 | benchmark=$srcdir/${name}.xccdf.xml |
| 11 | tailoring=$srcdir/${name}_tailoring.xccdf.xml |
| 12 | echo "Stderr file = $stderr" |
| 13 | echo "Result file = $result" |
| 14 | ret=0 |
| 15 | |
| 16 | touch test_file |
| 17 | [ -f test_file ] |
| 18 | |
| 19 | # Multiple matches should result in failure |
| 20 | $OSCAP xccdf eval --profile common $benchmark 2> $stderr || ret=$? |
| 21 | [ $ret -eq 1 ] |
| 22 | # Checks that first test does result in multiple match error |
| 23 | grep -Fq "Multiple matches found" $stderr |
| 24 | |
| 25 | # Should pass, because underscore creates unique suffix |
| 26 | $OSCAP xccdf eval --profile _common --results $result $benchmark 2> $stderr |
| 27 | # Checks that full profile name is used in rule evaluation |
| 28 | grep -Fq xccdf_org.open-scap_testresult_xccdf_moc.elpmaxe.www_profile_common $result |
| 29 | |
| 30 | # Should fail, because a profile with this suffix does not exist |
| 31 | $OSCAP xccdf eval --profile xcommon $benchmark 2> $stderr || ret=$? |
| 32 | [ $ret -eq 1 ] |
| 33 | # Checks that last test does result in no match error |
| 34 | grep -Fq "No profile matching suffix \"xcommon\" was found" $stderr |
| 35 | |
| 36 | |
| 37 | # Should pass, because only one match is in tailoring file, which takes precedence |
| 38 | $OSCAP xccdf eval --tailoring-file $tailoring --profile common $benchmark 2> $stderr |
| 39 | # Checks that full profile name is used in rule evaluation |
| 40 | grep -Fq xccdf_org.open-scap_testresult_xccdf_moc.elpmaxe.www_profile_common $result |
| 41 | |
| 42 | # Should fail, because there will be multiple suffix matches |
| 43 | $OSCAP xccdf eval --tailoring-file $tailoring --profile her $benchmark 2> $stderr || ret=$? |
| 44 | [ $ret -eq 1 ] |
| 45 | # Checks that multiple match error does result |
| 46 | grep -Fq "Multiple matches found" $stderr |
| 47 | |
| 48 | # Should pass, because underscore creates unique suffix |
| 49 | $OSCAP xccdf eval --tailoring-file $tailoring --profile _her --results $result $benchmark 2> $stderr |
| 50 | # Checks that full profile name is used in rule evaluation |
| 51 | grep -Fq xccdf_org.open-scap_testresult_xccdf_org.ssgproject.content_profile_her $result |
| 52 | |
| 53 | # Should fail, because a profile with this suffix does not exist |
| 54 | $OSCAP xccdf eval --tailoring-file $tailoring --profile another $benchmark 2> $stderr || ret=$? |
| 55 | [ $ret -eq 1 ] |
| 56 | # Checks that last test does result in no match error |
| 57 | grep -Fq "No profile matching suffix \"another\" was found" $stderr |
| 58 | |
| 59 | [ -f $stderr ]; rm $stderr |
| 60 | rm $result |
| 61 | |
| 62 | rm -f test_file |