summaryrefslogtreecommitdiffstats
path: root/pigeonhole/tests/plugins/extprograms/execute
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
commitf7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch)
treea3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /pigeonhole/tests/plugins/extprograms/execute
parentInitial commit. (diff)
downloaddovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.tar.xz
dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.zip
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pigeonhole/tests/plugins/extprograms/execute')
-rw-r--r--pigeonhole/tests/plugins/extprograms/execute/command.svtest27
-rw-r--r--pigeonhole/tests/plugins/extprograms/execute/errors.svtest53
-rw-r--r--pigeonhole/tests/plugins/extprograms/execute/errors/syntax.sieve38
-rw-r--r--pigeonhole/tests/plugins/extprograms/execute/errors/unknown-program.sieve3
-rw-r--r--pigeonhole/tests/plugins/extprograms/execute/errors/variables.sieve7
-rw-r--r--pigeonhole/tests/plugins/extprograms/execute/execute.svtest177
6 files changed, 305 insertions, 0 deletions
diff --git a/pigeonhole/tests/plugins/extprograms/execute/command.svtest b/pigeonhole/tests/plugins/extprograms/execute/command.svtest
new file mode 100644
index 0000000..92c1fd1
--- /dev/null
+++ b/pigeonhole/tests/plugins/extprograms/execute/command.svtest
@@ -0,0 +1,27 @@
+require "vnd.dovecot.testsuite";
+require "vnd.dovecot.execute";
+require "variables";
+
+test_config_set "sieve_execute_bin_dir" "${tst.path}/../bin";
+test_config_reload :extension "vnd.dovecot.execute";
+
+test "Basic" {
+ execute "program";
+}
+
+test "Input message" {
+ execute :pipe "program";
+}
+
+test "Input string" {
+ execute :input "DATA" "program";
+}
+
+test "Input variable" {
+ set "DATA" "DATA";
+ execute :input "${DATA}" "program";
+}
+
+test "Output variable" {
+ execute :output "DATA" "program";
+}
diff --git a/pigeonhole/tests/plugins/extprograms/execute/errors.svtest b/pigeonhole/tests/plugins/extprograms/execute/errors.svtest
new file mode 100644
index 0000000..3dd2d5f
--- /dev/null
+++ b/pigeonhole/tests/plugins/extprograms/execute/errors.svtest
@@ -0,0 +1,53 @@
+require "vnd.dovecot.testsuite";
+
+require "relational";
+require "comparator-i;ascii-numeric";
+
+test_config_set "sieve_execute_bin_dir" "${tst.path}/../bin";
+test_config_reload :extension "vnd.dovecot.execute";
+
+/*
+ * Command syntax
+ */
+
+test "Command syntax" {
+ if test_script_compile "errors/syntax.sieve" {
+ test_fail "compile should have failed";
+ }
+
+ if not test_error :count "eq" :comparator "i;ascii-numeric" "13" {
+ test_fail "wrong number of errors reported";
+ }
+}
+
+/*
+ * Variables
+ */
+
+test "Variables" {
+ if test_script_compile "errors/variables.sieve" {
+ test_fail "compile should have failed";
+ }
+
+ if not test_error :count "eq" :comparator "i;ascii-numeric" "2" {
+ test_fail "wrong number of errors reported";
+ }
+}
+
+/*
+ * Unknown program
+ */
+
+test "Unknown program" {
+ if not test_script_compile "errors/unknown-program.sieve" {
+ test_fail "compile should have succeeded";
+ }
+
+ if test_script_run {
+ test_fail "execution should have failed";
+ }
+
+ if not test_error :count "eq" :comparator "i;ascii-numeric" "1" {
+ test_fail "wrong number of errors reported";
+ }
+}
diff --git a/pigeonhole/tests/plugins/extprograms/execute/errors/syntax.sieve b/pigeonhole/tests/plugins/extprograms/execute/errors/syntax.sieve
new file mode 100644
index 0000000..1f4646a
--- /dev/null
+++ b/pigeonhole/tests/plugins/extprograms/execute/errors/syntax.sieve
@@ -0,0 +1,38 @@
+require "vnd.dovecot.execute";
+
+# 1: error: no arguments
+execute;
+
+# 2: error: numeric argument
+execute 1;
+
+# 3: error: tag argument
+execute :frop;
+
+# 4: error: numeric second argument
+execute "sdfd" 1;
+
+# 5: error: stringlist first argument
+execute ["sdfd","werwe"] "sdfs";
+
+# 6: error: too many arguments
+execute "sdfs" "sdfd" "werwe";
+
+# 7: error: inappropriate :copy argument
+execute :copy "234234" ["324234", "23423"];
+
+# 8: error: invalid :input argument; missing parameter
+execute :input "frop";
+
+# 9: error: invalid :input argument; invalid parameter
+execute :input 1 "frop";
+
+# 10: error: invalid :input argument; invalid parameter
+execute :input ["23423","21342"] "frop";
+
+# 11: error: invalid :input argument; invalid parameter
+execute :input :friep "frop";
+
+# 12: error: :output not allowed without variables extension
+execute :output "${frop}" "frop";
+
diff --git a/pigeonhole/tests/plugins/extprograms/execute/errors/unknown-program.sieve b/pigeonhole/tests/plugins/extprograms/execute/errors/unknown-program.sieve
new file mode 100644
index 0000000..3a79bb6
--- /dev/null
+++ b/pigeonhole/tests/plugins/extprograms/execute/errors/unknown-program.sieve
@@ -0,0 +1,3 @@
+require "vnd.dovecot.execute";
+
+execute "unknown";
diff --git a/pigeonhole/tests/plugins/extprograms/execute/errors/variables.sieve b/pigeonhole/tests/plugins/extprograms/execute/errors/variables.sieve
new file mode 100644
index 0000000..3d0b3e7
--- /dev/null
+++ b/pigeonhole/tests/plugins/extprograms/execute/errors/variables.sieve
@@ -0,0 +1,7 @@
+require "vnd.dovecot.execute";
+require "variables";
+
+# 1: invalid variable name
+execute :output "wqwe-aeqwe" "frop";
+
+
diff --git a/pigeonhole/tests/plugins/extprograms/execute/execute.svtest b/pigeonhole/tests/plugins/extprograms/execute/execute.svtest
new file mode 100644
index 0000000..f16af11
--- /dev/null
+++ b/pigeonhole/tests/plugins/extprograms/execute/execute.svtest
@@ -0,0 +1,177 @@
+require "vnd.dovecot.testsuite";
+require "vnd.dovecot.execute";
+require "vnd.dovecot.debug";
+require "variables";
+require "relational";
+require "environment";
+require "encoded-character";
+
+test_set "message" text:
+From: stephan@example.com
+To: pipe@example.net
+Subject: Frop!
+
+Frop!
+.
+;
+
+test_config_set "sieve_execute_bin_dir" "${tst.path}/../bin";
+test_config_reload :extension "vnd.dovecot.execute";
+test_result_reset;
+
+test "Execute - bare" {
+ execute "program";
+}
+
+test_result_reset;
+test "Execute - i/-" {
+ execute :input "FROP" "frame";
+}
+
+test_result_reset;
+test "Execute - -/o" {
+ execute :output "out" "frame";
+
+ if not string "${out}" "FRAMED { }" {
+ test_fail "wrong string returned: ${out}";
+ }
+}
+
+test_result_reset;
+test "Execute - i/o" {
+ execute :input "FROP" :output "out" "frame";
+
+ if not string "${out}" "FRAMED { FROP }" {
+ test_fail "wrong string returned: ${out}";
+ }
+}
+
+test_result_reset;
+test "Execute - i/o and arguments" {
+ execute :input "FROP" :output "out" "frame" ["FRIEP "];
+
+ if not string "${out}" "FRAMED FRIEP { FROP }" {
+ test_fail "wrong string returned: ${out}";
+ }
+}
+
+test_result_reset;
+test "Execute - pipe" {
+ execute :pipe :output "msg" "cat";
+
+ if not string :contains "${msg}" "Subject: Frop!" {
+ test_fail "wrong string returned: ${out}";
+ }
+}
+
+test_result_reset;
+test "Execute - pipe /dev/stdin" {
+ execute :pipe :output "msg" "cat-stdin";
+
+ if not string :contains "${msg}" "Subject: Frop!" {
+ test_fail "wrong string returned: ${out}";
+ }
+}
+
+test_result_reset;
+test "Execute - env" {
+ test_set "envelope.from" "stephan@sub.example.com";
+ test_set "envelope.to" "stephan@sub.example.net";
+ test_set "envelope.orig_to" "all@sub.example.net";
+
+ execute :output "out" "env" "SENDER";
+ if not string :is "${out}" "stephan@sub.example.com" {
+ test_fail "wrong SENDER env returned: '${out}'";
+ }
+
+ execute :output "out" "env" "RECIPIENT";
+ if not string :is "${out}" "stephan@sub.example.net" {
+ test_fail "wrong RECIPIENT env returned: '${out}'";
+ }
+
+ execute :output "out" "env" "ORIG_RECIPIENT";
+ if not string :is "${out}" "all@sub.example.net" {
+ test_fail "wrong ORIG_RECIPIENT env returned: '${out}'";
+ }
+
+ execute :output "out" "env" "HOST";
+ if not environment :is "host" "${out}" {
+ test_fail "wrong HOST env returned: '${out}'";
+ }
+
+ execute :output "out" "env" "HOME";
+ if string :count "eq" "${out}" "0" {
+ test_fail "empty HOME env returned";
+ }
+
+ execute :output "out" "env" "USER";
+ if string :count "eq" "${out}" "0" {
+ test_fail "empty USER env returned";
+ }
+}
+
+test_result_reset;
+test "Execute - used as test" {
+ if execute :pipe :output "msg" "dog" {
+ test_fail "execute action indicated success with invalid program";
+ }
+
+ if not execute :pipe :output "msg" "cat" {
+ test_fail "execute action indicated failure with valid program";
+ }
+
+ if not string :contains "${msg}" "Subject: Frop!" {
+ test_fail "wrong string returned: ${out}";
+ }
+}
+
+test_config_set "sieve_execute_input_eol" "crlf";
+test_config_reload :extension "vnd.dovecot.execute";
+test_result_reset;
+set "out" "";
+
+test "Execute - CRLF" {
+ execute
+ :input "FROP${hex:0A}FRIEP${hex:0a}"
+ :output "out"
+ "crlf";
+
+ if not string "${out}" "FROP#${hex:0A}FRIEP#${hex:0a}" {
+ test_fail "wrong string returned: '${out}'";
+ }
+}
+
+test_config_set "sieve_execute_input_eol" "lf";
+test_config_reload :extension "vnd.dovecot.execute";
+test_result_reset;
+set "out" "";
+
+test "Execute - LF" {
+ execute
+ :input "FROP${hex:0D 0A}FRIEP${hex:0d 0a}"
+ :output "out"
+ "crlf";
+
+ if not string "${out}" "FROP${hex:0A}FRIEP${hex:0a}" {
+ test_fail "wrong string returned: '${out}'";
+ }
+}
+
+set "D" "0123456701234567012345670123456701234567012345670123456701234567";
+set "D" "${D}${D}${D}${D}${D}${D}${D}${D}${D}${D}${D}${D}${D}${D}${D}${D}";
+set "data" "${D}${D}";
+
+test_config_set "sieve_execute_input_eol" "crlf";
+test_config_reload :extension "vnd.dovecot.execute";
+test_result_reset;
+set "out" "";
+
+test "Execute - big" {
+ execute
+ :output "out"
+ "big";
+
+ if not string "${out}" "${data}" {
+ test_fail "wrong string returned: '${out}'";
+ }
+}