From fb59caa734b08b055aadee0eac19d391df72828b Mon Sep 17 00:00:00 2001 From: Stephan Bosch <stephan@rename-it.nl> Date: Fri, 17 Jul 2009 21:46:00 +0200 Subject: [PATCH] Testsuite: added tests for deprecated notify extension. --- Makefile.am | 6 +- tests/deprecated/notify/basic.svtest | 11 ++ tests/deprecated/notify/errors.svtest | 13 ++ tests/deprecated/notify/errors/options.sieve | 11 ++ tests/deprecated/notify/execute.svtest | 25 +++ .../notify/execute/duplicates.sieve | 4 + tests/deprecated/notify/mailto.svtest | 155 ++++++++++++++++++ 7 files changed, 224 insertions(+), 1 deletion(-) create mode 100644 tests/deprecated/notify/basic.svtest create mode 100644 tests/deprecated/notify/errors.svtest create mode 100644 tests/deprecated/notify/errors/options.sieve create mode 100644 tests/deprecated/notify/execute.svtest create mode 100644 tests/deprecated/notify/execute/duplicates.sieve create mode 100644 tests/deprecated/notify/mailto.svtest diff --git a/Makefile.am b/Makefile.am index 4da531e06..7301d3677 100644 --- a/Makefile.am +++ b/Makefile.am @@ -85,7 +85,11 @@ test_cases = \ tests/extensions/enotify/mailto.svtest \ tests/extensions/environment/basic.svtest \ tests/extensions/environment/rfc.svtest \ - tests/multiscript/basic.svtest + tests/multiscript/basic.svtest \ + tests/deprecated/notify/basic.svtest \ + tests/deprecated/notify/mailto.svtest \ + tests/deprecated/notify/errors.svtest \ + tests/deprecated/notify/execute.svtest if HAVE_DOVECOT_LIBS diff --git a/tests/deprecated/notify/basic.svtest b/tests/deprecated/notify/basic.svtest new file mode 100644 index 000000000..72eed3682 --- /dev/null +++ b/tests/deprecated/notify/basic.svtest @@ -0,0 +1,11 @@ +require "vnd.dovecot.testsuite"; +require "notify"; + +test "Execute" { + /* Test to catch runtime segfaults */ + notify + :message "This is probably very important" + :low + :method "mailto" + :options ["stephan@example.com", "stephan@rename-it.nl"]; +} diff --git a/tests/deprecated/notify/errors.svtest b/tests/deprecated/notify/errors.svtest new file mode 100644 index 000000000..d1f1325a4 --- /dev/null +++ b/tests/deprecated/notify/errors.svtest @@ -0,0 +1,13 @@ +require "vnd.dovecot.testsuite"; +require "comparator-i;ascii-numeric"; +require "relational"; + +test "Invalid :options argument (FIXME: count only)" { + if test_script_compile "errors/options.sieve" { + test_fail "compile should have failed"; + } + + if not test_error :count "eq" :comparator "i;ascii-numeric" "3" { + test_fail "wrong number of errors reported"; + } +} diff --git a/tests/deprecated/notify/errors/options.sieve b/tests/deprecated/notify/errors/options.sieve new file mode 100644 index 000000000..e93741b39 --- /dev/null +++ b/tests/deprecated/notify/errors/options.sieve @@ -0,0 +1,11 @@ +require "notify"; + +# 1: empty option +notify :options ""; + +# 2: invalid address syntax +notify :options "frop#vestingbar.nl"; + +# Valid +notify :options "frop@vestingbar.nl"; + diff --git a/tests/deprecated/notify/execute.svtest b/tests/deprecated/notify/execute.svtest new file mode 100644 index 000000000..83ca40141 --- /dev/null +++ b/tests/deprecated/notify/execute.svtest @@ -0,0 +1,25 @@ +require "vnd.dovecot.testsuite"; +require "relational"; + + +/* + * Execution testing (currently just meant to trigger any segfaults) + */ + +test "Duplicate recipients" { + if not test_script_compile "execute/duplicates.sieve" { + test_fail "script compile failed"; + } + + if not test_script_run { + test_fail "script execute failed"; + } + + if test_result :count "ne" "2" { + test_fail "second notify action was discarded entirely"; + } + + if not test_result_execute { + test_fail "result execute failed"; + } +} diff --git a/tests/deprecated/notify/execute/duplicates.sieve b/tests/deprecated/notify/execute/duplicates.sieve new file mode 100644 index 000000000..8f185c3fc --- /dev/null +++ b/tests/deprecated/notify/execute/duplicates.sieve @@ -0,0 +1,4 @@ +require "notify"; + +notify :message "Incoming stupidity." :options ["stephan@rename-it.nl", "stephan@drunksnipers.com", "idiot@rename-it.nl"]; +notify :message "There it is." :options ["tss@iki.fi", "stephan@rename-it.nl", "idiot@rename-it.nl", "nico@vestingbar.nl", "stephan@drunksnipers.com"]; diff --git a/tests/deprecated/notify/mailto.svtest b/tests/deprecated/notify/mailto.svtest new file mode 100644 index 000000000..37b83c975 --- /dev/null +++ b/tests/deprecated/notify/mailto.svtest @@ -0,0 +1,155 @@ +require "vnd.dovecot.testsuite"; +require "notify"; +require "relational"; +require "comparator-i;ascii-numeric"; + +/* + * Simple test + */ + +test_set "message" text: +From: stephan@rename-it.nl +To: nico@vestingbar.nl +Subject: Frop! + +Klutsefluts. +. +; + +test "Simple" { + notify :method "mailto" :options "stephan@rename-it.nl"; + + if not test_result_execute { + test_fail "failed to execute notify"; + } + + test_message :smtp 0; + + if not header :matches "Auto-Submitted" "auto-generated*" { + test_fail "auto-submitted header set inappropriately"; + } + + if not exists "X-Sieve" { + test_fail "x-sieve header missing from outgoing message"; + } +} + +/* + * Multiple recipients + */ + +test_result_reset; + +test_set "message" text: +From: stephan@rename-it.nl +To: nico@vestingbar.nl +Subject: Frop! + +Klutsefluts. +. +; + +test "Multiple recipients" { + notify :options ["timo@example.com","stephan@dovecot.org","postmaster@vestingbar.nl"]; + + if not test_result_execute { + test_fail "failed to execute notify"; + } + + test_message :smtp 0; + + if not address :is "to" "timo@example.com" { + test_fail "first To address missing"; + } + + test_message :smtp 1; + + if not address :is "to" "stephan@dovecot.org" { + test_fail "second To address missing"; + } + + if not header :matches "Auto-Submitted" "auto-generated*" { + test_fail "auto-submitted header not found for second message"; + } + + test_message :smtp 2; + + if not address :is "to" "postmaster@vestingbar.nl" { + test_fail "third To address missing"; + } + + if not header :matches "Auto-Submitted" "auto-generated*" { + test_fail "auto-submitted header not found for third message"; + } + + if not address :count "eq" :comparator "i;ascii-numeric" "to" "1" { + test_fail "too many recipients in To header"; + } + + if not address :count "eq" :comparator "i;ascii-numeric" "cc" "0" { + test_fail "too many recipients in Cc header"; + } +} + +/* + * Duplicate recipients + */ + +test_result_reset; + +test_set "message" text: +From: stephan@rename-it.nl +To: nico@vestingbar.nl +Subject: Frop! + +Klutsefluts. +. +; + +test "Duplicate recipients" { + notify :options ["timo@example.com", "stephan@dovecot.org", "stephan@dovecot.org"]; + notify :options ["timo@example.com", "stephan@rename-it.nl"]; + + if not test_result_execute { + test_fail "failed to execute notify"; + } + + test_message :smtp 2; + + if address "To" "stephan@dovecot.org" { + test_fail "duplicate recipient not removed from first message"; + } + + if address "To" "timo@example.com" { + test_fail "duplicate recipient not removed from second message"; + } +} + +/* + * Notifying on automated messages + */ + +test_result_reset; + +test_set "message" text: +From: stephan@rename-it.nl +To: nico@vestingbar.nl +Auto-submitted: auto-notify +Subject: Frop! + +Klutsefluts. +. +; + +test "Notifying on automated messages" { + notify :options "stephan@rename-it.nl"; + + if not test_result_execute { + test_fail "failed to execute notify"; + } + + if test_message :smtp 0 { + test_fail "notified of auto-submitted message"; + } +} + -- GitLab