Ignore:
Timestamp:
Feb 12, 2006, 10:49:56 PM (19 years ago)
Author:
rainer
Message:

Rewrite of test suite, checksum for growing logs, fix for minor bug with dead client detection.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/testrun_2b.sh

    r1 r19  
    11#! /bin/sh
    22
     3LOGFILE="$PW_DIR/.samhain_log"; export LOGFILE
     4RCFILE="$PW_DIR/testrc_2";  export RCFILE
     5RCFILE_C="$PW_DIR/testrc_1.dyn";  export RCFILE_C
    36
    4 # The following two are the ANSI sequences for start and end embolden
    5 case $TERM in
    6 vt*|ansi*|con*|xterm*|linux*|screen*)
    7   S=[1m
    8   E=[m
    9   ;;
    10 *)
    11   S=
    12   E=
    13   ;;
    14 esac
     7SERVER_BUILDOPTS="--quiet  $TRUST  --enable-network=server --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=REQ_FROM_SERVER$PW_DIR/testrc_2 --with-data-file=REQ_FROM_SERVER$PW_DIR/.samhain_file --with-logserver=${SH_LOCALHOST}  --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock"; export SERVER_BUILDOPTS
    158
    16 PW_DIR=`pwd`
     9CLIENT_BUILDOPTS="--quiet  $TRUST --enable-micro-stealth=137 --enable-debug --enable-network=client --enable-srp --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=REQ_FROM_SERVER${RCFILE_C} --with-data-file=REQ_FROM_SERVER$PW_DIR/.samhain_file --with-logserver=localhost  --with-log-file=$LOGFILE --with-pid-file=$PW_DIR/.samhain_lock"; export CLIENT_BUILDOPTS
    1710
    18 if test x$UID != x; then
    19   TRUST="--with-trusted=0,2,$UID"
    20 else
    21   TRUST="--with-trusted=0,2"
    22 fi
     11testrun2b_internal ()
     12{
     13    GPG="$1"
    2314
    24 TEST_MYSQL=
    25 # TEST_MYSQL=" --with-database=mysql --with-libs=-L/usr/local/mysql/lib "
    26 export TEST_MYSQL
     15    [ -z "$verbose" ] || {
     16        echo;
     17        echo Working directory: $PW_DIR; echo MAKE is $MAKE; echo GPG is $GPG;
     18        echo;
     19    }
    2720
    28 echo; echo "${S}__ STARTING TEST RUN CLIENT/SERVER W/GPG __${E}"; echo;
    29 echo Working directory: $PW_DIR
     21    [ -z "$verbose" ] || { echo; echo "${S}Building client and server${E}"; echo; }
    3022
    31 MAKE=`which gmake`
    32 if test "x$?" = x1 ; then
    33     MAKE="make -s"
    34 else
    35     MAKE=`which gmake | sed -e "s%\([a-z:]\) .*%\1%g"`
    36     if test "x$MAKE" = x; then
    37         MAKE="make -s"
    38     elif test "x$MAKE" = xno; then
    39         MAKE="make -s"
     23    if test -r "Makefile"; then
     24        $MAKE distclean
     25    fi
     26
     27    ${TOP_SRCDIR}/configure --with-gpg=${GPG} --with-checksum=no ${CLIENT_BUILDOPTS} >/dev/null 2>&1
     28
     29    if test x$? = x0; then
     30        [ -z "$verbose" ] ||     log_msg_ok "configure...";
     31        $MAKE  > /dev/null 2>>test_log
     32        if test x$? = x0; then
     33            [ -z "$verbose" ] || log_msg_ok "make...";
     34        else
     35            [ -z "$quiet" ] &&   log_msg_fail "make...";
     36            return 1
     37        fi
    4038    else
    41         if test "x$MAKE" = "xwhich:"; then
    42                 MAKE="make -s"
     39        [ -z "$quiet" ] &&       log_msg_fail "configure...";
     40        return 1
     41    fi
     42   
     43    SKIP=`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' ${SCRIPTDIR}/test.sh`
     44   
     45    tail -n "+$SKIP" ${SCRIPTDIR}/test.sh >/dev/null 2>&1
     46    if [ $? -eq 0 ]; then
     47        tail -n "+$SKIP" ${SCRIPTDIR}/test.sh | gunzip -c - | tar xf - &&  \
     48            mv "./testrc.gpg.asc" "${RCFILE_C}"
     49    else
     50        tail "+$SKIP" ${SCRIPTDIR}/test.sh | gunzip -c - | tar xf - &&  \
     51            mv "./testrc.gpg.asc" "${RCFILE_C}"
     52    fi
     53    if test x$? = x0; then
     54        [ -z "$verbose" ] || log_msg_ok    "extract gpg signed files...";
     55    else
     56        [ -z "$quiet" ]   && log_msg_fail  "extract gpg signed files...";
     57        return 1
     58    fi
     59
     60    # save binary and build server
     61
     62    cp samhain samhain.build || return 1
     63    make clean >/dev/null || return 1
     64   
     65    ${TOP_SRCDIR}/configure ${SERVER_BUILDOPTS}
     66
     67    if test x$? = x0; then
     68        [ -z "$verbose" ] ||     log_msg_ok "configure...";
     69        $MAKE  > /dev/null 2>>test_log
     70        if test x$? = x0; then
     71            [ -z "$verbose" ] || log_msg_ok "make...";
    4372        else
    44                 MAKE="gmake -s"
    45                 gmake -v >/dev/null 2>&1 || MAKE="make -s"
     73            [ -z "$quiet" ] &&   log_msg_fail "make...";
     74            return 1
    4675        fi
     76       
     77    else
     78        [ -z "$quiet" ] &&       log_msg_fail "configure...";
     79        return 1
    4780    fi
    48 fi
     81   
     82   
     83    #####################################################################
     84    #
     85    #
     86    rm -f ./.samhain_file
     87    rm -f ./.samhain_log
     88    rm -f ./.samhain_lock
     89    rm -f ./rc.${SH_LOCALHOST}
     90    rm -f ./file.${SH_LOCALHOST}
     91   
     92    cp ${SCRIPTDIR}/testrc_2.in testrc_2
     93   
     94    ./samhain.build -t init -p none
     95   
     96    if test x$? = x0; then
     97        [ -z "$verbose" ] || log_msg_ok    "init...";
     98    else
     99        [ -z "$quiet" ]   && log_msg_fail  "init...";
     100        return 1
     101    fi
     102   
     103    # Create a password
    49104
    50 echo MAKE is $MAKE
    51 echo
     105    SHPW=`./yule -G`
     106    if test x"$SHPW" = x; then
     107        [ -z "$quiet" ]   && log_msg_fail  "password not generated -- aborting"
     108        return 1
     109    fi
     110   
     111    # Set in client
     112   
     113    ./samhain_setpwd samhain.build new $SHPW >/dev/null
     114   
     115    if test x$? = x0; then
     116        [ -z "$verbose" ] || log_msg_ok    "./samhain_setpwd samhain.build new $SHPW";
     117    else
     118        [ -z "$quiet" ]   && log_msg_fail  "./samhain_setpwd samhain.build new $SHPW";
     119        return 1
     120    fi
     121   
     122    mv samhain.build.new  samhain.new || return 1
     123   
     124    rm -f ./.samhain_log*
     125    rm -f ./.samhain_lock
     126   
     127    SHCLT=`./yule -P $SHPW | sed s%HOSTNAME%${SH_LOCALHOST}%`
     128   
     129    if test x$? = x0; then
     130        [ -z "$verbose" ] || log_msg_ok    "yule -P $SHPW";
     131    else
     132        [ -z "$quiet" ]   && log_msg_fail  "yule -P $SHPW";
     133        return 1
     134    fi
     135   
     136    echo $SHCLT >> testrc_2
     137   
     138    cp    "${RCFILE_C}"              ./rc.${SH_LOCALHOST}
     139    mv    $PW_DIR/.samhain_file.asc  ./file.${SH_LOCALHOST}
    52140
    53 # $GPG_PATH _must_ be an absolute path
    54 #
    55 if test x${GPG_PATH} = x; then
    56     GPG_PATH=`which gpg | sed -e "s%\([a-z:]\) .*%\1%g"`
    57 fi
     141    ALTHOST=`find_hostname`
     142    cp    ./testrc_2       "./rc.${ALTHOST}"
     143    cp    ./file.${SH_LOCALHOST} "./file.${ALTHOST}" 2>/dev/null
     144}
    58145
    59 if test x${GPG_PATH} = x; then
    60     echo "ERROR: gpg (GnuPG) not found"
    61     exit
    62 else
    63     GPG_OK=`echo ${GPG_PATH} | sed -e "s%\(/.*\)%OK%g"`
    64     if test x${GPG_OK} = xOK; then
    65         echo "GPG_PATH is ${GPG_PATH}"
    66     else
    67         echo "ERROR: GPG_PATH (${GPG_PATH}) is _not_ an absolute path."
    68         echo
    69         echo "  Apparently the command 'which gpg' did not yield an absolute path."
    70         echo "  You can fix the problem by setting the environment variable GPG_PATH"
    71         echo "  to the absolute path to gpg (GnuPG) and start the test again."
    72         exit
    73     fi
    74 fi
    75 
    76 echo
     146MAXTEST=1; export MAXTEST
    77147
    78148testrun2b ()
    79149{
    80         #
    81         # test standalone compilation
    82         #
    83         echo "${S}Building client and server${E}"; echo;
    84         #
    85         if test -r "Makefile"; then
    86                 $MAKE distclean
     150    log_start "RUN FULL CLIENT/SERVER W/GPG";
     151    #
     152    if [ x"$1" = x ]; then
     153        [ -z "$quiet" ] && log_msg_fail "Missing hostname"
     154    fi
     155    #
     156    GPG=`find_path gpg`
     157    if [ -z "$GPG" ]; then
     158        log_skip 1 $MAXTEST 'gpg not found in $PATH'
     159    else
     160        eval "$GPG" --list-keys 0F571F6C >/dev/null 2>/dev/null
     161        if [ $? -ne 0 ]; then
     162            log_skip 1 $MAXTEST 'public PGP key 0x0F571F6C not present'
     163        else
     164           
     165            SH_LOCALHOST=$1; export SH_LOCALHOST
     166   
     167            testrun2b_internal "$GPG"
     168   
     169            do_test_1_a
     170            if [ $? -eq 0 ]; then
     171                [ -z "$quiet" ] && log_ok   1 ${MAXTEST} "Client download+logging w/gpg";
     172            else
     173                [ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Client download+logging w/gpg";
     174            fi
     175   
     176            if [ -n "$cleanup" ]; then
     177                rm -f ./rc.${SH_LOCALHOST}
     178                rm -f ./file.${SH_LOCALHOST}
     179                ALTHOST=`find_hostname`
     180                rm -f "./file.${ALTHOST}"
     181                rm -f "./rc.${ALTHOST}"
     182            fi
    87183        fi
    88         #
    89         GPG_HASH=`${GPG_PATH} --load-extension tiger --print-md TIGER192 ${GPG_PATH}`
    90         #
    91         echo GPG_HASH is ${GPG_HASH}
    92         #
    93         ${TOP_SRCDIR}/configure --quiet  $TRUST --with-gpg=${GPG_PATH} --enable-xml-log --enable-network=client --enable-srp --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=REQ_FROM_SERVER$PW_DIR/testrc_2.signed --with-data-file=REQ_FROM_SERVER$PW_DIR/.samhain_file --with-logserver=localhost  --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock
    94         #
    95         if test x$? = x0; then
    96                 echo "configure completed, exit status 0"; echo;
    97                 $MAKE  > /dev/null
    98                 if test x$? = x0; then
    99                     echo "$MAKE completed, exit status $?"; echo;
    100                 else
    101                     echo "${S}ERROR:${E} make failed, exit status $?"; echo;
    102                     exit
    103                 fi
    104 
    105         else
    106                 echo "${S}ERROR:${E} configure failed, exit status $?"; echo;
    107                 exit
    108         fi
    109 
    110         # save binary and build server
    111         #
    112         cp samhain samhain.build
    113         make clean
    114 
    115         #
    116         ${TOP_SRCDIR}/configure --quiet  $TRUST --with-gpg=${GPG_PATH} --enable-xml-log ${TEST_MYSQL} --enable-debug --enable-network=server --enable-srp --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=REQ_FROM_SERVER$PW_DIR/testrc_2.signed --with-data-file=REQ_FROM_SERVER$PW_DIR/.samhain_file --with-logserver=${SH_LOCALHOST}  --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --enable-identity=rainer
    117         #
    118         if test x$? = x0; then
    119                 echo "configure completed, exit status 0"; echo;
    120                 $MAKE  > /dev/null
    121                 if test x$? = x0; then
    122                     echo "$MAKE completed, exit status $?"; echo;
    123                 else
    124                     echo "${S}ERROR:${E} make failed, exit status $?"; echo;
    125                     exit
    126                 fi
    127 
    128         else
    129                 echo "${S}ERROR:${E} configure failed, exit status $?"; echo;
    130                 exit
    131         fi
    132         echo "${S}Initialize database${E}"; echo;
    133 
    134         rm -f ./.samhain_file
    135         rm -f ./.samhain_log
    136         rm -f ./.samhain_lock
    137         rm -f ./rc.${SH_LOCALHOST}
    138         rm -f ./file.${SH_LOCALHOST}
    139 
    140         cp ${SCRIPTDIR}/testrc_2.in testrc_2.signed
    141 
    142         # Create a password
    143         SHPW=`./yule -G`
    144         if test x"$SHPW" = x; then
    145             echo "password not generated -- aborting"
    146             exit 1
    147         fi
    148 
    149         # Set in client
    150         echo "./samhain_setpwd samhain.build new $SHPW"
    151         ./samhain_setpwd samhain.build new $SHPW
    152         mv samhain.build.new samhain.new
    153         SHCLT=`./yule -P $SHPW | sed s%HOSTNAME%${SH_LOCALHOST}%`
    154         echo $SHCLT >> testrc_2.signed
    155 
    156         echo "--- You need to sign the config file testrc_2.signed now ---"
    157         echo
    158         ${GPG_PATH} -a --clearsign --not-dash-escaped $PW_DIR/testrc_2.signed
    159         mv $PW_DIR/testrc_2.signed.asc $PW_DIR/testrc_2.signed
    160 
    161         echo "./samhain.new -t init"
    162         ./samhain.new -t init
    163 
    164         SHINI=$?
    165 
    166         rm -f ./.samhain_log
    167         rm -f ./.samhain_lock
    168 
    169         cp    ./testrc_2.signed       ./rc.${SH_LOCALHOST}
    170         mv    ./.samhain_file         ./file.${SH_LOCALHOST}
    171 
    172         if test x$SHINI = x0; then
    173                 echo
    174                 echo "--- You need to sign the database file.${SH_LOCALHOST} now ---"
    175                 echo
    176                 ${GPG_PATH} -a --clearsign --not-dash-escaped $PW_DIR/file.${SH_LOCALHOST}
    177                 mv $PW_DIR/file.${SH_LOCALHOST}.asc $PW_DIR/file.${SH_LOCALHOST}
    178 
    179                 echo; echo "${S}Start Server${E}: ./yule  &"; echo;
    180                 ./yule &
    181                 PROC_Y=$!
    182                 sleep 5
    183 
    184                 echo; echo "${S}Start Client${E}: ./samhain.new -l none -p none -e info -t check";
    185 
    186                 ./samhain.new -t check -p none -l none -e info
    187                 if test x$? = x0; then
    188                     echo "${S}check completed${E}"
    189                 else
    190                     echo "${S}ERROR:${E} -- check -- failed, exit status $?"
    191                     echo
    192                     kill $PROC_Y
    193                     exit
    194                 fi
    195 
    196                 kill $PROC_Y
    197                 sleep 5
    198         else
    199                 echo "${S}ERROR:${E} -- init -- failed, exit status $SHINI";
    200                 echo;
    201                 exit
    202         fi
    203            
     184    fi
     185    log_end "RUN FULL CLIENT/SERVER W/GPG"
    204186}
    205187
    206     if test x$1 = x; then
    207         echo
    208         echo "Please provide the local hostname as argument."
    209         echo
    210         exit 8
    211     fi
    212 
    213     SH_LOCALHOST=$1; export SH_LOCALHOST
    214 
    215     testrun2b
    216 
    217 
    218 echo; echo "${S}__ END TEST RUN CLIENT/SERVER W/GPG __${E}"; echo;
    219 
    220 exit
    221 
Note: See TracChangeset for help on using the changeset viewer.