diff --git a/Makefile.am b/Makefile.am index 7301d367792fcb7081503b9548369b928e49faaa..9657a4de4862fc0f7d958b54c9460ed7b1a7b62d 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 7c1ea07ae963c7d1e7a5e9423087e5f3db7dc7de..edc08bb4c92cb8e6f9161244d8801d5a1a83f45c 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 0000000000000000000000000000000000000000..c45f0814e4e47de47974d6d351a8c148a1e640c4 --- /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 6abd107adf9f55643e7ee366d122c65a4b8d4722..fe809f193faf52d31b0b84f5b3fd3cb3c5b358c8 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 0000000000000000000000000000000000000000..6548bc3d9967b8e2ebccd3b45eac028c2e07eaf6 --- /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 0000000000000000000000000000000000000000..a06e4aae8844c19cf13e5d1bd6457c9a855fd083 --- /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"; + } +}