| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . $builddir/tests/test_common.sh |
| 4 | |
| 5 | set -e -o pipefail |
| 6 | |
| 7 | |
| 8 | function test_prefer_sce_on () { |
| 9 | stdout=$(mktemp) |
| 10 | stderr=$(mktemp) |
| 11 | arf=$(mktemp) |
| 12 | |
| 13 | OSCAP_PREFERRED_ENGINE="SCE" $OSCAP xccdf eval --verbose INFO --progress --profile common --results-arf "$arf" > "$stdout" 2> "$stderr" "$srcdir/test_prefer_sce.ds.xml" || ret="$?" |
| 14 | grep -q "xccdf_org.openscap.www_rule_1:fail" "$stdout" |
| 15 | ! grep -q "I: oscap: Evaluating definition 'oval:org.openscap.www:def:1': OVAL check for rule 1." "$stderr" |
| 16 | grep -q "I: oscap: Executing SCE check 'fedora/checks/sce/rule_1.sh'" "$stderr" |
| 17 | |
| 18 | rm -rf "$stdout" "$stderr" "$arf" |
| 19 | } |
| 20 | |
| 21 | test_prefer_sce_off () { |
| 22 | stdout=$(mktemp) |
| 23 | stderr=$(mktemp) |
| 24 | arf=$(mktemp) |
| 25 | |
| 26 | $OSCAP xccdf eval --verbose INFO --progress --profile common --results-arf "$arf" > "$stdout" 2> "$stderr" "$srcdir/test_prefer_sce.ds.xml" || ret="$?" |
| 27 | grep -q "xccdf_org.openscap.www_rule_1:pass" "$stdout" |
| 28 | grep -q "I: oscap: Evaluating definition 'oval:org.openscap.www:def:1': OVAL check for rule 1." "$stderr" |
| 29 | ! grep -q "I: oscap: Executing SCE check 'fedora/checks/sce/rule_1.sh'" "$stderr" |
| 30 | |
| 31 | rm -rf "$stdout" "$stderr" "$arf" |
| 32 | } |
| 33 | |
| 34 | test_prefer_oval_explicit () { |
| 35 | stdout=$(mktemp) |
| 36 | stderr=$(mktemp) |
| 37 | arf=$(mktemp) |
| 38 | |
| 39 | OSCAP_PREFERRED_ENGINE="OVAL" $OSCAP xccdf eval --verbose INFO --progress --profile common --results-arf "$arf" > "$stdout" 2> "$stderr" "$srcdir/test_prefer_sce.ds.xml" || ret="$?" |
| 40 | grep -q "xccdf_org.openscap.www_rule_1:pass" "$stdout" |
| 41 | grep -q "I: oscap: Evaluating definition 'oval:org.openscap.www:def:1': OVAL check for rule 1." "$stderr" |
| 42 | ! grep -q "I: oscap: Executing SCE check 'fedora/checks/sce/rule_1.sh'" "$stderr" |
| 43 | |
| 44 | rm -rf "$stdout" "$stderr" "$arf" |
| 45 | } |
| 46 | |
| 47 | test_invalid_envi_variable () { |
| 48 | stdout=$(mktemp) |
| 49 | stderr=$(mktemp) |
| 50 | arf=$(mktemp) |
| 51 | |
| 52 | OSCAP_PREFERRED_ENGINE="FOOBARVIM" $OSCAP xccdf eval --verbose INFO --progress --profile common --results-arf "$arf" > "$stdout" 2> "$stderr" "$srcdir/test_prefer_sce.ds.xml" || ret="$?" |
| 53 | grep -q "Unknown value of OSCAP_PREFFERED_ENGINE: 'FOOBARVIM'. It will be ignored." "$stderr" |
| 54 | grep -q "xccdf_org.openscap.www_rule_1:pass" "$stdout" |
| 55 | grep -q "I: oscap: Evaluating definition 'oval:org.openscap.www:def:1': OVAL check for rule 1." "$stderr" |
| 56 | ! grep -q "I: oscap: Executing SCE check 'fedora/checks/sce/rule_1.sh'" "$stderr" |
| 57 | |
| 58 | rm -rf "$stdout" "$stderr" "$arf" |
| 59 | } |
| 60 | |
| 61 | test_prefer_sce_on |
| 62 | test_prefer_sce_off |
| 63 | test_prefer_oval_explicit |
| 64 | test_invalid_envi_variable |