summaryrefslogtreecommitdiff
path: root/test/tests/inject
diff options
context:
space:
mode:
Diffstat (limited to 'test/tests/inject')
-rw-r--r--test/tests/inject/bad-headers15
-rw-r--r--test/tests/inject/date12
-rw-r--r--test/tests/inject/from70
-rw-r--r--test/tests/inject/from_10
-rw-r--r--test/tests/inject/message-id23
-rw-r--r--test/tests/inject/queue15
-rw-r--r--test/tests/inject/recips50
-rw-r--r--test/tests/inject/return-path9
-rw-r--r--test/tests/inject/sender86
9 files changed, 290 insertions, 0 deletions
diff --git a/test/tests/inject/bad-headers b/test/tests/inject/bad-headers
new file mode 100644
index 0000000..a33dfeb
--- /dev/null
+++ b/test/tests/inject/bad-headers
@@ -0,0 +1,15 @@
+. functions
+
+injtest() { echo "$@" | not inject >/dev/null; }
+
+echo "Checking that inject rejects leading continuation lines."
+injtest " foo..."
+
+echo "Checking that inject rejects malformed RFC headers."
+injtest "foo : bar"
+injtest ":foo bar"
+injtest "foo"
+
+echo "Checking that inject rejects bad addresses."
+injtest "from: foo<bar"
+
diff --git a/test/tests/inject/date b/test/tests/inject/date
new file mode 100644
index 0000000..9510436
--- /dev/null
+++ b/test/tests/inject/date
@@ -0,0 +1,12 @@
+. functions
+
+inj() { injectfield date 'to: nobody' "$@"; }
+
+echo "Checking that inject inserts a date line."
+test -n "`inj`"
+
+echo "Checking that inject preserves an existing date line."
+inj "date: foo" | grep '^ foo$' >/dev/null
+
+echo "Checking that inject does not add more date lines."
+test 1 -eq `inj "date: foo" | wc -l`
diff --git a/test/tests/inject/from b/test/tests/inject/from
new file mode 100644
index 0000000..001b185
--- /dev/null
+++ b/test/tests/inject/from
@@ -0,0 +1,70 @@
+. functions
+
+inj() { injectfield from 'to: nobody' "$@"; }
+testvar() {
+ set -e
+ echo "Checking that inject obeys $1."
+ export $1="$2"
+ inj | grep -q "$3"
+}
+
+echo "Checking that inject inserts a from line."
+test -n "`inj`"
+
+echo "Checking that inject preserves an existing from line."
+inj "from: a@b.c" | grep -q '^ a@b\.c$'
+
+echo "Checking that inject does not add more from lines."
+test 1 -eq `inj "from: a@b.c" | wc -l`
+
+echo "Checking that inject will strip from lines."
+export NULLMAILER_FLAGS=f
+inj "from: a@b.c" | not grep -q '^ a@b\.c$'
+unset NULLMAILER_FLAGS
+
+echo "Checking that inject obeys me"
+rm -f $SYSCONFDIR/default*
+inj | grep -q "@f.q.d.n>$"
+
+echo "Checking that inject obeys config/defaulthost"
+echo test.org >$SYSCONFDIR/defaulthost
+inj | grep -q '@test.org>$'
+
+echo "Checking that inject obeys config/defaultdomain"
+echo test >$SYSCONFDIR/defaulthost
+echo domain.org >$SYSCONFDIR/defaultdomain
+inj | grep -q '@test.domain.org>$'
+
+echo "Checking that inject ignores config/defaultdomain for localhost"
+echo localhost >$SYSCONFDIR/defaulthost
+inj | grep -q '@localhost>$'
+
+testvar HOSTNAME test1.org '@test1.org>$'
+
+testvar MAILHOST test2.org '@test2.org>$'
+
+testvar NULLMAILER_HOST test3.org '@test3.org>$'
+
+echo "Checking that inject uses getpwnam"
+inj | grep -q " <`id -un`@"
+
+testvar LOGNAME name1 ' <name1@'
+
+testvar USER name2 ' <name2@'
+
+testvar MAILUSER name3 ' <name3@'
+
+testvar NULLMAILER_USER name4 ' <name4@'
+
+echo "Checking that inject uses a blank name."
+inj | grep -q '^ <'
+
+testvar NAME full1 '^ full1 <'
+
+testvar MAILNAME full2 '^ full2 <'
+
+testvar NULLMAILER_NAME full3 '^ full3 <'
+
+echo "Checking that inject will use address-comment form."
+export NULLMAILER_FLAGS=c
+inj | grep -q '^ name4@test3.org (full3)$'
diff --git a/test/tests/inject/from_ b/test/tests/inject/from_
new file mode 100644
index 0000000..33e973b
--- /dev/null
+++ b/test/tests/inject/from_
@@ -0,0 +1,10 @@
+. functions
+
+injectfrom() { injectlines "${1}From somebody" "Subject: test1" "To: nowhere"; }
+
+for lead in '' '>'
+do
+ echo "Checking that inject ignores a leading \"${lead}From \" line"
+ injectfrom "$lead" | egrep -qv '^>?From '
+ injectfrom "$lead" | head -n 1 | grep -q '^Subject:'
+done
diff --git a/test/tests/inject/message-id b/test/tests/inject/message-id
new file mode 100644
index 0000000..a553a5d
--- /dev/null
+++ b/test/tests/inject/message-id
@@ -0,0 +1,23 @@
+. functions
+
+inj() { injectfield message-id 'to: n' "$@"; }
+
+echo "Checking that inject inserts a message-id."
+test -n "`inj`"
+
+echo "Checking that inject preserves an existing message-id."
+inj "Message-Id: <mid@mid>" | grep -q '^ <mid@mid>$'
+
+echo "Checking that inject does not add more message-ids."
+test 1 -eq `inj "Message-Id: <mid@mid>" | wc -l`
+
+echo "Checking that inject will ignore an existing message-id."
+export NULLMAILER_FLAGS=i
+inj "Message-Id: <mid@mid>" | not grep -q '^ <mid@mid>$'
+
+echo "Checking that inject obeys me"
+inj | grep -q "@f.q.d.n>$"
+
+echo "Checking that inject obeys config/idhost"
+echo test1.org >$SYSCONFDIR/idhost
+inj | grep -q '@test1.org>$'
diff --git a/test/tests/inject/queue b/test/tests/inject/queue
new file mode 100644
index 0000000..fa2f8c2
--- /dev/null
+++ b/test/tests/inject/queue
@@ -0,0 +1,15 @@
+. functions
+
+echo 'Testing that inject queues messages properly.'
+
+echo 'To: nobody' | inject
+test $( ls $QUEUEDIR/queue | wc -l ) = 1
+egrep -i '^to: *nobody' $QUEUEDIR/queue/* >/dev/null
+
+echo 'Testing that inject honors $NULLMAILER_QUEUE.'
+
+rm -f $QUEUEDIR/queue/*
+export NULLMAILER_QUEUE=/bin/cat
+echo 'To: nobody' | inject >/dev/null
+test $( ls $QUEUEDIR/queue | wc -l ) = 0
+unset NULLMAILER_QUEUE
diff --git a/test/tests/inject/recips b/test/tests/inject/recips
new file mode 100644
index 0000000..008a2cb
--- /dev/null
+++ b/test/tests/inject/recips
@@ -0,0 +1,50 @@
+. functions
+
+inj() { inject -n -v "$@" | tail -n +2 | sed '/^$/,$d'; }
+inj-find() { echo to: a@b.c | inj "$1" d@e.f | grep -q "$2"; }
+inj-notfind() { echo to: a@b.c | inj "$1" d@e.f | not grep -q "$2"; }
+
+hdrline='^a@b.c$'
+cmdline='^d@e.f$'
+
+echo "Checking that inject uses command line with -a."
+inj-find -a $cmdline
+
+echo "Checking that inject ignores header lines with -a."
+inj-notfind -a $hdrline
+
+echo "Checking that inject uses command line with -b."
+inj-find -b $cmdline
+
+echo "Checking that inject uses header lines with -b."
+inj-find -b $hdrline
+
+echo "Checking that inject ignores command line with -h."
+inj-notfind -h $cmdline
+
+echo "Checking that inject uses header lines with -h."
+inj-find -h $hdrline
+
+echo "Checking that inject uses command line with -e and no header."
+echo | inj -e d@e.f | grep -q $cmdline
+
+echo "Checking that inject uses command line with -e and header."
+inj-find -e $cmdline
+
+echo "Checking that inject uses header with -e and no command line."
+echo to: a@b.c | inj -e | grep -q $hdrline
+
+echo "Checking that inject ignores header with -e and command line."
+inj-notfind -e $hdrline
+
+echo "Checking that inject uses command line with no header by default."
+echo | inj -e d@e.f | grep -q $cmdline
+
+echo "Checking that inject uses command line with header by default."
+inj-find -e $cmdline
+
+echo "Checking that inject uses header with no command line by default."
+echo to: a@b.c | inj -e | grep -q $hdrline
+
+echo "Checking that inject ignores header with command line by default."
+inj-notfind -e $hdrline
diff --git a/test/tests/inject/return-path b/test/tests/inject/return-path
new file mode 100644
index 0000000..a3f61d2
--- /dev/null
+++ b/test/tests/inject/return-path
@@ -0,0 +1,9 @@
+. functions
+
+inj() { injectfield return-path 'to: n' "$@"; }
+
+echo "Checking that inject does not inserts a return-path."
+test -z "`inj`"
+
+echo "Checking that inject strips return-paths."
+test -z "`inj return-path: blah`"
diff --git a/test/tests/inject/sender b/test/tests/inject/sender
new file mode 100644
index 0000000..77932a3
--- /dev/null
+++ b/test/tests/inject/sender
@@ -0,0 +1,86 @@
+. functions
+
+inj() { inject -n -v "$@" a </dev/null 2>/dev/null | head -n 1; }
+testvar() {
+ set -e
+ echo "Checking that inject obeys $1."
+ export $1="$2"
+ inj | grep -q "$3"
+}
+testcanon() {
+ set -e
+ echo "Checking that inject canonicalizes $1."
+ export $1="$2"
+ inj | grep -q "$3"
+}
+testhdr() {
+ set -e
+ echo "Checking that inject $1 $2:"
+ echo $2: $3 | inject -n -v a 2>/dev/null | head -n 1 | grep -q "$4"
+}
+testign() { testhdr ignores "$@"; }
+testset() { testhdr uses "$@"; }
+testfrom() {
+ echo "Checking that inject honors -f '$1'"
+ inj -f "$1" | grep -qx "$2"
+}
+testfrom2() {
+ testfrom "$1" "$2"
+ testfrom "<$1>" "$2"
+}
+
+echo "Checking that inject obeys me"
+rm -f $SYSCONFDIR/default*
+inj | grep -q "@f.q.d.n$"
+
+echo "Checking that inject obeys config/defaulthost"
+echo test.org >$SYSCONFDIR/defaulthost
+inj | grep -q '@test.org$'
+
+echo "Checking that inject obeys config/defaultdomain"
+echo test >$SYSCONFDIR/defaulthost
+echo domain.org >$SYSCONFDIR/defaultdomain
+inj | grep -q '@test.domain.org$'
+
+echo "Checking that inject ignores config/defaultdomain for localhost"
+echo localhost >$SYSCONFDIR/defaulthost
+inj | grep -q '@localhost$'
+
+testvar HOSTNAME test1.org '@test1.org$'
+
+testcanon HOSTNAME test1 '@test1.domain.org$'
+
+testvar MAILHOST test2.org '@test2.org$'
+
+testcanon MAILHOST test2 '@test2.domain.org$'
+
+testvar NULLMAILER_HOST test3.org '@test3.org$'
+
+testcanon NULLMAILER_HOST test3 '@test3.domain.org$'
+
+echo "Checking that inject uses getpwnam"
+inj | grep -q "^`id -un`@"
+
+testvar LOGNAME name1 '^name1@'
+
+testvar USER name2 '^name2@'
+
+testvar MAILUSER name3 '^name3@'
+
+testvar NULLMAILER_USER name4 '^name4@'
+
+testign Errors-To a@b.c '^name4@test3'
+testign From a@b.c '^name4@test3'
+testign Reply-To a@b.c '^name4@test3'
+testign Resent-From a@b.c '^name4@test3'
+testign Resent-Reply-To a@b.c '^name4@test3'
+testign Resent-Sender a@b.c '^name4@test3'
+testign Return-Receipt-To a@b.c '^name4@test3'
+testign Sender a@b.c '^name4@test3'
+testset Return-Path name0@host0.org '^name0@host0.org$'
+export NULLMAILER_FLAGS=s
+testign Return-Path name0@host0.org '^name4@test3'
+
+testfrom2 '' ''
+testfrom2 'a@b.c' 'a@b.c'
+testfrom2 'a@b' 'a@b.domain.org'