Skip to content

Commit

Permalink
updated indimail test script
Browse files Browse the repository at this point in the history
  • Loading branch information
mbhangui committed Jun 17, 2023
1 parent 9d77d97 commit a0cb6a9
Showing 1 changed file with 159 additions and 65 deletions.
224 changes: 159 additions & 65 deletions indimail-x/tests/testindimail-virtual
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ function setup_svscan()
echo $certdir > $servicedir/smtpd/variables/CERTDIR
echo $qmaildir/inquery > $servicedir/smtpd/variables/INFIFODIR
echo $qmaildir > $servicedir/smtpd/variables/DOMAINDIR
echo 1 > $servicedir/smtpd/variables/DEBUG
echo 1 > $servicedir/smtpd/variables/DEBUG_LOGIN
printf "#!/bin/sh\nexec envdir ./variables $tcpserver -u qmaild -g qmail,indimail -HR 0 2025 $qmail_smtpd $HOSTNAME /usr/sbin/vchkpass /bin/false 2>&1\n" > $servicedir/smtpd/run
printf "#!/bin/sh\nexec $setuidgid $user $multilog t $logdir/smtpd\n" > $servicedir/smtpd/log/run
chmod +x $servicedir/smtpd/run
Expand Down Expand Up @@ -415,6 +417,7 @@ function setup_svscan()

function do_svscan_start()
{
echo
echo "Starting svscan"
(
cd $servicedir/.svscan
Expand Down Expand Up @@ -534,26 +537,7 @@ function create_domain()
fi
}

function delete_domain()
{
sudo env - \
PATH=/bin:/usr/bin \
ASSIGNDIR=$sysconfdir/users \
SYSCONFDIR=$sysconfdir \
CONTROLDIR=$cntrldir \
DOMAINDIR=$qmaildir \
SERVICEDIR=$servicedir \
vdeldomain $1 > $logdir/setup/vdeldomain.log
if [ $? -eq 0 ] ; then
tcount=$(expr $tcount + 1)
echo " testing command vdeldomain succeeded"
else
echo " testing command vdeldomain failed"
exit 1
fi
}

function create_user_plain()
function create_plain_user()
{
sudo env - \
PATH=/bin:/usr/bin \
Expand All @@ -572,7 +556,7 @@ function create_user_plain()
fi
}

function create_user_scram()
function create_scram_user()
{
sudo env - \
PATH=/bin:/usr/bin \
Expand All @@ -581,8 +565,13 @@ function create_user_scram()
CONTROLDIR=$cntrldir \
DOMAINDIR=$qmaildir \
SERVICEDIR=$servicedir \
vadduser -C -m $1 -d $2 $3 >> $logdir/setup/vadduser.log
if [ $? -eq 0 ] ; then
vadduser -C -m $1 -d -h $4 $2 $3 >> $logdir/setup/vadduser.log
status=$?

if [ $# -gt 4 ] ; then
return $status
fi
if [ $status -eq 0 ] ; then
tcount=$(expr $tcount + 1)
echo " testing command vadduser (scram) succeeded"
else
Expand Down Expand Up @@ -639,7 +628,7 @@ function delete_domain()
fi
}

function password_change()
function change_password()
{
sudo env - \
PATH=/bin:/usr/bin \
Expand Down Expand Up @@ -1179,12 +1168,13 @@ function test_imap()
echo "fi"
) > $testdir/tcpclient.imap
chmod +x $testdir/tcpclient.imap
tcpclient -vDHR 0 1430 /tmp/qmail-test/tcpclient.imap 2> $logdir/imapd/imapd.log
tcpclient -vDHR 0 1430 /tmp/qmail-test/tcpclient.imap 2>$logdir/imapd/imapd.log
if [ $? -eq 0 ] ; then
tcount=$(expr $tcount + 1)
printf " testing mail IMAP login and mail retrieval (%s) succeeded\n" "$str"
else
printf " testing mail IMAP login and mail retrieval (%s) failed\n" "$str"
less $logdir/imapd/imapd.log
exit 1
fi
check_relay > /dev/null
Expand Down Expand Up @@ -1230,6 +1220,75 @@ function test_imap()
fi
}

function test_imap_simple()
{
swaks -S --tls --to $1 --from $1 --server localhost --port 2025 -a LOGIN -au $1 -ap "$2"
(
echo "#!/bin/sh"
echo "exec 0<&6"
echo "exec 1>&7"
echo "read key"
echo "printf \"%s\n\" \"\$key\" 1>&2"
echo "printf \"a1 login $1 $2\r\n\""
echo "read key"
echo "printf \"%s\" \"\$key\" |grep \"a1 OK LOGIN Ok.\" >/dev/null"
echo "if [ \$? -ne 0 ] ; then"
echo " printf \"%s\n\" \"\$key\" 1>&2"
echo " echo \"LOGIN Failed\" 1>&2"
echo " exit 1"
echo "else"
echo " printf \"%s\n\" \"\$key\" 1>&2"
echo "fi"
echo "printf \"a1 select inbox\r\n\""
echo "while true"
echo "do"
echo " read line"
echo " t=\$(echo \"\$line\" | cut -d' ' -f1)"
echo " if [ \"\$t\" = \"*\" ] ; then"
echo " echo \"\$line\" 1>&2"
echo " continue"
echo " elif [ \"\$t\" = \"a1\" ] ; then"
echo " break"
echo " else"
echo " echo \"\$line\" 1>&2"
echo " fi"
echo "done"
echo ""
echo "printf \"a1 fetch 1 RFC822\r\n\""
echo "found=0"
echo "while true"
echo "do"
echo " read line"
echo " echo \"\$line\" | grep \"a1 OK FETCH completed.\" > /dev/null"
echo " if [ \$? -eq 0 ] ; then"
echo " break"
echo " fi"
echo " echo \"\$line\" | grep \"This is a test mailing\" > /dev/null"
echo " if [ \$? -eq 0 ] ; then"
echo " found=1"
echo " fi"
echo " echo \"\$line\" 1>&2"
echo "done"
echo "printf \"a1 logout\r\n\""
echo "read line"
echo "printf \"%s\n\" \"\$line\""
echo "if [ \$found -eq 1 ] ; then"
echo " exit 0"
echo "else"
echo " exit 1"
echo "fi"
) > $testdir/tcpclient.imap
chmod +x $testdir/tcpclient.imap
tcpclient -vDHR 0 1430 /tmp/qmail-test/tcpclient.imap 2> $logdir/imapd/imapd.log
if [ $? -eq 0 ] ; then
tcount=$(expr $tcount + 1)
printf " testing mail IMAP login and mail retrieval (%s) succeeded\n" "$str"
else
printf " testing mail IMAP login and mail retrieval (%s) failed\n" "$str"
exit 1
fi
}

function do_post_handle()
{
(
Expand Down Expand Up @@ -1494,7 +1553,7 @@ test_services
create_domain $domain1 pass
do_vdominfo
do_dbinfo
create_user_plain $testuser1 $password2
create_plain_user $testuser1 $password2
sudo svc -2 $servicedir/inlookup.infifo

do_inquerytest $testuser1
Expand All @@ -1503,65 +1562,100 @@ do_smtp_auth_login_swaks $testuser1 $password2

do_smtp_auth_qmail_remote $domain1 $testuser1 $password2

password_change $testuser1 $password1
change_password $testuser1 $password1
do_vmoduser $testuser1
do_pwdlookup $testuser1
delete_user $testuser1

create_user_scram SCRAM-SHA-1 $testuser1 $password1
create_user_scram SCRAM-SHA-256 $testuser2 $password2
sudo svc -h $servicedir/inlookup.infifo
sleep $sleep_int

for j in 1 2
for hash in DES MD5 SHA-256 SHA-512
do
case $j in
1)
str="inlookup cache=0"
> $servicedir/smtpd/variables/PASSWD_CACHE
> $servicedir/smtpd/variables/QUERY_CACHE
for i in imap pop3
do
for k in d d-ssl
echo
echo "Starting SMTP AUTH, IMAP/POP3 login tests for hash $hash"
t1="$password1""$hash"
t2="$password2""$hash"
create_scram_user SCRAM-SHA-1 $testuser1 $t1 $hash
create_scram_user SCRAM-SHA-256 $testuser2 $t2 $hash
sudo svc -h $servicedir/inlookup.infifo
sleep $sleep_int
if [ "$hash" = "DES" ] ; then
echo "DES_HASH" > $servicedir/smtpd/variables/PASSWORD_HASH
else
/bin/rm -f $servicedir/smtpd/variables/PASSWORD_HASH
fi

for j in 1 2
do
case $j in
1)
str="inlookup cache=0"
> $servicedir/smtpd/variables/PASSWD_CACHE
> $servicedir/smtpd/variables/QUERY_CACHE
for i in imap pop3
do
> $servicedir/"$i"$k/variables/PASSWD_CACHE
> $servicedir/"$i"$k/variables/QUERY_CACHE
for k in d d-ssl
do
> $servicedir/"$i"$k/variables/PASSWD_CACHE
> $servicedir/"$i"$k/variables/QUERY_CACHE
done
done
done
;;
2)
str="inlookup cache=1"
echo 1 > $servicedir/smtpd/variables/PASSWD_CACHE
echo 1 > $servicedir/smtpd/variables/QUERY_CACHE
;;
2)
str="inlookup cache=1"
echo 1 > $servicedir/smtpd/variables/PASSWD_CACHE
echo 1 > $servicedir/smtpd/variables/QUERY_CACHE
for i in imap pop3
do
for k in d d-ssl
do
echo 1 > $servicedir/"$i"$k/variables/PASSWD_CACHE
echo 1 > $servicedir/"$i"$k/variables/QUERY_CACHE
done
done
;;
esac
sudo svc -r $servicedir/smtpd
for i in imap pop3
do
for k in d d-ssl
do
echo 1 > $servicedir/"$i"$k/variables/PASSWD_CACHE
echo 1 > $servicedir/"$i"$k/variables/QUERY_CACHE
if [ "$hash" = "DES" ] ; then
echo "DES_HASH" > $servicedir/"$i"$k/variables/PASSWORD_HASH
else
/bin/rm -f $servicedir/"$i"$k/variables/PASSWORD_HASH
fi
sudo svc -r $servicedir/"$i"$k
done
done
;;
esac
sudo svc -r $servicedir/smtpd
sleep $sleep_int
test_imap $testuser1 $password1
test_pop3 $testuser1 $password1
do_gsasl_test "SCRAM-SHA-1" $testuser1 $password1
do_gsasl_test "SCRAM-SHA-1-PLUS" $testuser1 $password1
do_gsasl_test "SCRAM-SHA-256" $testuser2 $password2
do_gsasl_test "SCRAM-SHA-256-PLUS" $testuser2 $password2
do_smtp_auth_qmail_remote_scram "SCRAM-SHA-1" $domain1 $testuser1 $password1
do_smtp_auth_qmail_remote_scram "SCRAM-SHA-1-PLUS" $domain1 $testuser1 $password1
do_smtp_auth_qmail_remote_scram "SCRAM-SHA-256" $domain1 $testuser2 $password2
do_smtp_auth_qmail_remote_scram "SCRAM-SHA-256-PLUS" $domain1 $testuser2 $password2
sleep $sleep_int
test_imap $testuser1 $t1
test_pop3 $testuser1 $t1
do_gsasl_test "SCRAM-SHA-1" $testuser1 $t1
do_gsasl_test "SCRAM-SHA-1-PLUS" $testuser1 $t1
do_gsasl_test "SCRAM-SHA-256" $testuser2 $t2
do_gsasl_test "SCRAM-SHA-256-PLUS" $testuser2 $t2
do_smtp_auth_qmail_remote_scram "SCRAM-SHA-1" $domain1 $testuser1 $t1
do_smtp_auth_qmail_remote_scram "SCRAM-SHA-1-PLUS" $domain1 $testuser1 $t1
do_smtp_auth_qmail_remote_scram "SCRAM-SHA-256" $domain1 $testuser2 $t2
do_smtp_auth_qmail_remote_scram "SCRAM-SHA-256-PLUS" $domain1 $testuser2 $t2
done
echo " testing SMTP AUTH, IMAP/POP3 login tests for hash $hash succeeded"
tcount=$(expr $tcount + 1)
delete_user $testuser1
delete_user $testuser2
done
tcount=$(expr $tcount + 3)
printf " testing command tcpserver non-encrypted succeeded\n"
printf " testing command tcpclient non-encrypted succeeded\n"
printf " testing command tcpclient encrypted succeeded\n"
create_scram_user SCRAM-SHA-1 $testuser1 $password1 MD5 1
create_scram_user SCRAM-SHA-256 $testuser2 $password2 MD5 1
echo
do_valias $testuser1 $testuser2
echo
echo "Testing domain deletion"
delete_domain $domain1
echo
echo "Starting POST Handle tests"
do_post_handle $domain1 pass $domain2 $testuser3 $testuser4 $domain3

do_svscan_stop $svpid
Expand Down

0 comments on commit a0cb6a9

Please sign in to comment.