| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Copyright 2009 Red Hat Inc., Durham, North Carolina. |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # OpenScap Probes Test Suite. |
| 7 | # |
| 8 | # Created on: Nov 30, 2009 |
| 9 | # |
| 10 | # Authors: |
| 11 | # Peter Vrabec, <[email protected]> |
| 12 | # David Niemoller |
| 13 | # Ondrej Moris, <[email protected]> |
| 14 | |
| 15 | . $builddir/tests/test_common.sh |
| 16 | |
| 17 | # Test Cases. |
| 18 | |
| 19 | function test_probes_filehash58_old_algos { |
| 20 | |
| 21 | probecheck "filehash58" || return 255 |
| 22 | require "md5sum" || return 255 |
| 23 | require "sha1sum" || return 255 |
| 24 | |
| 25 | local ret_val=0; |
| 26 | local DF="test_probes_filehash58_old_algos.xml" |
| 27 | local RF="results.xml" |
| 28 | |
| 29 | [ -f $RF ] && rm -f $RF |
| 30 | |
| 31 | bash ${srcdir}/test_probes_filehash58_old_algos.xml.sh > $DF |
| 32 | $OSCAP oval eval --results $RF $DF |
| 33 | |
| 34 | if [ -f $RF ]; then |
| 35 | verify_results "def" $DF $RF 13 && verify_results "tst" $DF $RF 120 |
| 36 | ret_val=$? |
| 37 | else |
| 38 | ret_val=1 |
| 39 | fi |
| 40 | |
| 41 | # The file was created as a side-effect of test_probes_filehash58_old_algos.xml.sh |
| 42 | [ $ret_val -eq 0 ] && rm -f /tmp/test_probes_filehash58.tmp |
| 43 | |
| 44 | return $ret_val |
| 45 | } |
| 46 | |
| 47 | function test_probes_filehash58_new_algos { |
| 48 | |
| 49 | probecheck "filehash58" || return 255 |
| 50 | require "sha256sum" || return 255 |
| 51 | require "sha512sum" || return 255 |
| 52 | |
| 53 | local ret_val=0 |
| 54 | local DF="test_probes_filehash58_new_algos.xml" |
| 55 | local RF="results.xml" |
| 56 | |
| 57 | [ -f $RF ] && rm -f $RF |
| 58 | |
| 59 | bash ${srcdir}/test_probes_filehash58_new_algos.xml.sh > $DF |
| 60 | $OSCAP oval eval --results $RF $DF |
| 61 | |
| 62 | if [ -f $RF ]; then |
| 63 | verify_results "def" $DF $RF 13 && verify_results "tst" $DF $RF 120 |
| 64 | ret_val=$? |
| 65 | else |
| 66 | ret_val=1 |
| 67 | fi |
| 68 | |
| 69 | # The file was created as a side-effect of test_probes_filehash58_new_algos.xml.sh |
| 70 | [ $ret_val -eq 0 ] && rm -f /tmp/test_probes_filehash58.tmp |
| 71 | |
| 72 | return $ret_val |
| 73 | } |
| 74 | |
| 75 | |
| 76 | # $1: The chroot directory |
| 77 | function test_probes_filehash58_chroot { |
| 78 | |
| 79 | probecheck "filehash58" || return 255 |
| 80 | |
| 81 | local ret_val=0; |
| 82 | local DF="$srcdir/check_filehash_simple.xml" |
| 83 | |
| 84 | absolute_probe_root=$(cd "$1" && pwd) |
| 85 | |
| 86 | # oscap-chroot is not readily available during test run, so we use oscap + env var setting. |
| 87 | result_keyword=$(OSCAP_PROBE_ROOT="$absolute_probe_root" $OSCAP oval eval "$DF" | grep oval_test_has_hash | grep -o '\w*$') |
| 88 | |
| 89 | [ "$result_keyword" == "$2" ] && return 0 |
| 90 | # vvv This is more a test error than a failure or "warning" vvv |
| 91 | [ "$result_keyword" == "" ] && return 2 |
| 92 | return 1 |
| 93 | } |
| 94 | |
| 95 | |
| 96 | function test_probes_filehash58_chroot_pass { |
| 97 | local ret_val=0 |
| 98 | |
| 99 | mkdir -p pass |
| 100 | echo foo > pass/oval-test |
| 101 | |
| 102 | test_probes_filehash58_chroot pass true |
| 103 | ret_val=$? |
| 104 | rm -rf pass |
| 105 | |
| 106 | return $ret_val |
| 107 | } |
| 108 | |
| 109 | |
| 110 | function test_probes_filehash58_chroot_fail { |
| 111 | local ret_val=0 |
| 112 | |
| 113 | mkdir -p fail |
| 114 | echo bar > fail/oval-test |
| 115 | |
| 116 | test_probes_filehash58_chroot fail false |
| 117 | ret_val=$? |
| 118 | rm -rf fail |
| 119 | |
| 120 | return $ret_val |
| 121 | } |
| 122 | |
| 123 | # Testing. |
| 124 | |
| 125 | test_init |
| 126 | |
| 127 | if [[ "$OPENSCAP_ENABLE_MD5" == "ON" && "$OPENSCAP_ENABLE_SHA1" == "ON" ]] ; then |
| 128 | test_run "test_probes_filehash58_old_algos" test_probes_filehash58_old_algos |
| 129 | fi |
| 130 | |
| 131 | test_run "test_probes_filehash58_new_algos" test_probes_filehash58_new_algos |
| 132 | |
| 133 | test_run "test_probes_filehash58_chroot_fail" test_probes_filehash58_chroot_fail |
| 134 | |
| 135 | test_run "test_probes_filehash58_chroot_pass" test_probes_filehash58_chroot_pass |
| 136 | |
| 137 | test_exit |