]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
mlmmj-process: add tests for simple reception and subscription
authorBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 8 Mar 2023 17:05:52 +0000 (18:05 +0100)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 8 Mar 2023 17:05:52 +0000 (18:05 +0100)
While here ensure we exit with failures in case we have a bad envelop

src/mlmmj-process.c
tests/mlmmj-receive.sh

index ab6f93a4745b067ec6d2f62090a765454c491eaa..5f577e6be0817ac9d2db4df850e4b9f8e8b98d2a 100644 (file)
@@ -749,7 +749,7 @@ int main(int argc, char **argv)
                free(discardname);
                free(randomstr);
                /* TODO: free emailstructs */
-               exit(EXIT_SUCCESS);
+               exit(EXIT_FAILURE);
        }
 
        unlink(mailfile);
index f2b836776b0d20799bd3ff3d726ec53dfda850bc..dbd9675d9cbebab4b9373f031d18eb488009364c 100755 (executable)
@@ -3,12 +3,15 @@
 . $(atf_get_srcdir)/test_env.sh
 
 tests_init \
-       basics
+       basics \
+       simple \
+       subscribe
+
+mlmmjreceive=$(command -v mlmmj-receive)
 
 basics_body()
 {
 
-       mlmmjreceive=$(command -v mlmmj-receive)
        helptxt="Usage: $mlmmjreceive -L /path/to/listdir
        [-s sender@example.org] [-e extension] [-h] [-V] [-P] [-F]
  -h: This help
@@ -65,3 +68,194 @@ EOF
        *) atf_fail "Extra files left" ;;
        esac
 }
+
+simple_body()
+{
+       atf_check $srcdir/fakesmtpd
+       trap kill_fakesmtp EXIT TERM
+       init_ml list
+       rmdir list/text
+       ln -s ${srcdir}/../listtexts/en list/text
+       echo test@mlmmjtest > list/control/listaddress
+       echo "25678" > list/control/smtpport
+       echo "heloname" > list/control/smtphelo
+       cat > incoming-invalid << EOF
+From: bob@test
+To: invalid@test
+Subject: subscribe
+
+this is a subscribtion test
+EOF
+
+       atf_check -s exit:1 $mlmmjreceive -L list -F <incoming-invalid
+       atf_check -s exit:1 test -f mail-1.txt
+
+       cat > incoming << EOF
+From: bob@test
+To: invalid@test
+Return-Path: jane@test
+Subject: subscribe
+
+this is a subscribtion test
+EOF
+       atf_check $mlmmjreceive -L list -F <incoming
+cat > expected-1.txt << EOF
+EHLO heloname\r
+MAIL FROM:<test+bounces-help@mlmmjtest>\r
+RCPT TO:<bob@test>\r
+DATA\r
+Subject: =?utf-8?q?Post_to_test=40mlmmjtest_denied:_subscribe?=\r
+MIME-Version: 1.0\r
+Content-Type: multipart/mixed;\r
+ boundary
+Content-Transfer-Encoding: 8bit\r
+From: test+owner@mlmmjtest\r
+To: bob@test\r
+\r
+--=RANDOM=\r
+Content-Type: text/plain; charset=utf8\r
+Content-Transfer-Encoding: 8bit\r
+\r
+Hi, this is the Mlmmj program managing the <test@mlmmjtest> mailing list.\r
+\r
+The message from <bob@test> with subject "subscribe" was unable to be\r
+delivered to the list because the list address was not found in either the\r
+To: or CC: header.\r
+\r
+(The denied message is below.)\r
+\r
+--=RANDOM=\r
+Content-Type: message/rfc822\r
+Content-Transfer-Encoding: 8bit\r
+Content-Disposition: inline; filename="message.eml"\r
+\r
+From: bob@test\r
+To: invalid@test\r
+Subject: subscribe\r
+\r
+this is a subscribtion test\r
+--=RANDOM=--\r
+\r
+.\r
+QUIT\r
+EOF
+       atf_check -o file:expected-1.txt sed -e "/^Message-ID:/d; /^Date:/d; s/boundary=.*/boundary/g; s/--=.*=/--=RANDOM=/g" mail-1.txt
+       cat > incoming << EOF
+From: bob@test
+To: test@mlmmjtest
+Return-Path: jane@test
+Subject: subscribe
+
+this is a subscribtion test
+EOF
+       cat > archived << EOF
+From: bob@test
+To: test@mlmmjtest
+Subject: subscribe
+
+this is a subscribtion test
+EOF
+       atf_check $mlmmjreceive -L list -F <incoming
+       atf_check -o file:archived cat list/archive/1
+}
+
+subscribe_body()
+{
+       atf_check $srcdir/fakesmtpd
+       trap kill_fakesmtp EXIT TERM
+       init_ml list
+       rmdir list/text
+       ln -s ${srcdir}/../listtexts/en list/text
+       echo test@mlmmjtest > list/control/listaddress
+       echo "25678" > list/control/smtpport
+       echo "heloname" > list/control/smtphelo
+
+       cat > incoming << EOF
+From: bob@test
+To: test+subscribe@mlmmjtest
+Return-Path: jane@test
+Subject: subscribe
+
+this is a subscribtion test
+EOF
+       atf_check $mlmmjreceive -L list -F <incoming
+
+cat > expected-1.txt <<EOF
+EHLO heloname\r
+MAIL FROM:<test+bounces-confsub-@mlmmjtest>\r
+RCPT TO:<bob@test>\r
+DATA\r
+Subject: =?utf-8?q?Confirm_subscription_to_test=40mlmmjtest?=\r
+From: test+help@mlmmjtest\r
+To: bob@test\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Transfer-Encoding: 8bit\r
+Reply-To: test+confsub-@mlmmjtest\r
+\r
+Hi, this is the Mlmmj program managing the <test@mlmmjtest> mailing list.\r
+\r
+Somebody (and we hope it was you) has requested that your email address\r
+<bob@test> be added to the list. This means every time a post is sent to\r
+the list, you will receive a copy of it.\r
+\r
+To confirm you want to do this, please send a message to\r
+<test+confsub-@mlmmjtest> which can usually be done simply\r
+by replying to this message. The subject and the body of the message can be\r
+anything.\r
+\r
+After doing so, you should receive a reply informing you that the operation\r
+succeeded.\r
+\r
+If you do not want to do this, simply ignore this message.\r
+\r
+\r
+.\r
+QUIT\r
+EOF
+       atf_check -o file:expected-1.txt sed -e "/^Message-ID:/d; /^Date:/d; s/confsub-.*@mlmmjtest/confsub-@mlmmjtest/g" mail-1.txt
+       var=$(ls list/subconf)
+
+       cat > incoming << EOF
+From: bob@test
+To: test+confsub-${var}@mlmmjtest
+Return-Path: jane@test
+Subject: subscribe
+
+this is a subscribtion test
+EOF
+       atf_check $mlmmjreceive -L list -F <incoming
+       cat > expected-2.txt <<EOF
+EHLO heloname\r
+MAIL FROM:<test+bounces-help@mlmmjtest>\r
+RCPT TO:<bob@test>\r
+DATA\r
+Subject: =?utf-8?q?Welcome_to_test=40mlmmjtest?=\r
+From: test+help@mlmmjtest\r
+To: bob@test\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Transfer-Encoding: 8bit\r
+\r
+Hi, this is the Mlmmj program managing the <test@mlmmjtest> mailing list.\r
+\r
+Thank you for confirming your subscription. You have now been added to the\r
+normal version of the list.\r
+\r
+The email address you are subscribed with is <bob@test>.\r
+\r
+If you ever wish to unsubscribe, send a message to\r
+<test+unsubscribe@mlmmjtest> using this email address. The subject and the\r
+body of the message can be anything. You will then receive confirmation or\r
+further instructions.\r
+\r
+For other information and help about this list, send a message to\r
+<test+help@mlmmjtest>.\r
+\r
+\r
+.\r
+QUIT\r
+EOF
+       atf_check -o file:expected-2.txt sed -e "/^Message-ID:/d; /^Date:/d" mail-2.txt
+       atf_check -o inline:"bob@test\n" cat list/subscribers.d/b
+}