diff options
Diffstat (limited to 'test/tests/send')
-rw-r--r-- | test/tests/send | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/test/tests/send b/test/tests/send new file mode 100644 index 0000000..5444410 --- /dev/null +++ b/test/tests/send @@ -0,0 +1,83 @@ +. functions + +cat <<EOF >$tmpdir/protocols/dummy +#!/bin/sh +set -e +read opts +read code +echo "\$opts" | grep -q '^host=' +echo "code=\$code (#5.2.1) \$opts" +exit \$code +EOF +chmod +x $tmpdir/protocols/dummy + +echo 127.0.0.1 smtp >$SYSCONFDIR/remotes + +# Start up the servers +start send $builddir/src/nullmailer-send + +make_message() { + msgid=$(date +%s).$$.me + cat <<EOF >$QUEUEDIR/tmp/$msgid +me@example.com +me@example.net + +Subject: test +Message-Id: <$msgid> + +This is just a test. +EOF + mv -f $QUEUEDIR/tmp/$msgid $QUEUEDIR/queue/$msgid +} + +send_message() { + echo 127.0.0.1 dummy $@ >$SYSCONFDIR/remotes + make_message + svc -a $tmpdir/service/send + sleep 2 + not test -e $QUEUEDIR/queue/$msgid +} + +echo 'Testing sending with a succeeding protocol' +send_message 0 2.0.0 + +echo 'Testing sending with a failing protocol' +not send_message 1 5.2.2 +rm -f $QUEUEDIR/queue/$msgid + +echo 'Testing handling of a permanent failure' +send_message 33 5.2.2 + +echo 'Checking failed message was moved out of the queue' +test -e $QUEUEDIR/failed/$msgid +rm -f $QUEUEDIR/failed/$msgid + +echo 'Checking for a generated bounce message' +# It will also bounce, so look at failed messages +msgid2=$( ls $QUEUEDIR/failed ) +test $( wc -w <<< $msgid2 ) = 1 +fn=$QUEUEDIR/failed/$msgid2 + +echo 'Checking bounce sender' +head -n 1 $fn | grep -qx '' + +echo 'Checking bounce recipient' +sed -e '1d;q' $fn | grep -qx 'me@example.com' +sed -e '1,2d;q' $fn | grep -qx '' + +echo 'Checking bounce contents' +sed -e '1,3d; /^$/q' $fn | grep -qx 'To: <me@example.com>' +sed -e '1,3d; 1,/^$/d' $fn | grep -qx 'Reporting-MTA: x-local-hostname; f.q.d.n' +sed -e '1,3d; 1,/^$/d' $fn | grep -qx 'Final-Recipient: rfc822; me@example.net' +sed -e '1,3d; 1,/^$/d' $fn | grep -qx 'Action: failed' +sed -e '1,3d; 1,/^$/d' $fn | grep -qx 'Status: 5.2.1' +sed -e '1,3d; 1,/^$/d' $fn | grep -qx 'Diagnostic-Code: DUMMY; code=33 (#5.2.1) host=127.0.0.1' +sed -e '1,3d; 1,/^$/d' $fn | grep -qx 'Subject: test' +sed -e '1,3d; 1,/^$/d' $fn | not grep -qx 'This is just a test.' + +echo 'Checking log outputs' +log=$tmpdir/service/send-log +grep -qx "^Starting delivery: host: 127.0.0.1 protocol: dummy file: $msgid" $log +grep -qx 'From: <me@example.com> to: <me@example.net>' $log +grep -qx 'Sending failed: Unspecified temporary error' $log +grep -qx "Message-Id: <$msgid>" $log |