From 9f52b42faa1afe682f0adeec0bc828b252ab739a Mon Sep 17 00:00:00 2001 From: Manvendra Bhangui Date: Fri, 24 May 2024 14:53:36 +0530 Subject: [PATCH] added -H option --- indimail-x/tests/testindimail-virtual | 285 ++++++++++++++++++-------- 1 file changed, 205 insertions(+), 80 deletions(-) diff --git a/indimail-x/tests/testindimail-virtual b/indimail-x/tests/testindimail-virtual index 999c056fb..a2edda12f 100755 --- a/indimail-x/tests/testindimail-virtual +++ b/indimail-x/tests/testindimail-virtual @@ -1,11 +1,9 @@ #!/bin/sh # -# $Id: testindimail-virtual,v 1.25 2024-05-23 01:51:33+05:30 Cprogrammer Exp mbhangui $ +# $Id: testindimail-virtual,v 1.27 2024-05-24 14:53:22+05:30 Cprogrammer Exp mbhangui $ # start=$(date +'%s') user=$(whoami) -failed="" -hash_supported="DES MD5 SHA-256 SHA-512" domain1=example.com # virtual domain domain2=newexample.com # alias domain domain3=example2.com # remote domain @@ -68,7 +66,8 @@ INUID=$(id -u indimail) INGID=$(id -g indimail) sleep_int=0.5 -trap do_cleanup_failed 2 EXIT +#trap do_cleanup_failed 2 EXIT +trap do_cleanup_failed EXIT setup_maildir() { @@ -689,6 +688,11 @@ do_svscan_stop() do_setup() { + if [ -x /usr/bin/mariadb ] ; then + mysql=/usr/bin/mariadb + else + mysql=/usr/bin/mysql + fi # basic setup for maildir, assign config and queue $sudo /bin/rm -rf $logdir mkdir -p $logdir/setup @@ -2543,7 +2547,16 @@ run_vcfilter() do_plain_cram_user_tests() { - for hash in "default" $hash_supported + if [ -n "$thash_supported" ] ; then + hash_supported=$thash_supported + else + hash_supported="default DES MD5 SHA-256 SHA-512" + sudo grep '\$y\$' /etc/shadow > /dev/null 2>&1 && shadow_pass=1 || shadow_pass=0 + if [ $shadow_pass -eq 1 ] ; then + hash_supported="$hash_supported YESCRYPT" + fi + fi + for hash in $hash_supported do printf "\r%126s\n" " " echo "Starting SMTP AUTH, qmail-remote, IMAP/POP3 login tests for hash $hash plain/cram users" @@ -2648,6 +2661,15 @@ do_plain_cram_user_tests() do_scram_user_tests() { echo 1 > $servicedir/smtpd/variables/ENABLE_CRAM + if [ -n "$thash_supported" ] ; then + hash_supported=$thash_supported + else + hash_supported="DES MD5 SHA-256 SHA-512" + sudo grep '\$y\$' /etc/shadow > /dev/null 2>&1 && shadow_pass=1 || shadow_pass=0 + if [ $shadow_pass -eq 1 ] ; then + hash_supported="$hash_supported YESCRYPT" + fi + fi for hash in $hash_supported do printf "\r%126s\n" " " @@ -3241,37 +3263,133 @@ do_admin_server_tests() [ -z "$failed" ] && failed="test vpriv" || failed="$failed, test vpriv" [ $continue_on_err -eq 0 ] && exit 1 || return 0 fi + tm1=$(date +"%s.%4N") + $sudo env - \ + PATH=/usr/bin:/usr/sbin \ + SYSCONFDIR=$sysconfdir \ + CONTROLDIR=$cntrldir \ + mgmtpass -u admin -p $adminpass + if [ $? -eq 0 ] ; then + tm2=$(date +"%s.%4N") + secs=$(echo $tm1 $tm2 | awk '{printf("%0.4f\n", $2-$1)}') + tcount=$(expr $tcount + 1) + printf "\r testing mgmtpass command %-17s succeeded %55s [%.4f sec]\n" " " " " "$secs" + print_pct + else + tm2=$(date +"%s.%4N") + secs=$(echo $tm1 $tm2 | awk '{printf("%0.4f\n", $2-$1)}') + fcount=$(expr $fcount + 1) + echo " testing mgmtpass command failed [%.4f sec]\n" "$secs" + [ -z "$failed" ] && failed="test vpriv" || failed="$failed, test vpriv" + [ $continue_on_err -eq 0 ] && exit 1 || return 0 + fi + $sudo env - \ PATH=/usr/bin:/usr/sbin \ SYSCONFDIR=$sysconfdir \ CONTROLDIR=$cntrldir \ vpriv -d /usr/bin/vuserinfo admin + tm1=$(date +"%s.%4N") + $sudo $setuidgid -g indimail,qcerts indimail env - \ + PATH=/usr/bin:/usr/sbin \ + SYSCONFDIR=$sysconfdir \ + CONTROLDIR=$cntrldir \ + adminclient -n $certdir/servercert.pem -h $adminhost -p $adminport \ + -u $adminuser -P $adminpass -c "vuserinfo $testuser1" > $logdir/setup/adminclient-"vuserinfo".log 2>&1 + if [ $? -ne 0 ] ; then + tm2=$(date +"%s.%4N") + secs=$(echo $tm1 $tm2 | awk '{printf("%0.4f\n", $2-$1)}') + tcount=$(expr $tcount + 1) + printf "\r testing adminclient command denial succeeded %55s [%.4f sec]\n" " " "$secs" + print_pct + else + tm2=$(date +"%s.%4N") + secs=$(echo $tm1 $tm2 | awk '{printf("%0.4f\n", $2-$1)}') + fcount=$(expr $fcount + 1) + echo " testing adminclient command denial failed [%.4f sec]\n" "$secs" + [ -z "$failed" ] && failed="test vpriv" || failed="$failed, test vpriv" + [ $continue_on_err -eq 0 ] && exit 1 || return 0 + fi + + ############################################################### $sudo env - \ PATH=/usr/bin:/usr/sbin \ SYSCONFDIR=$sysconfdir \ CONTROLDIR=$cntrldir \ - mgmtpass -u admin -p $adminpass - if [ $? -eq 0 ] ; then + vpriv -i /usr/bin/vuserinfo admin '*' + + # this should succeed + $sudo $setuidgid -g indimail,qcerts indimail env - \ + PATH=/usr/bin:/usr/sbin \ + SYSCONFDIR=$sysconfdir \ + CONTROLDIR=$cntrldir \ + adminclient -n $certdir/servercert.pem -h $adminhost -p $adminport \ + -u $adminuser -P $adminpass -c "vuserinfo $testuser1" > $logdir/setup/adminclient-"vuserinfo".log 2>&1 + ret1=$? + for i in 1 2 3 4 5 6 7 + do + adminclient -n $certdir/servercert.pem -h $adminhost -p $adminport \ + -u $adminuser -P "abcdefg" -c "vuserinfo $testuser1" > $logdir/setup/adminclient-"vuserinfo".log 2>&1 + done + + tm1=$(date +"%s.%4N") + # this should fail + adminclient -n $certdir/servercert.pem -h $adminhost -p $adminport \ + -u $adminuser -P "$adminpass" -c "vuserinfo $testuser1" > $logdir/setup/adminclient-"vuserinfo".log 2>&1 + ret2=$? + if [ $ret1 -eq 0 -a $ret2 -ne 0 ] ; then tm2=$(date +"%s.%4N") secs=$(echo $tm1 $tm2 | awk '{printf("%0.4f\n", $2-$1)}') tcount=$(expr $tcount + 1) - printf "\r testing mgmtpass command %-17s succeeded %55s [%.4f sec]\n" " " " " "$secs" + printf "\r testing adminclient command disablement succeeded %55s [%.4f sec]\n" " " "$secs" print_pct else tm2=$(date +"%s.%4N") secs=$(echo $tm1 $tm2 | awk '{printf("%0.4f\n", $2-$1)}') fcount=$(expr $fcount + 1) - echo " testing mgmtpass command succeeded failed [%.4f sec]\n" "$secs" + echo " testing adminclient command disablement failed [%.4f sec]\n" "$secs" [ -z "$failed" ] && failed="test vpriv" || failed="$failed, test vpriv" [ $continue_on_err -eq 0 ] && exit 1 || return 0 fi + tm1=$(date +"%s.%4N") + # this should succeed + $sudo env - \ + PATH=/usr/bin:/usr/sbin \ + SYSCONFDIR=$sysconfdir \ + CONTROLDIR=$cntrldir \ + mgmtpass -u admin -p $adminpass + ret3=$? + tm2=$(date +"%s.%4N") + + # this should succeed + adminclient -n $certdir/servercert.pem -h $adminhost -p $adminport \ + -u $adminuser -P "$adminpass" -c "vuserinfo $testuser1" > $logdir/setup/adminclient-"vuserinfo".log 2>&1 + ret4=$? + if [ $ret3 -eq 0 -a $ret4 -eq 0 ] ; then + secs=$(echo $tm1 $tm2 | awk '{printf("%0.4f\n", $2-$1)}') + tcount=$(expr $tcount + 1) + printf "\r testing adminclient command enablement succeeded %55s [%.4f sec]\n" " " "$secs" + print_pct + else + echo "ret3=$ret3, ret4=$ret4" + secs=$(echo $tm1 $tm2 | awk '{printf("%0.4f\n", $2-$1)}') + fcount=$(expr $fcount + 1) + echo " testing adminclient command enablement failed [%.4f sec]\n" "$secs" + [ -z "$failed" ] && failed="test vpriv" || failed="$failed, test vpriv" + [ $continue_on_err -eq 0 ] && exit 1 || return 0 + fi + $sudo env - \ + PATH=/usr/bin:/usr/sbin \ + SYSCONFDIR=$sysconfdir \ + CONTROLDIR=$cntrldir \ + vpriv -d /usr/bin/vuserinfo admin + ############################################################### + tm1=$(date +"%s.%4N") for cmd in /usr/bin/vuserinfo /usr/bin/vsetuserquota \ - /usr/bin/vipmap /usr/bin/crc /usr/bin/printdir \ - /usr/bin/vlimit /usr/sbin/resetquota /usr/sbin/ipchange \ - /usr/sbin/vfstab /usr/libexec/indimail/updatefile + /usr/bin/vipmap /usr/bin/crc /usr/bin/printdir do d=$(dirname $cmd) prog=$(basename $cmd) @@ -3282,8 +3400,6 @@ do_admin_server_tests() vpriv -i $d/$prog admin '*' case $prog in vuserinfo) - #set -- -q $testuser1 - # head -1 |cut -d: -f2|awk '{print $1}' set "$testuser1" ;; vsetuserquota) @@ -3299,14 +3415,6 @@ do_admin_server_tests() printdir) set $domain1 ;; - kvlimit) - ;; - kresetquota) - ;; - kvfstab) - ;; - kupdatefile) - ;; *) set "notset" ;; @@ -3320,8 +3428,9 @@ do_admin_server_tests() SYSCONFDIR=$sysconfdir \ CONTROLDIR=$cntrldir \ adminclient -n $certdir/servercert.pem -h $adminhost -p $adminport \ - -u $adminuser -P $adminpass -c "$prog $*" > $logdir/setup/adminclient"$prog".log 2>&1 - if [ $? -eq 0 ] ; then + -u $adminuser -P $adminpass -c "$prog $*" > $logdir/setup/adminclient-"$prog".log 2>&1 + ret=$? + if [ $ret -eq 0 ] ; then tm2=$(date +"%s.%4N") secs=$(echo $tm1 $tm2 | awk '{printf("%0.4f\n", $2-$1)}') if [ "$prog" = "vsetuserquota" ] ; then @@ -3340,7 +3449,12 @@ do_admin_server_tests() printf "\r testing adminclient command %-17s failed %55s [%.4f sec]\n" "$prog" " " "$secs" print_pct if [ $prompt -eq 1 ] ; then - less $logdir/setup/adminclient"$prog".log + ( + if [ "$prog" = "vsetuserquota" ] ; then + echo quota=$quota + fi + cat $logdir/setup/adminclient-"$prog".log + ) | less fi [ -z "$failed" ] && failed="adminclient $prog failed" || failed="$failed, adminclient $prog failed" fi @@ -3356,7 +3470,13 @@ do_admin_server_tests() printf "\r testing adminclient command %-17s failed %55s [%.4f sec]\n" "$prog" " " "$secs" print_pct if [ $prompt -eq 1 ] ; then - less $logdir/setup/adminclient"$prog".log + ( + echo "Return status = $ret" + if [ "$prog" = "vsetuserquota" ] ; then + echo quota=$quota + fi + cat $logdir/setup/adminclient-"$prog".log + ) | less fi [ -z "$failed" ] && failed="adminclient $prog failed" || failed="$failed, adminclient $prog failed" fi @@ -3364,7 +3484,6 @@ do_admin_server_tests() /bin/rm -f $cntrldir/host.master $cntrldir/host.cntrl } -## begin getopt usage() { echo "testindimail [-y|--nprompt]" 1>&2 @@ -3406,52 +3525,6 @@ display_tests() echo "Test execution of post handle scripts" } -prompt=1 -continue_on_err=0 -sudo grep '\$y\$' /etc/shadow > /dev/null 2>&1 -if [ $? -eq 0 ] ; then - if [ -n "$hash_supported" ] ; then - hash_supported="$hash_supported YESCRYPT" - else - hash_supported="YESCRYPT" - fi -fi -options=$(getopt -a -n testindimail-virtual -o "hyc" -l help,noprompt,continue -- "$@") -if [ $? != 0 ]; then - usage - exit 1 -fi -eval set -- "$options" -while : -do - case "$1" in - -y | --noprompt) - prompt=0 - export LESS="-E" - shift - ;; - -c | --continue) - continue_on_err=1 - shift - ;; - -h | --help) - usage - display_tests - exit 1 - ;; - --) # end of options - shift - break - ;; - *) - echo "Unexpected option: $1 - this should'nt happen." 1>&2 - usage - exit 1 - ;; - esac -done -## end getopt - print_pct() { pct=$(echo $tcount $total_tests | awk '{printf("%0.2f\n", ($1 * 100)/$2)}') @@ -3653,17 +3726,56 @@ export SERVICEDIR=/service tcount=0 fcount=0 current_dir=$(pwd) +thash_supported="" +failed="" if [ -f $testdir/itotal.count ] ; then total_tests=$(cat $testdir/itotal.count) else - total_tests=1312 + total_tests=1315 fi -if [ -x /usr/bin/mariadb ] ; then - mysql=/usr/bin/mariadb -else - mysql=/usr/bin/mysql +prompt=1 +continue_on_err=0 +## begin getopt +options=$(getopt -a -n testindimail-virtual -o "hycH:" -l help,noprompt,continue,hash -- "$@") +if [ $? != 0 ]; then + usage + exit 1 fi -t=$(dirname $0) +eval set -- "$options" +while : +do + case "$1" in + -y | --noprompt) + prompt=0 + export LESS="-E" + shift + ;; + -c | --continue) + continue_on_err=1 + shift + ;; + -H | --hash) + thash_supported=$2 + shift 2 + ;; + -h | --help) + usage + display_tests + exit 1 + ;; + --) # end of options + shift + break + ;; + *) + echo "Unexpected option: $1 - this should'nt happen." 1>&2 + usage + exit 1 + ;; + esac +done +## end getopt + do_setup do_svscan_start svpid=$(sed -n '$p' $servicedir/.svscan.pid) @@ -3751,11 +3863,24 @@ secs=$(($end-$start)) printf '%d days, %d hours, %d minutes, %d seconds\n' $((secs/86400)) $((secs%86400/3600)) $((secs%3600/60)) \ $((secs%60)) t=$(expr $tcount + $fcount) -echo $t > $testdir/itotal.count +if [ -f $testdir/itotal.count ] ; then + c=$(cat $testdir/itotal.count) +else + c=0 +fi +if [ $t -gt $c ] ; then + echo $t > $testdir/itotal.count +fi exit 0 # # $Log: testindimail-virtual,v $ +# Revision 1.27 2024-05-24 14:53:22+05:30 Cprogrammer +# updated test script +# +# Revision 1.26 2024-05-24 08:49:45+05:30 Cprogrammer +# added tests for enabling, disabling adminclient passwords +# # Revision 1.25 2024-05-23 01:51:33+05:30 Cprogrammer # added test for adminclient/indisrvr #