summaryrefslogtreecommitdiffstats
path: root/pigeonhole/tests/extensions/regex
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:36:47 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:36:47 +0000
commit0441d265f2bb9da249c7abf333f0f771fadb4ab5 (patch)
tree3f3789daa2f6db22da6e55e92bee0062a7d613fe /pigeonhole/tests/extensions/regex
parentInitial commit. (diff)
downloaddovecot-0441d265f2bb9da249c7abf333f0f771fadb4ab5.tar.xz
dovecot-0441d265f2bb9da249c7abf333f0f771fadb4ab5.zip
Adding upstream version 1:2.3.21+dfsg1.upstream/1%2.3.21+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pigeonhole/tests/extensions/regex')
-rw-r--r--pigeonhole/tests/extensions/regex/basic.svtest51
-rw-r--r--pigeonhole/tests/extensions/regex/errors.svtest29
-rw-r--r--pigeonhole/tests/extensions/regex/errors/compile.sieve25
-rw-r--r--pigeonhole/tests/extensions/regex/errors/runtime.sieve9
-rw-r--r--pigeonhole/tests/extensions/regex/match-values.svtest72
5 files changed, 186 insertions, 0 deletions
diff --git a/pigeonhole/tests/extensions/regex/basic.svtest b/pigeonhole/tests/extensions/regex/basic.svtest
new file mode 100644
index 0000000..9417434
--- /dev/null
+++ b/pigeonhole/tests/extensions/regex/basic.svtest
@@ -0,0 +1,51 @@
+require "vnd.dovecot.testsuite";
+
+require "regex";
+require "variables";
+
+test_set "message" text:
+From: stephan+sieve@friep.example.com
+To: tss@example.net, nico@nl.example.com, sirius@fi.example.com
+Subject: Test
+
+Test message.
+.
+;
+
+test "Basic example" {
+ if not address :regex :comparator "i;ascii-casemap" "from" [
+ "stephan(\\+.*)?@it\\.example\\.com",
+ "stephan(\\+.*)?@friep\\.example\\.com"
+ ] {
+ test_fail "failed to match";
+ }
+}
+
+test "No values" {
+ if header :regex "cc" [".*\\.com", ".*\\.nl"] {
+ test_fail "matched inappropriately";
+ }
+}
+
+
+test "More values" {
+ if address :regex "to" [".*\\.uk", ".*\\.nl", ".*\\.tk"] {
+ test_fail "matched inappropriately";
+ }
+
+ if not address :regex "to" [".*\\.uk", ".*\\.nl", ".*\\.tk", ".*fi\\..*"] {
+ test_fail "failed to match last";
+ }
+}
+
+test "Variable regex" {
+ set "regex" "stephan[+](sieve)@friep.example.com";
+
+ if not header :regex "from" "${regex}" {
+ test_fail "failed to match variable regex";
+ }
+
+ if not string "${1}" "sieve" {
+ test_fail "failed to extract proper match value from variable regex";
+ }
+}
diff --git a/pigeonhole/tests/extensions/regex/errors.svtest b/pigeonhole/tests/extensions/regex/errors.svtest
new file mode 100644
index 0000000..2e0ebe0
--- /dev/null
+++ b/pigeonhole/tests/extensions/regex/errors.svtest
@@ -0,0 +1,29 @@
+require "vnd.dovecot.testsuite";
+
+require "relational";
+require "comparator-i;ascii-numeric";
+
+test "Compile errors" {
+ if test_script_compile "errors/compile.sieve" {
+ test_fail "compile should have failed";
+ }
+
+ if not test_error :count "eq" :comparator "i;ascii-numeric" "5" {
+ test_fail "wrong number of errors reported";
+ }
+}
+
+test "Runtime errors" {
+ if not test_script_compile "errors/runtime.sieve" {
+ test_fail "failed to compile";
+ }
+
+ if not test_script_run {
+ test_fail "script should have run fine";
+ }
+
+ if not test_error :count "eq" :comparator "i;ascii-numeric" "1" {
+ test_fail "wrong number of errors reported";
+ }
+}
+
diff --git a/pigeonhole/tests/extensions/regex/errors/compile.sieve b/pigeonhole/tests/extensions/regex/errors/compile.sieve
new file mode 100644
index 0000000..5ddaaf8
--- /dev/null
+++ b/pigeonhole/tests/extensions/regex/errors/compile.sieve
@@ -0,0 +1,25 @@
+require "regex";
+require "comparator-i;ascii-numeric";
+require "envelope";
+
+if address :regex :comparator "i;ascii-numeric" "from" "sirius(\\+.*)?@friep\\.example\\.com" {
+ keep;
+ stop;
+}
+
+if address :regex "from" "sirius(+\\+.*)?@friep\\.example\\.com" {
+ keep;
+ stop;
+}
+
+if header :regex "from" "sirius(\\+.*)?@friep\\.ex[]ample.com" {
+ keep;
+ stop;
+}
+
+if envelope :regex "from" "sirius(\\+.*)?@friep\\.ex[]ample.com" {
+ keep;
+ stop;
+}
+
+discard;
diff --git a/pigeonhole/tests/extensions/regex/errors/runtime.sieve b/pigeonhole/tests/extensions/regex/errors/runtime.sieve
new file mode 100644
index 0000000..2d0bf66
--- /dev/null
+++ b/pigeonhole/tests/extensions/regex/errors/runtime.sieve
@@ -0,0 +1,9 @@
+require "regex";
+require "variables";
+require "fileinto";
+
+set "regex" "[";
+
+if header :regex "to" "${regex}" {
+ fileinto "frop";
+}
diff --git a/pigeonhole/tests/extensions/regex/match-values.svtest b/pigeonhole/tests/extensions/regex/match-values.svtest
new file mode 100644
index 0000000..18b7404
--- /dev/null
+++ b/pigeonhole/tests/extensions/regex/match-values.svtest
@@ -0,0 +1,72 @@
+require "vnd.dovecot.testsuite";
+
+require "regex";
+require "variables";
+
+test_set "message" text:
+From: Andy Howell <AndyHowell@example.com>
+Sender: antlr-interest-bounces@ant.example.com
+To: Stephan Bosch <stephan@example.org>
+Subject: [Dovecot] Sieve regex match problem
+
+Hi,
+
+I is broken.
+.
+;
+
+test "Basic match values 1" {
+ if header :regex ["Sender"] ["([^-@]*)-([^-@]*)(-bounces)?@ant.example.com"] {
+
+ if not string :is "${1}" "antlr" {
+ test_fail "first match value is not correct";
+ }
+
+ if not string :is "${2}" "interest" {
+ test_fail "second match value is not correct";
+ }
+
+ if not string :is "${3}" "-bounces" {
+ test_fail "third match value is not correct";
+ }
+
+ if string :is "${4}" "-bounces" {
+ test_fail "fourth match contains third value";
+ }
+ } else {
+ test_fail "failed to match";
+ }
+}
+
+test "Basic match values 2" {
+ if header :regex ["Sender"] ["(.*>[ \\t]*,?[ \\t]*)?([^-@]*)-([^-@]*)(-bounces)?@ant.example.com"] {
+
+ if not string :is "${1}" "" {
+ test_fail "first match value is not correct: ${1}";
+ }
+
+ if not string :is "${2}" "antlr" {
+ test_fail "second match value is not correct: ${2}";
+ }
+
+ if not string :is "${3}" "interest" {
+ test_fail "third match value is not correct: ${3}";
+ }
+
+ if not string :is "${4}" "-bounces" {
+ test_fail "fourth match value is not correct: ${4}";
+ }
+
+ if string :is "${5}" "-bounces" {
+ test_fail "fifth match contains fourth value: ${5}";
+ }
+ } else {
+ test_fail "failed to match";
+ }
+}
+
+
+
+
+
+