1require "vnd.dovecot.testsuite";
2require "variables";
3
4require "relational";
5require "comparator-i;ascii-numeric";
6
7/*
8 * Command syntax
9 */
10
11test "Command syntax" {
12        if test_script_compile "errors/syntax.sieve" {
13                test_fail "compile should have failed";
14        }
15
16        if not test_error :count "eq" :comparator "i;ascii-numeric" "8" {
17                test_fail "wrong number of errors reported";
18        }
19}
20
21/* Unknown program */
22
23test_set "message" text:
24From: stephan@example.com
25To: pipe@example.net
26Subject: Frop!
27
28Frop!
29.
30;
31
32test_config_set "sieve_pipe_bin_dir" "${tst.path}/../bin";
33test_config_reload :extension "vnd.dovecot.pipe";
34test_result_reset;
35
36test "Unknown program" {
37	if not test_script_compile "errors/unknown-program.sieve" {
38		test_fail "compile failed";
39	}
40
41	if not test_script_run {
42		test_fail "execute failed";
43	}
44
45	if test_result_execute {
46		test_fail "pipe should have failed";
47	}
48
49	if not test_error :count "eq" :comparator "i;ascii-numeric" "1" {
50		test_fail "wrong number of errors reported";
51	}
52
53	if not test_error :index 1 :contains "failed to pipe" {
54		test_fail "wrong error reported";
55	}
56}
57
58/* Timeout */
59
60test_set "message" text:
61From: stephan@example.com
62To: pipe@example.net
63Subject: Frop!
64
65Frop!
66.
67;
68
69test_config_set "sieve_pipe_bin_dir" "${tst.path}/../bin";
70test_config_set "sieve_pipe_exec_timeout" "1s";
71test_config_reload :extension "vnd.dovecot.pipe";
72test_result_reset;
73
74test "Timeout" {
75	if not test_script_compile "errors/timeout.sieve" {
76		test_fail "compile failed";
77	}
78
79	if not test_script_run {
80		test_fail "execute failed";
81	}
82
83	if test_result_execute {
84		test_fail "pipe should have timed out";
85	}
86
87	if not test_error :count "eq" :comparator "i;ascii-numeric" "2" {
88		test_fail "wrong number of errors reported";
89	}
90
91	if not test_error :index 2 :contains "failed to pipe" {
92		test_fail "wrong error reported";
93	}
94}
95