New test suite for "post"; uses fakesmtp to trap the SMTP protocol.
authorKen Hornstein <kenh@pobox.com>
Thu, 15 Mar 2012 01:15:54 +0000 (21:15 -0400)
committerKen Hornstein <kenh@pobox.com>
Thu, 15 Mar 2012 01:15:54 +0000 (21:15 -0400)
Makefile.am
test/common.sh.in
test/post/test-post-basic [new file with mode: 0755]
test/post/test-post-common.sh [new file with mode: 0755]
test/post/test-post-dcc [new file with mode: 0755]
test/post/test-post-envelope [new file with mode: 0755]
test/post/test-post-fcc [new file with mode: 0755]
test/post/test-post-multifrom [new file with mode: 0755]
test/post/test-post-multiple [new file with mode: 0755]

index e402ca1..8abe7ed 100644 (file)
@@ -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.
index e596fb1..1162566 100644 (file)
@@ -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 (executable)
index 0000000..a2e4fac
--- /dev/null
@@ -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" <<EOF
+From: Mr Nobody <nobody@example.com>
+To: Somebody Else <somebody@example.com>
+Subject: Test
+
+This is a test
+.
+EOF
+
+cat > "${testname}.expected" <<EOF
+EHLO nosuchhost.example.com
+MAIL FROM:<nobody@example.com>
+RCPT TO:<somebody@example.com>
+DATA
+From: Mr Nobody <nobody@example.com>
+To: Somebody Else <somebody@example.com>
+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" <<EOF
+To: Somebody Else <somebody@example.com>
+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 (executable)
index 0000000..7698b81
--- /dev/null
@@ -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 (executable)
index 0000000..f2bbda6
--- /dev/null
@@ -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" <<EOF
+From: Mr Nobody <nobody@example.com>
+To: Somebody One <somebody1@example.com>,
+    Somebody Two <somebody2@example.com>
+Subject: Test Dcc
+Dcc: Somebody Three <somebody3@example.com>
+
+This is test of Dcc recipients.
+EOF
+
+cat > "${testname}.expected" <<EOF
+EHLO nosuchhost.example.com
+MAIL FROM:<nobody@example.com>
+RCPT TO:<somebody1@example.com>
+RCPT TO:<somebody2@example.com>
+RCPT TO:<somebody3@example.com>
+DATA
+From: Mr Nobody <nobody@example.com>
+To: Somebody One <somebody1@example.com>,
+    Somebody Two <somebody2@example.com>
+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 (executable)
index 0000000..7d3288b
--- /dev/null
@@ -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" <<EOF
+From: Mr Nobody One <nobody1@example.com>,
+      Mr Nobody Two <nobody2@example.com>
+Sender: Mr Nobody Three <nobody3@example.com>
+To: Somebody Else <somebody@example.com>
+Subject: Sender test
+
+This is a test of the Sender header.
+EOF
+
+cat > "${testname}.0.expected" <<EOF
+EHLO nosuchhost.example.com
+MAIL FROM:<nobody3@example.com>
+RCPT TO:<somebody@example.com>
+DATA
+From: Mr Nobody One <nobody1@example.com>,
+      Mr Nobody Two <nobody2@example.com>
+Sender: Mr Nobody Three <nobody3@example.com>
+To: Somebody Else <somebody@example.com>
+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" <<EOF
+From: Mr Nobody One <nobody1@example.com>,
+      Mr Nobody Two <nobody2@example.com>
+Sender: Mr Nobody Three <nobody3@example.com>
+Envelope-From: Mr Nobody Four <nobody4@example.com>
+To: Somebody Else <somebody@example.com>
+Subject: Envelope-From test
+
+This is a test of the Envelope-From header.
+EOF
+
+cat > "${testname}.1.expected" <<EOF
+EHLO nosuchhost.example.com
+MAIL FROM:<nobody4@example.com>
+RCPT TO:<somebody@example.com>
+DATA
+From: Mr Nobody One <nobody1@example.com>,
+      Mr Nobody Two <nobody2@example.com>
+Sender: Mr Nobody Three <nobody3@example.com>
+To: Somebody Else <somebody@example.com>
+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" <<EOF
+From: Mr Nobody One <nobody1@example.com>,
+      Mr Nobody Two <nobody2@example.com>
+Envelope-From: Mr Nobody Four <nobody4@example.com>
+To: Somebody Else <somebody@example.com>
+Subject: Envelope-From and Sender test
+
+This is a test of the Envelope-From and Sender headers.
+EOF
+
+cat > "${testname}.2.expected" <<EOF
+EHLO nosuchhost.example.com
+MAIL FROM:<nobody4@example.com>
+RCPT TO:<somebody@example.com>
+DATA
+From: Mr Nobody One <nobody1@example.com>,
+      Mr Nobody Two <nobody2@example.com>
+To: Somebody Else <somebody@example.com>
+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" <<EOF
+From: Mr Nobody One <nobody1@example.com>
+Envelope-From: Mr Nobody Five <nobody5@example.com>
+To: Somebody Else <somebody@example.com>
+Subject: Solo Envelope-From test
+
+This is a solo test of the Envelope-From header.
+EOF
+
+cat > "${testname}.3.expected" <<EOF
+EHLO nosuchhost.example.com
+MAIL FROM:<nobody5@example.com>
+RCPT TO:<somebody@example.com>
+DATA
+From: Mr Nobody One <nobody1@example.com>
+To: Somebody Else <somebody@example.com>
+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" <<EOF
+From: Mr Nobody One <nobody1@example.com>
+Envelope-From:
+To: Somebody Else <somebody@example.com>
+Subject: Blank Envelope-From test
+
+This is a blank test of the Envelope-From header.
+EOF
+
+cat > "${testname}.4.expected" <<EOF
+EHLO nosuchhost.example.com
+MAIL FROM:<>
+RCPT TO:<somebody@example.com>
+DATA
+From: Mr Nobody One <nobody1@example.com>
+To: Somebody Else <somebody@example.com>
+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 (executable)
index 0000000..b8a9419
--- /dev/null
@@ -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" <<EOF
+From: Mr Nobody <nobody@example.com>
+To: Somebody Else <somebody@example.com>
+Subject: Fcc test
+Fcc: +inbox
+
+This is a fcc test
+EOF
+
+cat > "${testname}.expected" <<EOF
+EHLO nosuchhost.example.com
+MAIL FROM:<nobody@example.com>
+RCPT TO:<somebody@example.com>
+DATA
+From: Mr Nobody <nobody@example.com>
+To: Somebody Else <somebody@example.com>
+Subject: Fcc test
+Date:
+
+This is a fcc test
+.
+QUIT
+EOF
+
+test_post "${testname}.actual" "${testname}.expected"
+
+cat > "${testname}.msg.expected" <<EOF
+From: Mr Nobody <nobody@example.com>
+To: Somebody Else <somebody@example.com>
+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 (executable)
index 0000000..9810141
--- /dev/null
@@ -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" <<EOF
+From: Mr Nobody One <nobody1@example.com>, Mr Nobody Two <nobody2@example.com>
+To: Somebody Else <somebody@example.com>
+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" <<EOF
+From: Mr Nobody One <nobody1@example.com>, Mr Nobody Two <nobody2@example.com>
+To: Somebody Else <somebody@example.com>
+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 (executable)
index 0000000..4fe3e85
--- /dev/null
@@ -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" <<EOF
+From: Mr Nobody <nobody@example.com>
+To: Somebody One <somebody1@example.com>,
+    Somebody Two <somebody2@example.com>
+Subject: Test multiple
+
+This is test of multiple recipients.
+EOF
+
+cat > "${testname}.expected" <<EOF
+EHLO nosuchhost.example.com
+MAIL FROM:<nobody@example.com>
+RCPT TO:<somebody1@example.com>
+RCPT TO:<somebody2@example.com>
+DATA
+From: Mr Nobody <nobody@example.com>
+To: Somebody One <somebody1@example.com>,
+    Somebody Two <somebody2@example.com>
+Subject: Test multiple
+Date:
+
+This is test of multiple recipients.
+.
+QUIT
+EOF
+
+test_post "${testname}.actual" "${testname}.expected"
+
+exit ${failed:-0}