From: Ken Hornstein Date: Thu, 15 Mar 2012 01:15:54 +0000 (-0400) Subject: New test suite for "post"; uses fakesmtp to trap the SMTP protocol. X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=b2fb9dfa039340fb4776e36cb381d02fffacd608;p=mmh New test suite for "post"; uses fakesmtp to trap the SMTP protocol. --- diff --git a/Makefile.am b/Makefile.am index e402ca1..8abe7ed 100644 --- a/Makefile.am +++ b/Makefile.am @@ -57,6 +57,9 @@ TESTS = test/bad-input/test-header \ test/mhshow/test-subpart test/mhstore/test-mhstore \ test/new/test-basic \ test/pick/test-pick test/pick/test-stderr \ + test/post/test-post-basic test/post/test-post-multiple \ + test/post/test-post-dcc test/post/test-post-fcc \ + test/post/test-post-multifrom test/post/test-post-envelope \ test/refile/test-refile \ test/repl/test-if-str test/scan/test-scan \ test/sequences/test-flist test/sequences/test-mark \ @@ -207,7 +210,8 @@ EXTRA_DIST = config/version.sh sbr/sigmsg.awk etc/mts.conf.in etc/sendfiles.in \ man/sendfiles.man man/show.man man/slocal.man man/sortm.man \ man/unseen.man man/whatnow.man man/whom.man test/README $(TESTS) \ test/inc/deb359167.mbox test/inc/fromline.txt \ - test/inc/msgheader.txt test/inc/filler.txt test/inc/md5sums + test/inc/msgheader.txt test/inc/filler.txt test/inc/md5sums \ + test/post/test-post-common.sh ## ## These are all of the definitions for each of the programs listed above. diff --git a/test/common.sh.in b/test/common.sh.in index e596fb1..1162566 100644 --- a/test/common.sh.in +++ b/test/common.sh.in @@ -137,6 +137,7 @@ Path: ${MH_TEST_DIR}/Mail mhlproc: ${MH_LIB_DIR}/mhl showproc: ${MH_LIB_DIR}/mhl postproc: ${MH_LIB_DIR}/post +fileproc: ${MH_INST_DIR}${bindir}/refile EOF for f in MailAliases components digestcomps distcomps forwcomps mhl.body \ diff --git a/test/post/test-post-basic b/test/post/test-post-basic new file mode 100755 index 0000000..a2e4fac --- /dev/null +++ b/test/post/test-post-basic @@ -0,0 +1,64 @@ +#!/bin/sh +# +# Test the basic behavior of post +# + +set -e + +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname "$0"`/../.. + MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR +fi + +. "${srcdir}/test/post/test-post-common.sh" + +# +# Basic test - Simple message, single user, single recipient. Note that +# we test dot-stuffing here as well. +# + +cat > "${MH_TEST_DIR}/Mail/draft" < +To: Somebody Else +Subject: Test + +This is a test +. +EOF + +cat > "${testname}.expected" < +RCPT TO: +DATA +From: Mr Nobody +To: Somebody Else +Subject: Test +Date: + +This is a test +.. +. +QUIT +EOF + +test_post "${testname}.actual" "${testname}.expected" + +# +# Make sure a draft without a From: is rejected +# + +cat > "${MH_TEST_DIR}/Mail/draft" < +Subject: Blank Test + +This is a blank test +EOF + +run_test "send -draft -server 127.0.0.1 -port $localport" \ + "post: message has no From: header +post: See default components files for examples +post: re-format message and try again +send: message not delivered to anyone" + +exit ${failed:-0} diff --git a/test/post/test-post-common.sh b/test/post/test-post-common.sh new file mode 100755 index 0000000..7698b81 --- /dev/null +++ b/test/post/test-post-common.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# +# Common routines for the post tests +# + +set -e + +. "${MH_OBJ_DIR}/test/common.sh" + +setup_test + +localport=65412 +testname="${MH_TEST_DIR}/$$" + +# +# Set this for the EHLO command +# + +echo "clientname: nosuchhost.example.com" >> ${MHMTSCONF} + +# +# One "post" test run. Ok, yeah, we're using "send", but that's just +# because it's easier. +# + +test_post () +{ "${MH_OBJ_DIR}/test/fakesmtp" "$1" $localport & + pid="$!" + + send -draft -server 127.0.0.1 -port $localport || exit 1 + + wait $! + + # + # It's hard to calculate the exact Date: header post is going to + # use, so we'll just use sed to remove the actual date so we can easily + # compare it against our "correct" output. + # + + sed -i "" -e 's/^Date:.*/Date:/' "$1" + + check "$1" "$2" +} diff --git a/test/post/test-post-dcc b/test/post/test-post-dcc new file mode 100755 index 0000000..f2bbda6 --- /dev/null +++ b/test/post/test-post-dcc @@ -0,0 +1,48 @@ +#!/bin/sh +# +# Test the behavior of post with multiple recipients (& dcc) +# + +set -e + +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname "$0"`/../.. + MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR +fi + +. "${srcdir}/test/post/test-post-common.sh" + +# +# Dcc test +# +cat > "${MH_TEST_DIR}/Mail/draft" < +To: Somebody One , + Somebody Two +Subject: Test Dcc +Dcc: Somebody Three + +This is test of Dcc recipients. +EOF + +cat > "${testname}.expected" < +RCPT TO: +RCPT TO: +RCPT TO: +DATA +From: Mr Nobody +To: Somebody One , + Somebody Two +Subject: Test Dcc +Date: + +This is test of Dcc recipients. +. +QUIT +EOF + +test_post "${testname}.actual" "${testname}.expected" + +exit ${failed:-0} diff --git a/test/post/test-post-envelope b/test/post/test-post-envelope new file mode 100755 index 0000000..7d3288b --- /dev/null +++ b/test/post/test-post-envelope @@ -0,0 +1,179 @@ +#!/bin/sh +# +# Test the setting of the envelope-from address for SMTP +# +# Note here we use multiple From: addresses for some tests so we pick up +# some cases skipped in other tests. +# + +set -e + +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname "$0"`/../.. + MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR +fi + +. "${srcdir}/test/post/test-post-common.sh" + +# +# Sender +# + +cat > "${MH_TEST_DIR}/Mail/draft" <, + Mr Nobody Two +Sender: Mr Nobody Three +To: Somebody Else +Subject: Sender test + +This is a test of the Sender header. +EOF + +cat > "${testname}.0.expected" < +RCPT TO: +DATA +From: Mr Nobody One , + Mr Nobody Two +Sender: Mr Nobody Three +To: Somebody Else +Subject: Sender test +Date: + +This is a test of the Sender header. +. +QUIT +EOF + +test_post "${testname}.0.actual" "${testname}.0.expected" + +# +# Check to see if Envelope-From overrides Sender +# + +cat > "${MH_TEST_DIR}/Mail/draft" <, + Mr Nobody Two +Sender: Mr Nobody Three +Envelope-From: Mr Nobody Four +To: Somebody Else +Subject: Envelope-From test + +This is a test of the Envelope-From header. +EOF + +cat > "${testname}.1.expected" < +RCPT TO: +DATA +From: Mr Nobody One , + Mr Nobody Two +Sender: Mr Nobody Three +To: Somebody Else +Subject: Envelope-From test +Date: + +This is a test of the Envelope-From header. +. +QUIT +EOF + +test_post "${testname}.1.actual" "${testname}.1.expected" + +# +# See if Envelope-From will generate a Sender: header with multiple From: +# addresses +# + +cat > "${MH_TEST_DIR}/Mail/draft" <, + Mr Nobody Two +Envelope-From: Mr Nobody Four +To: Somebody Else +Subject: Envelope-From and Sender test + +This is a test of the Envelope-From and Sender headers. +EOF + +cat > "${testname}.2.expected" < +RCPT TO: +DATA +From: Mr Nobody One , + Mr Nobody Two +To: Somebody Else +Subject: Envelope-From and Sender test +Date: +Sender: nobody4@example.com + +This is a test of the Envelope-From and Sender headers. +. +QUIT +EOF + +test_post "${testname}.2.actual" "${testname}.2.expected" + +# +# And make sure we do NOT get a Sender with only one From: +# + +cat > "${MH_TEST_DIR}/Mail/draft" < +Envelope-From: Mr Nobody Five +To: Somebody Else +Subject: Solo Envelope-From test + +This is a solo test of the Envelope-From header. +EOF + +cat > "${testname}.3.expected" < +RCPT TO: +DATA +From: Mr Nobody One +To: Somebody Else +Subject: Solo Envelope-From test +Date: + +This is a solo test of the Envelope-From header. +. +QUIT +EOF + +test_post "${testname}.3.actual" "${testname}.3.expected" + +# +# Make sure blank Envelope-From does what we expect it to +# + +cat > "${MH_TEST_DIR}/Mail/draft" < +Envelope-From: +To: Somebody Else +Subject: Blank Envelope-From test + +This is a blank test of the Envelope-From header. +EOF + +cat > "${testname}.4.expected" < +RCPT TO: +DATA +From: Mr Nobody One +To: Somebody Else +Subject: Blank Envelope-From test +Date: + +This is a blank test of the Envelope-From header. +. +QUIT +EOF + +test_post "${testname}.4.actual" "${testname}.4.expected" + +exit ${failed:-0} diff --git a/test/post/test-post-fcc b/test/post/test-post-fcc new file mode 100755 index 0000000..b8a9419 --- /dev/null +++ b/test/post/test-post-fcc @@ -0,0 +1,61 @@ +#!/bin/sh +# +# Test the Fcc: feature of post +# + +set -e + +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname "$0"`/../.. + MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR +fi + +. "${srcdir}/test/post/test-post-common.sh" + +# +# Basic test - Simple message, single user, single recipient. Note that +# we test dot-stuffing here as well. +# + +cat > "${MH_TEST_DIR}/Mail/draft" < +To: Somebody Else +Subject: Fcc test +Fcc: +inbox + +This is a fcc test +EOF + +cat > "${testname}.expected" < +RCPT TO: +DATA +From: Mr Nobody +To: Somebody Else +Subject: Fcc test +Date: + +This is a fcc test +. +QUIT +EOF + +test_post "${testname}.actual" "${testname}.expected" + +cat > "${testname}.msg.expected" < +To: Somebody Else +Subject: Fcc test +Date: + +This is a fcc test +EOF + +msgname=$(mhpath +inbox 11) + +sed -i "" -e 's/^Date:.*/Date:/' ${msgname} + +check "${testname}.msg.expected" ${msgname} + +exit ${failed:-0} diff --git a/test/post/test-post-multifrom b/test/post/test-post-multifrom new file mode 100755 index 0000000..9810141 --- /dev/null +++ b/test/post/test-post-multifrom @@ -0,0 +1,55 @@ +#!/bin/sh +# +# Test the behavior of post with multiple from addresses +# + +set -e + +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname "$0"`/../.. + MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR +fi + +. "${srcdir}/test/post/test-post-common.sh" + +# +# This SHOULD error +# + +cat > "${MH_TEST_DIR}/Mail/draft" <, Mr Nobody Two +To: Somebody Else +Subject: Test multi-from + +This is a test of multi-from. +EOF + +# +# Since this should fail, don't run fakesmtp +# + +run_test "send -draft -server 127.0.0.1 -port $localport" \ + "post: A Sender: or Envelope-From: header is required with multiple +From: addresses +post: re-format message and try again +send: message not delivered to anyone" + +# +# This should also error +# +cat > "${MH_TEST_DIR}/Mail/draft" <, Mr Nobody Two +To: Somebody Else +Subject: Test multi-from +Envelope-From: + +This is a test of multi-from with blank Envelope-From. +EOF + +run_test "send -draft -server 127.0.0.1 -port $localport" \ + "post: Envelope-From cannot be blank when there is multiple From: addresses +and no Sender: header +post: re-format message and try again +send: message not delivered to anyone" + +exit ${failed:-0} diff --git a/test/post/test-post-multiple b/test/post/test-post-multiple new file mode 100755 index 0000000..4fe3e85 --- /dev/null +++ b/test/post/test-post-multiple @@ -0,0 +1,46 @@ +#!/bin/sh +# +# Test the behavior of post with multiple recipients +# + +set -e + +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname "$0"`/../.. + MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR +fi + +. "${srcdir}/test/post/test-post-common.sh" + +# +# Multiple recipients test +# +cat > "${MH_TEST_DIR}/Mail/draft" < +To: Somebody One , + Somebody Two +Subject: Test multiple + +This is test of multiple recipients. +EOF + +cat > "${testname}.expected" < +RCPT TO: +RCPT TO: +DATA +From: Mr Nobody +To: Somebody One , + Somebody Two +Subject: Test multiple +Date: + +This is test of multiple recipients. +. +QUIT +EOF + +test_post "${testname}.actual" "${testname}.expected" + +exit ${failed:-0}