Эх сурвалжийг харах

split tests, add signup/subscribe tests and fix regression

Pi 1 жил өмнө
parent
commit
5bfe3a3e83

+ 1 - 1
cropswap-reply.sh

@@ -3,7 +3,7 @@ SENDMAIL=/usr/sbin/sendmail
 if ((DEBUG != 0)); then
 	SENDMAIL="$DEBUGMAIL"
 fi
-/usr/bin/mailbot -N -t $SIGNUPRESP \
+/usr/bin/mailbot -N -t $RESP \
 	-A 'From: $MAILGROUP' \
 	-A "List-Id: $MAILGROUP" \
 	-A "List-Unsubscribe: <mailto:$MAILGROUP?subject=[UNSUBSCRIBE]>" \

+ 2 - 1
filters/postmaster@localhost

@@ -1,3 +1,4 @@
+SIGNUPRESP="/opt/cropswap/signup.eml"
 if (!$CONTINUE)
 {
    if (/^Subject:\s*\[SIGNUP\]\s*$/)
@@ -66,7 +67,7 @@ elsif ($CONTINUE)
             exit
          }
          gdbmclose
-         cc "|$DEBUGMAIL mailbot-reply"
+         RESP=$SIGNUPRESP
          to "|$MAILBOT"
       }
       else

+ 3 - 1
filters/subscriptions

@@ -1,3 +1,4 @@
+SUBSCRIBERESP="/opt/cropswap/subunsub.eml"
 gdbmopen($SLIST, "C")
 if (/^Subject:\s*\[(SUBSCRIBE|UNSUBSCRIBE)\]\s*$/)
 {
@@ -10,7 +11,8 @@ if ($SUBSCRIBE ne "")
    {
       gdbmclose
       system "$SUBUNSUB '$SUBSCRIBE' '$ALIAS' '$FROM'"
-      to "|$MAILBOT -N -t $SUBSCRIBERESP -A 'From: $MAILGROUP' -f$FROM /usr/sbin/sendmail $FROM"
+      RESP=$SUBSCRIBERESP
+      to "|$MAILBOT"
    }
    else
    {

+ 0 - 2
maildroprc

@@ -10,8 +10,6 @@ SENDMAIL="/opt/cropswap/sendmail.sh"
 SUBUNSUB="/opt/cropswap/subunsub.sh"
 DEBUGMAIL="/opt/cropswap/debug.sh"
 MAILBOT="/opt/cropswap/mailbot.sh"
-SIGNUPRESP="/opt/cropswap/signup.eml"
-SUBSCRIBERESP="/opt/cropswap/subunsub.eml"
 FILTERDIR="/opt/cropswap/filters"
 MAILDROPDIR="/var/mail/maildrop"
 DEBUG=($DEBUG != 0)

+ 48 - 0
test-cropswap-members@shandan.one.sh

@@ -0,0 +1,48 @@
+#!/bin/bash
+set -euo pipefail
+export DEBUG=1
+export TEST=1
+MAILDROPDIR=$(mktemp -d)
+cleanup (){
+	rm -rf "$MAILDROPDIR"
+}
+trap cleanup EXIT
+
+export MAILDROPDIR
+
+SCRIPTDIR=$(readlink -e "${BASH_SOURCE[0]%/*}")
+cd "$MAILDROPDIR"
+
+#
+# TEST cropswap-members@shandan.one
+mkdir cropswap-members@shandan.one
+${SCRIPTDIR}/cropswap-register.sh cropswap-members@shandan.one "Member" "member1@mail.com" &>/dev/null
+${SCRIPTDIR}/cropswap-register.sh cropswap-members@shandan.one "Member" "member2@mail.com" &>/dev/null
+${SCRIPTDIR}/cropswap-register.sh cropswap-members@shandan.one "Organizer" "organizer1@mail.com" &>/dev/null
+${SCRIPTDIR}/cropswap-register.sh cropswap-members@shandan.one "Organizer" "organizer2@mail.com" &>/dev/null
+
+set -x
+maildrop -funregistered@mail.com < ${SCRIPTDIR}/tests/cropswap-members@shandan.one/from-unregistered.eml 1>forward.out 2>forward.err || [ "$?" == "3" ]
+! grep '^From: A. Person <unregistered@mail.com>$' < forward.out
+! grep '^To: A. Person <unregistered@mail.com>$' < forward.out
+! grep '^To: Organizer <organizer1@mail.com>$' < forward.out
+! grep '^To: Organizer 1 <organizer2@mail.com>$' < forward.out
+! grep '^To: Member <member1@mail.com>$' < forward.out
+! grep '^To: Member 1 <member2@mail.com>$' < forward.out
+! grep '^Subject: \[Crop Swap Query\] .*$' < forward.out
+
+maildrop -fmember1@mail.com < ${SCRIPTDIR}/tests/cropswap-members@shandan.one/from-member.eml 1>forward.out 2>forward.err
+grep '^From: Member <cropswap-members@shandan.one>$' < forward.out
+! grep '^To: Member <member1@mail.com>$' < forward.out
+grep '^To: Organizer <organizer1@mail.com>$' < forward.out
+grep '^To: Organizer 1 <organizer2@mail.com>$' < forward.out
+grep '^To: Member 1 <member2@mail.com>$' < forward.out
+grep '^Subject: \[Crop Swap Member\] .*$' < forward.out
+
+maildrop -forganizer1@mail.com < ${SCRIPTDIR}/tests/cropswap-members@shandan.one/from-member-to-member.eml 1>forward.out 2>forward.err
+grep '^From: Organizer <cropswap-members@shandan.one>$' < forward.out
+! grep '^To: Organizer <organizer1@mail.com>$' < forward.out
+! grep '^To: Organizer 1 <organizer2@mail.com>$' < forward.out
+! grep '^To: Member <member1@mail.com>$' < forward.out
+grep '^To: Member 1 <member2@mail.com>$' < forward.out
+grep '^Subject: \[Crop Swap Member\] .*$' < forward.out

+ 63 - 0
test-cropswap@shandan.one.sh

@@ -0,0 +1,63 @@
+#!/bin/bash
+set -euo pipefail
+export DEBUG=1
+export TEST=1
+MAILDROPDIR=$(mktemp -d)
+cleanup (){
+	rm -rf "$MAILDROPDIR"
+}
+trap cleanup EXIT
+
+export MAILDROPDIR
+
+SCRIPTDIR=$(readlink -e "${BASH_SOURCE[0]%/*}")
+cd "$MAILDROPDIR"
+
+#
+# TEST cropswap@shandan.one
+mkdir cropswap@shandan.one
+${SCRIPTDIR}/cropswap-register.sh cropswap@shandan.one "Member" "member1@mail.com" &>/dev/null
+${SCRIPTDIR}/cropswap-register.sh cropswap@shandan.one "Member" "member2@mail.com" &>/dev/null
+${SCRIPTDIR}/cropswap-postmaster.sh SIGNUP cropswap@shandan.one organizer1@mail.com <<EOF &>/dev/null
+X-MEMBER-ALIAS: Organizer
+X-AUTH: admin
+EOF
+${SCRIPTDIR}/cropswap-postmaster.sh SUBSCRIBE cropswap@shandan.one organizer1@mail.com &>/dev/null
+${SCRIPTDIR}/cropswap-postmaster.sh SIGNUP cropswap@shandan.one organizer2@mail.com <<EOF &>/dev/null
+X-MEMBER-ALIAS: Organizer
+X-AUTH: admin
+EOF
+${SCRIPTDIR}/cropswap-postmaster.sh SUBSCRIBE cropswap@shandan.one organizer2@mail.com &>/dev/null
+
+set -x
+maildrop -funregistered@mail.com < ${SCRIPTDIR}/tests/cropswap@shandan.one/from-unregistered.eml 1>forward.out 2>forward.err
+grep '^From: A. Person <unregistered@mail.com>$' < forward.out
+! grep '^To: A. Person <unregistered@mail.com>$' < forward.out
+grep '^To: Organizer <organizer1@mail.com>$' < forward.out
+grep '^To: Organizer 1 <organizer2@mail.com>$' < forward.out
+! grep '^To: Member <member1@mail.com>$' < forward.out
+! grep '^To: Member 1 <member2@mail.com>$' < forward.out
+grep '^Subject: \[Crop Swap Query\] .*$' < forward.out
+
+maildrop -fmember1@mail.com < ${SCRIPTDIR}/tests/cropswap@shandan.one/from-member.eml 1>forward.out 2>forward.err
+grep '^From: Member <cropswap@shandan.one>$' < forward.out
+! grep '^To: Member <member1@mail.com>$' < forward.out
+grep '^To: Organizer <organizer1@mail.com>$' < forward.out
+grep '^To: Organizer 1 <organizer2@mail.com>$' < forward.out
+grep '^Subject: \[Crop Swap Query\] .*$' < forward.out
+
+maildrop -forganizer1@mail.com < ${SCRIPTDIR}/tests/cropswap@shandan.one/from-organizer-to-member.eml 1>forward.out 2>forward.err
+grep '^From: Organizer <cropswap@shandan.one>$' < forward.out
+! grep '^To: Organizer <organizer1@mail.com>$' < forward.out
+! grep '^To: Organizer 1 <organizer2@mail.com>$' < forward.out
+! grep '^To: Member <member1@mail.com>$' < forward.out
+grep '^To: Member 1 <member2@mail.com>$' < forward.out
+grep '^Subject: \[Crop Swap Notice\] .*$' < forward.out
+
+maildrop -forganizer2@mail.com < ${SCRIPTDIR}/tests/cropswap@shandan.one/from-organizer.eml 1>forward.out 2>forward.err
+grep '^From: Organizer 1 <cropswap@shandan.one>$' < forward.out
+! grep '^To: Organizer 1 <organizer2@mail.com>$' < forward.out
+grep '^To: Organizer <organizer1@mail.com>$' < forward.out
+grep '^To: Member <member1@mail.com>$' < forward.out
+grep '^To: Member 1 <member2@mail.com>$' < forward.out
+grep '^Subject: \[Crop Swap Notice\] .*$' < forward.out

+ 48 - 0
test-signup.sh

@@ -0,0 +1,48 @@
+#!/bin/bash
+set -euo pipefail
+export DEBUG=1
+export TEST=1
+MAILDROPDIR=$(mktemp -d)
+cleanup (){
+	rm -rf "$MAILDROPDIR"
+}
+trap cleanup EXIT
+
+export MAILDROPDIR
+
+SCRIPTDIR=$(readlink -e "${BASH_SOURCE[0]%/*}")
+cd "$MAILDROPDIR"
+
+#
+# TEST SIGNUP
+for g in "" "-members"; do
+	mkdir -p cropswap${g}@shandan.one
+	${SCRIPTDIR}/cropswap-postmaster.sh SIGNUP "cropswap${g}@shandan.one" admin@mail.com <<EOF 1> reply.out 2> reply.err
+X-MEMBER-ALIAS: Admin
+X-AUTH: admin
+EOF
+	grep 'You have been registered as a member' reply.out
+	grep '^\+Admin$' "cropswap${g}@shandan.one"/alist.txt
+	grep '^\+admin@mail.com$' cropswap${g}@shandan.one/alist.txt
+
+	${SCRIPTDIR}/cropswap-postmaster.sh SUBSCRIBE "cropswap${g}@shandan.one" admin@mail.com <<EOF 1> reply.out 2> reply.err
+EOF
+	grep 'Your subscription status has been updated successfully' reply.out
+	grep '^\+Admin$' "cropswap${g}@shandan.one"/slist.txt
+	grep '^\+admin@mail.com$' cropswap${g}@shandan.one/slist.txt
+done
+for g in "" "-members"; do
+	mkdir -p cropswap${g}@shandan.one
+	${SCRIPTDIR}/cropswap-postmaster.sh SIGNUP "cropswap${g}@shandan.one" non-admin@mail.com <<EOF 1> reply.out 2> reply.err
+X-MEMBER-ALIAS: Non-admin
+EOF
+	grep 'You have been registered as a member' reply.out
+	! grep '^\+Non\-admin$' "cropswap${g}@shandan.one"/alist.txt
+	! grep '^\+non-admin@mail.com$' cropswap${g}@shandan.one/alist.txt
+
+	${SCRIPTDIR}/cropswap-postmaster.sh SUBSCRIBE "cropswap${g}@shandan.one" non-admin@mail.com <<EOF 1> reply.out 2> reply.err
+EOF
+	grep 'Your subscription status has been updated successfully' reply.out
+	grep '^\+Non\-admin$' "cropswap${g}@shandan.one"/slist.txt
+	grep '^\+non-admin@mail.com$' cropswap${g}@shandan.one/slist.txt
+done

+ 3 - 95
test.sh

@@ -1,98 +1,6 @@
 #!/bin/bash
 set -euo pipefail
-export DEBUG=1
-export TEST=1
-MAILDROPDIR=$(mktemp -d)
-cleanup (){
-	rm -rf "$MAILDROPDIR"
-}
-trap cleanup EXIT
 
-export MAILDROPDIR
-
-SCRIPTDIR=$(readlink -e "${BASH_SOURCE[0]%/*}")
-cd "$MAILDROPDIR"
-
-#
-# TEST cropswap@shandan.one
-mkdir cropswap@shandan.one
-${SCRIPTDIR}/cropswap-register.sh cropswap@shandan.one "Member" "member1@mail.com" &>/dev/null
-${SCRIPTDIR}/cropswap-register.sh cropswap@shandan.one "Member" "member2@mail.com" &>/dev/null
-${SCRIPTDIR}/cropswap-postmaster.sh SIGNUP cropswap@shandan.one organizer1@mail.com <<EOF &>/dev/null
-X-MEMBER-ALIAS: Organizer
-X-AUTH: admin
-EOF
-${SCRIPTDIR}/cropswap-postmaster.sh SUBSCRIBE cropswap@shandan.one organizer1@mail.com &>/dev/null
-${SCRIPTDIR}/cropswap-postmaster.sh SIGNUP cropswap@shandan.one organizer2@mail.com <<EOF &>/dev/null
-X-MEMBER-ALIAS: Organizer
-X-AUTH: admin
-EOF
-${SCRIPTDIR}/cropswap-postmaster.sh SUBSCRIBE cropswap@shandan.one organizer2@mail.com &>/dev/null
-
-set -x
-maildrop -funregistered@mail.com < ${SCRIPTDIR}/tests/cropswap@shandan.one/from-unregistered.eml 1>forward.out 2>forward.err
-grep '^From: A. Person <unregistered@mail.com>$' < forward.out
-grep '^To: A. Person <unregistered@mail.com>$' < forward.out && false
-grep '^To: Organizer <organizer1@mail.com>$' < forward.out
-grep '^To: Organizer 1 <organizer2@mail.com>$' < forward.out
-grep '^To: Member <member1@mail.com>$' < forward.out && false
-grep '^To: Member 1 <member2@mail.com>$' < forward.out && false
-grep '^Subject: \[Crop Swap Query\] .*$' < forward.out
-
-maildrop -fmember1@mail.com < ${SCRIPTDIR}/tests/cropswap@shandan.one/from-member.eml 1>forward.out 2>forward.err
-grep '^From: Member <cropswap@shandan.one>$' < forward.out
-grep '^To: Member <member1@mail.com>$' < forward.out && false
-grep '^To: Organizer <organizer1@mail.com>$' < forward.out
-grep '^To: Organizer 1 <organizer2@mail.com>$' < forward.out
-grep '^Subject: \[Crop Swap Query\] .*$' < forward.out
-
-maildrop -forganizer1@mail.com < ${SCRIPTDIR}/tests/cropswap@shandan.one/from-organizer-to-member.eml 1>forward.out 2>forward.err
-grep '^From: Organizer <cropswap@shandan.one>$' < forward.out
-grep '^To: Organizer <organizer1@mail.com>$' < forward.out && false
-grep '^To: Organizer 1 <organizer2@mail.com>$' < forward.out && false
-grep '^To: Member <member1@mail.com>$' < forward.out && false
-grep '^To: Member 1 <member2@mail.com>$' < forward.out
-grep '^Subject: \[Crop Swap Notice\] .*$' < forward.out
-
-maildrop -forganizer2@mail.com < ${SCRIPTDIR}/tests/cropswap@shandan.one/from-organizer.eml 1>forward.out 2>forward.err
-grep '^From: Organizer 1 <cropswap@shandan.one>$' < forward.out
-grep '^To: Organizer 1 <organizer2@mail.com>$' < forward.out && false
-grep '^To: Organizer <organizer1@mail.com>$' < forward.out
-grep '^To: Member <member1@mail.com>$' < forward.out
-grep '^To: Member 1 <member2@mail.com>$' < forward.out
-grep '^Subject: \[Crop Swap Notice\] .*$' < forward.out
-set +x
-
-#
-# TEST cropswap-members@shandan.one
-mkdir cropswap-members@shandan.one
-${SCRIPTDIR}/cropswap-register.sh cropswap-members@shandan.one "Member" "member1@mail.com" &>/dev/null
-${SCRIPTDIR}/cropswap-register.sh cropswap-members@shandan.one "Member" "member2@mail.com" &>/dev/null
-${SCRIPTDIR}/cropswap-register.sh cropswap-members@shandan.one "Organizer" "organizer1@mail.com" &>/dev/null
-${SCRIPTDIR}/cropswap-register.sh cropswap-members@shandan.one "Organizer" "organizer2@mail.com" &>/dev/null
-
-set -x
-maildrop -funregistered@mail.com < ${SCRIPTDIR}/tests/cropswap-members@shandan.one/from-unregistered.eml 1>forward.out 2>forward.err
-grep '^From: A. Person <unregistered@mail.com>$' < forward.out && false
-grep '^To: A. Person <unregistered@mail.com>$' < forward.out && false
-grep '^To: Organizer <organizer1@mail.com>$' < forward.out && false
-grep '^To: Organizer 1 <organizer2@mail.com>$' < forward.out && false
-grep '^To: Member <member1@mail.com>$' < forward.out && false
-grep '^To: Member 1 <member2@mail.com>$' < forward.out && false
-grep '^Subject: \[Crop Swap Query\] .*$' < forward.out && false
-
-maildrop -fmember1@mail.com < ${SCRIPTDIR}/tests/cropswap-members@shandan.one/from-member.eml 1>forward.out 2>forward.err
-grep '^From: Member <cropswap-members@shandan.one>$' < forward.out
-grep '^To: Member <member1@mail.com>$' < forward.out && false
-grep '^To: Organizer <organizer1@mail.com>$' < forward.out
-grep '^To: Organizer 1 <organizer2@mail.com>$' < forward.out
-grep '^To: Member 1 <member2@mail.com>$' < forward.out
-grep '^Subject: \[Crop Swap Member\] .*$' < forward.out
-
-maildrop -forganizer1@mail.com < ${SCRIPTDIR}/tests/cropswap-members@shandan.one/from-member-to-member.eml 1>forward.out 2>forward.err
-grep '^From: Organizer <cropswap-members@shandan.one>$' < forward.out
-grep '^To: Organizer <organizer1@mail.com>$' < forward.out && false
-grep '^To: Organizer 1 <organizer2@mail.com>$' < forward.out && false
-grep '^To: Member <member1@mail.com>$' < forward.out && false
-grep '^To: Member 1 <member2@mail.com>$' < forward.out
-grep '^Subject: \[Crop Swap Member\] .*$' < forward.out
+./test-signup.sh
+./test-cropswap@shandan.one.sh
+./test-cropswap-members@shandan.one.sh

+ 1 - 1
tests/cropswap@shandan.one/from-member.eml

@@ -1,6 +1,6 @@
 From: Member <member1@mail.com>
 To: cropswap@shandan.one
-Subject: Question for Shannon
+Subject: Question for admins
 MIME-Version: 1.0
 Content-Type: multipart/alternative; 
 	boundary="----=_Part_16_6098270.1706251408890"

+ 1 - 1
tests/cropswap@shandan.one/from-organizer-to-member.eml

@@ -1,6 +1,6 @@
 From: Organizer <organizer1@mail.com>
 To: Member 1 <cropswap@shandan.one>
-Subject: Question for Shannon
+Subject: Response to Member
 MIME-Version: 1.0
 Content-Type: multipart/alternative; 
 	boundary="----=_Part_16_6098270.1706251408890"

+ 1 - 1
tests/cropswap@shandan.one/from-organizer.eml

@@ -1,6 +1,6 @@
 From: Organizer 1 <organizer2@mail.com>
 To: cropswap@shandan.one
-Subject: Question for Shannon
+Subject: Notice to all
 MIME-Version: 1.0
 Content-Type: multipart/alternative; 
 	boundary="----=_Part_16_6098270.1706251408890"

+ 1 - 1
tests/cropswap@shandan.one/from-unregistered.eml

@@ -1,6 +1,6 @@
 From: A. Person <unregistered@mail.com>
 To: cropswap@shandan.one
-Subject: Question for Shannon
+Subject: Question for admins
 MIME-Version: 1.0
 Content-Type: multipart/alternative; 
 	boundary="----=_Part_16_6098270.1706251408890"