From 4ad98f805b92d9548ce8c7d779d75337ff5786af Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Tue, 21 Jul 2009 13:09:06 +0200
Subject: [PATCH] Testsuite: added tests on the envelope of outgoing messages
 produced by redirect, enotify:mailto, reject and vacation.

---
 Makefile.am                            |   3 +
 src/testsuite/testsuite.c              |   1 +
 tests/execute/smtp.svtest              |  61 +++++++++++
 tests/extensions/enotify/mailto.svtest | 140 +++++++++++++++++++++++++
 tests/extensions/reject/smtp.svtest    |  56 ++++++++++
 tests/extensions/vacation/smtp.svtest  |  56 ++++++++++
 6 files changed, 317 insertions(+)
 create mode 100644 tests/execute/smtp.svtest
 create mode 100644 tests/extensions/reject/smtp.svtest
 create mode 100644 tests/extensions/vacation/smtp.svtest

diff --git a/Makefile.am b/Makefile.am
index 7301d3677..9657a4de4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -36,6 +36,7 @@ test_cases = \
 	tests/compile/errors.svtest \
 	tests/execute/errors.svtest \
 	tests/execute/actions.svtest \
+	tests/execute/smtp.svtest \
 	tests/exists.svtest \
 	tests/header.svtest \
 	tests/address.svtest \
@@ -68,6 +69,7 @@ test_cases = \
 	tests/extensions/regex/match-values.svtest \
 	tests/extensions/regex/errors.svtest \
 	tests/extensions/reject/execute.svtest \
+	tests/extensions/reject/smtp.svtest \
 	tests/extensions/relational/basic.svtest \
 	tests/extensions/relational/rfc.svtest \
 	tests/extensions/relational/errors.svtest \
@@ -76,6 +78,7 @@ test_cases = \
 	tests/extensions/vacation/errors.svtest \
 	tests/extensions/vacation/execute.svtest \
 	tests/extensions/vacation/message.svtest \
+	tests/extensions/vacation/smtp.svtest \
 	tests/extensions/enotify/basic.svtest \
 	tests/extensions/enotify/encodeurl.svtest \
 	tests/extensions/enotify/valid_notify_method.svtest \
diff --git a/src/testsuite/testsuite.c b/src/testsuite/testsuite.c
index 7c1ea07ae..edc08bb4c 100644
--- a/src/testsuite/testsuite.c
+++ b/src/testsuite/testsuite.c
@@ -220,6 +220,7 @@ int main(int argc, char **argv)
 		memset(&scriptenv, 0, sizeof(scriptenv));
 		scriptenv.default_mailbox = "INBOX";
 		scriptenv.hostname = "testsuite.example.com";
+		scriptenv.postmaster_address = "postmaster@example.com";
 		scriptenv.username = user;
 		scriptenv.smtp_open = testsuite_smtp_open;
 		scriptenv.smtp_close = testsuite_smtp_close;
diff --git a/tests/execute/smtp.svtest b/tests/execute/smtp.svtest
new file mode 100644
index 000000000..c45f0814e
--- /dev/null
+++ b/tests/execute/smtp.svtest
@@ -0,0 +1,61 @@
+require "vnd.dovecot.testsuite";
+require "envelope";
+
+test_set "message" text:
+From: stephan@rename-it.nl
+To: tss@iki.fi
+Subject: Frop!
+
+Frop!
+.
+;
+
+test_set "envelope.from" "sirius@rename-it.nl";
+test_set "envelope.to" "timo@iki.fi";
+
+test "Redirect" {
+	redirect "cras@iki.fi";
+
+	if not test_result_execute {
+        test_fail "failed to execute redirect";
+    }
+
+    test_message :smtp 0;
+
+    if not address :is "to" "tss@iki.fi" {
+        test_fail "to address incorrect (strange forward)";
+    }
+
+    if not address :is "from" "stephan@rename-it.nl" {
+        test_fail "from address incorrect (strange forward)";
+    }
+
+	if not envelope :is "to" "cras@iki.fi" {
+		test_fail "envelope recipient incorrect";
+	}
+
+	if not envelope :is "from" "sirius@rename-it.nl" {
+		test_fail "envelope sender incorrect";
+	}
+}
+
+test_result_reset;
+
+test "Redirect from <>" {
+
+	test_set "envelope.from" "<>";
+
+	redirect "cras@iki.fi";
+
+	if not test_result_execute {
+        test_fail "failed to execute redirect";
+    }
+
+	if envelope :is "from" "sirius@rename-it.nl" {
+        test_fail "envelope sender incorrect (not changed)";
+    }
+
+	if not envelope :is "from" "" {
+        test_fail "envelope sender incorrect";
+    }
+}
diff --git a/tests/extensions/enotify/mailto.svtest b/tests/extensions/enotify/mailto.svtest
index 6abd107ad..fe809f193 100644
--- a/tests/extensions/enotify/mailto.svtest
+++ b/tests/extensions/enotify/mailto.svtest
@@ -1,6 +1,7 @@
 require "vnd.dovecot.testsuite";
 require "enotify";
 require "relational";
+require "envelope";
 require "comparator-i;ascii-numeric";
 
 /*
@@ -160,3 +161,142 @@ test "Notifying on automated messages" {
 	}
 }
 
+/*
+ * Envelope
+ */
+
+test_set "message" text:
+From: stephan@rename-it.nl
+To: nico@vestingbar.nl
+Subject: Frop!
+
+Klutsefluts.
+.
+;
+
+test_result_reset;
+
+test_set "envelope.from" "sirius@rename-it.nl";
+test_set "envelope.to" "bertus@vestingbar.nl";
+
+test "Envelope" {
+	notify "mailto:stephan@rename-it.nl?cc=timo@example.com";
+
+	if not test_result_execute {
+		test_fail "failed to execute notify";
+	}
+
+	test_message :smtp 0;
+
+	if not envelope :localpart :is "from" "postmaster" {
+		test_fail "envelope sender set incorrectly";
+	}
+
+	if not envelope :is "to" "stephan@rename-it.nl" {
+		test_fail "envelope sender set incorrectly";
+	}
+
+	test_message :smtp 1;
+
+	if not envelope :localpart :is "from" "postmaster" {
+		test_fail "envelope sender set incorrectly";
+	}
+
+	if not envelope :is "to" "timo@example.com" {
+		test_fail "envelope sender set incorrectly";
+	}	
+}
+
+/* 
+ * Envelope :from 
+ */
+
+test_set "message" text:
+From: stephan@rename-it.nl
+To: nico@vestingbar.nl
+Subject: Frop!
+
+Klutsefluts.
+.
+;
+
+test_set "envelope.from" "sirius@rename-it.nl";
+test_set "envelope.to" "bertus@vestingbar.nl";
+
+test_result_reset;
+
+test "Envelope :from" {
+	notify :from "nico@vestingbar.nl"
+		"mailto:stephan@rename-it.nl?cc=timo@example.com";
+
+	if not test_result_execute {
+		test_fail "failed to execute notify";
+	}
+
+	test_message :smtp 0;
+
+	if not envelope :is "from" "nico@vestingbar.nl" {
+		test_fail "envelope sender set incorrectly";
+	}
+
+	if not envelope :is "to" "stephan@rename-it.nl" {
+		test_fail "envelope sender set incorrectly";
+	}
+
+	test_message :smtp 1;
+
+	if not envelope :is "from" "nico@vestingbar.nl" {
+		test_fail "envelope sender set incorrectly";
+	}
+
+	if not envelope :is "to" "timo@example.com" {
+		test_fail "envelope sender set incorrectly";
+	}	
+}
+
+/* 
+ * Envelope <> 
+ */
+
+test_set "message" text:
+From: stephan@rename-it.nl
+To: nico@vestingbar.nl
+Subject: Frop!
+
+Klutsefluts.
+.
+;
+
+test_set "envelope.from" "<>";
+test_set "envelope.to" "bertus@vestingbar.nl";
+
+test_result_reset;
+
+test "Envelope <>" {
+	notify :from "nico@vestingbar.nl"
+		"mailto:stephan@rename-it.nl?cc=timo@example.com";
+
+	if not test_result_execute {
+		test_fail "failed to execute notify";
+	}
+
+	test_message :smtp 0;
+
+	if not envelope :is "from" "" {
+		test_fail "envelope sender set incorrectly";
+	}
+
+	if not envelope :is "to" "stephan@rename-it.nl" {
+		test_fail "envelope sender set incorrectly";
+	}
+
+	test_message :smtp 1;
+
+	if not envelope :is "from" "" {
+		test_fail "envelope sender set incorrectly";
+	}
+
+	if not envelope :is "to" "timo@example.com" {
+		test_fail "envelope sender set incorrectly";
+	}	
+}
diff --git a/tests/extensions/reject/smtp.svtest b/tests/extensions/reject/smtp.svtest
new file mode 100644
index 000000000..6548bc3d9
--- /dev/null
+++ b/tests/extensions/reject/smtp.svtest
@@ -0,0 +1,56 @@
+require "vnd.dovecot.testsuite";
+require "envelope";
+require "reject";
+
+test_set "message" text:
+From: stephan@rename-it.nl
+To: tss@iki.fi
+Subject: Frop!
+
+Frop!
+.
+;
+
+test_set "envelope.from" "sirius@rename-it.nl";
+test_set "envelope.to" "timo@iki.fi";
+
+test "Basic" {
+	reject "I don't want your mail";
+
+	if not test_result_execute {
+        test_fail "failed to execute reject";
+    }
+
+    test_message :smtp 0;
+
+    if not address :is "to" "sirius@rename-it.nl" {
+        test_fail "to address incorrect";
+    }
+
+    if not header :contains "from" "Mail Delivery Subsystem" {
+        test_fail "from address incorrect";
+    }
+
+	if not envelope :is "to" "sirius@rename-it.nl" {
+		test_fail "envelope recipient incorrect";
+	}
+
+	if not envelope :is "from" "" {
+		test_fail "envelope sender not null";
+	}
+}
+
+test_result_reset;
+test_set "envelope.from" "<>";
+
+test "Null Sender" {
+	reject "I don't want your mail";
+
+	if not test_result_execute {
+		test_fail "failed to execute reject";
+	}
+
+	if test_message :smtp 0 {
+		test_fail "reject sent message to NULL sender";
+	}
+}
diff --git a/tests/extensions/vacation/smtp.svtest b/tests/extensions/vacation/smtp.svtest
new file mode 100644
index 000000000..a06e4aae8
--- /dev/null
+++ b/tests/extensions/vacation/smtp.svtest
@@ -0,0 +1,56 @@
+require "vnd.dovecot.testsuite";
+require "envelope";
+require "vacation";
+
+test_set "message" text:
+From: stephan@rename-it.nl
+To: tss@iki.fi
+Subject: Frop!
+
+Frop!
+.
+;
+
+test_set "envelope.from" "sirius@rename-it.nl";
+test_set "envelope.to" "timo@iki.fi";
+
+test "Basic" {
+	vacation :addresses "tss@iki.fi" :from "Timo Sirainen <tss@iki.fi>" "I am gone";
+
+	if not test_result_execute {
+        test_fail "failed to execute vacation";
+    }
+
+    test_message :smtp 0;
+
+    if not address :is "to" "sirius@rename-it.nl" {
+        test_fail "to address incorrect";
+    }
+
+    if not address :is "from" "tss@iki.fi" {
+        test_fail "from address incorrect";
+    }
+
+	if not envelope :is "to" "sirius@rename-it.nl" {
+		test_fail "envelope recipient incorrect";
+	}
+
+	if not envelope :is "from" "" {
+		test_fail "envelope sender not null";
+	}
+}
+
+test_result_reset;
+test_set "envelope.from" "<>";
+
+test "Null Sender" {
+	vacation :addresses "tss@iki.fi" "I am gone";
+
+	if not test_result_execute {
+		test_fail "failed to execute vacation";
+	}
+
+	if test_message :smtp 0 {
+		test_fail "reject sent message to NULL sender";
+	}
+}
-- 
GitLab