| 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_probe_xinetd_parser { |
| 20 | local ret_val=0; |
| 21 | |
| 22 | ./test_probe_xinetd ${srcdir}/xinetd_A.conf foo tcp |
| 23 | if [ $? -ne 3 ]; then |
| 24 | ret_val=$[$ret_val + 1] |
| 25 | fi |
| 26 | |
| 27 | ./test_probe_xinetd ${srcdir}/xinetd_B.conf foo tcp |
| 28 | if [ $? -ne 0 ]; then |
| 29 | ret_val=$[$ret_val + 1] |
| 30 | fi |
| 31 | |
| 32 | ./test_probe_xinetd ${srcdir}/xinetd_C.conf a tcp |
| 33 | if [ $? -ne 0 ]; then |
| 34 | ret_val=$[$ret_val + 1] |
| 35 | fi |
| 36 | |
| 37 | ./test_probe_xinetd ${srcdir}/xinetd_D.conf f udp |
| 38 | if [ $? -ne 0 ]; then |
| 39 | ret_val=$[$ret_val + 1] |
| 40 | fi |
| 41 | |
| 42 | ./test_probe_xinetd ${srcdir}/xinetd_E.conf foo udp |
| 43 | if [ $? -ne 0 ]; then |
| 44 | ret_val=$[$ret_val + 1] |
| 45 | fi |
| 46 | |
| 47 | ./test_probe_xinetd ${srcdir}/xinetd_E.conf foo tcp |
| 48 | if [ $? -ne 0 ]; then |
| 49 | ret_val=$[$ret_val + 1] |
| 50 | fi |
| 51 | |
| 52 | ./test_probe_xinetd ${srcdir}/xinetd_F.conf foo udp |
| 53 | if [ $? -ne 0 ]; then |
| 54 | ret_val=$[$ret_val + 1] |
| 55 | fi |
| 56 | |
| 57 | ./test_probe_xinetd ${srcdir}/xinetd_F.conf foo tcp |
| 58 | if [ $? -ne 0 ]; then |
| 59 | ret_val=$[$ret_val + 1] |
| 60 | fi |
| 61 | |
| 62 | return $ret_val |
| 63 | } |
| 64 | |
| 65 | function test_probe_xinetd_regression_stringlist { |
| 66 | output=$(./test_probe_xinetd "${srcdir}/xinetd_G.conf" rsync tcp | sed -n 's|.*only_from:[[:space:]]*\(only_this_is_allowed\)[[:space:]]*$|\1|p') |
| 67 | |
| 68 | if [ "$output" = "only_this_is_allowed" ]; then |
| 69 | return 0 |
| 70 | fi |
| 71 | return 1 |
| 72 | } |
| 73 | |
| 74 | function test_probe_xinetd_duplicates { |
| 75 | output=$(./test_probe_xinetd "${srcdir}/xinetd_H.conf" telnet tcp | grep 'xiconf_service_t(telnet)' | wc -l | xargs) |
| 76 | |
| 77 | if [ "$output" = "3" ]; then |
| 78 | return 0 |
| 79 | fi |
| 80 | return 1 |
| 81 | } |
| 82 | |
| 83 | # Testing. |
| 84 | |
| 85 | test_init |
| 86 | |
| 87 | if [ -z ${CUSTOM_OSCAP+x} ] ; then |
| 88 | test_run "test_probe_xinetd_parser" test_probe_xinetd_parser |
| 89 | test_run "xinetd parser regression test: string list" test_probe_xinetd_regression_stringlist |
| 90 | test_run "test_probe_xinetd_duplicates" test_probe_xinetd_duplicates |
| 91 | fi |
| 92 | |
| 93 | test_exit |