1require "vnd.dovecot.testsuite";
2require "vnd.dovecot.report";
3require "relational";
4require "comparator-i;ascii-numeric";
5require "body";
6require "variables";
7
8/*
9 * Simple test
10 */
11
12test_set "message" text:
13From: stephan@example.org
14To: nico@frop.example.org
15Subject: Frop!
16
17Klutsefluts.
18.
19;
20
21test "Simple" {
22	report "abuse" "This message is spam!" "abuse@example.com";
23
24	if not test_result_execute {
25		test_fail "failed to execute notify";
26	}
27
28	test_message :smtp 0;
29
30	if not body :raw :contains "This message is spam!" {
31		test_fail "report does not contain user text";
32	}
33
34	if not body :raw :contains "Klutsefluts" {
35		test_fail "report does not contain message body";
36	}
37}
38
39/*
40 * Simple - :headers_only test
41 */
42
43test_result_reset;
44
45test_set "message" text:
46From: stephan@example.org
47To: nico@frop.example.org
48Subject: Frop!
49
50Klutsefluts.
51.
52;
53
54test "Simple - :headers_only" {
55	report :headers_only "abuse"
56		"This message is spam!" "abuse@example.com";
57
58	if not test_result_execute {
59		test_fail "failed to execute notify";
60	}
61
62	test_message :smtp 0;
63
64	if not body :raw :contains "This message is spam!" {
65		test_fail "report does not contain user text";
66	}
67
68	if body :raw :contains "Klutsefluts" {
69		test_fail "report contains message body";
70	}
71}
72
73/*
74 * Configuration
75 */
76
77set "message" text:
78From: stephan@example.org
79To: nico@frop.example.org
80Subject: Frop!
81
82Klutsefluts.
83.
84;
85
86/* default */
87
88test_set "message" "${message}";
89test_set "envelope.from" "from@example.com";
90test_set "envelope.to" "to@example.com";
91test_set "envelope.orig_to" "orig_to@example.com";
92
93test_result_reset;
94
95test "Configuration - from default" {
96	report "abuse" "This message is spam!" "abuse@example.com";
97
98	if not test_result_execute {
99		test_fail "failed to execute notify";
100	}
101
102	test_message :smtp 0;
103
104	if not address :localpart "from" "postmaster" {
105		test_fail "not sent from postmaster";
106	}
107}
108
109/* from sender */
110
111test_set "message" "${message}";
112test_set "envelope.from" "from@example.com";
113test_set "envelope.to" "to@example.com";
114test_set "envelope.orig_to" "orig_to@example.com";
115
116test_config_set "sieve_report_from" "sender";
117test_config_reload :extension "vnd.dovecot.report";
118test_result_reset;
119
120test "Configuration - from sender" {
121	report "abuse" "This message is spam!" "abuse@example.com";
122
123	if not test_result_execute {
124		test_fail "failed to execute notify";
125	}
126
127	test_message :smtp 0;
128
129	if not address :localpart "from" "from" {
130		test_fail "not sent from sender";
131	}
132}
133
134/* from recipient */
135
136test_set "message" "${message}";
137test_set "envelope.from" "from@example.com";
138test_set "envelope.to" "to@example.com";
139test_set "envelope.orig_to" "orig_to@example.com";
140
141test_config_set "sieve_report_from" "recipient";
142test_config_reload :extension "vnd.dovecot.report";
143test_result_reset;
144
145test "Configuration - from recipient" {
146	report "abuse" "This message is spam!" "abuse@example.com";
147
148	if not test_result_execute {
149		test_fail "failed to execute notify";
150	}
151
152	test_message :smtp 0;
153
154	if not address :localpart "from" "to" {
155		test_fail "not sent from recipient";
156	}
157}
158
159/* from original recipient */
160
161test_set "message" "${message}";
162test_set "envelope.from" "from@example.com";
163test_set "envelope.to" "to@example.com";
164test_set "envelope.orig_to" "orig_to@example.com";
165
166test_config_set "sieve_report_from" "orig_recipient";
167test_config_reload :extension "vnd.dovecot.report";
168test_result_reset;
169
170test "Configuration - from original recipient" {
171	report "abuse" "This message is spam!" "abuse@example.com";
172
173	if not test_result_execute {
174		test_fail "failed to execute notify";
175	}
176
177	test_message :smtp 0;
178
179	if not address :localpart "from" "orig_to" {
180		test_fail "not sent from original recipient";
181	}
182}
183
184/* from user email */
185
186test_set "message" "${message}";
187test_set "envelope.from" "from@example.com";
188test_set "envelope.to" "to@example.com";
189test_set "envelope.orig_to" "orig_to@example.com";
190
191test_config_set "sieve_report_from" "user_email";
192test_config_set "sieve_user_email" "user@example.com";
193test_config_reload;
194test_config_reload :extension "vnd.dovecot.report";
195test_result_reset;
196
197test "Configuration - from user email" {
198	report "abuse" "This message is spam!" "abuse@example.com";
199
200	if not test_result_execute {
201		test_fail "failed to execute notify";
202	}
203
204	test_message :smtp 0;
205
206	if not address :localpart "from" "user" {
207		test_fail "not sent from user email";
208	}
209}
210
211/* explicit */
212
213test_set "message" "${message}";
214test_set "envelope.from" "from@example.com";
215test_set "envelope.to" "to@example.com";
216test_set "envelope.orig_to" "orig_to@example.com";
217
218test_config_set "sieve_report_from" "<frop@example.com>";
219test_config_reload :extension "vnd.dovecot.report";
220test_result_reset;
221
222test "Configuration - explicit" {
223	report "abuse" "This message is spam!" "abuse@example.com";
224
225	if not test_result_execute {
226		test_fail "failed to execute notify";
227	}
228
229	test_message :smtp 0;
230
231	if not address :localpart "from" "frop" {
232		test_fail "not sent from explicit address";
233	}
234}
235
236/*
237 * Reporting-User
238 */
239
240/* sieve_user_email */
241
242test_set "message" text:
243From: stephan@example.org
244To: nico@frop.example.org
245Subject: Frop!
246
247Klutsefluts.
248.
249;
250
251test_set "envelope.orig_to" "orig_to@example.com";
252
253test_config_set "sieve_user_email" "newuser@example.com";
254test_config_reload;
255test_result_reset;
256
257test "Reporting-User - sieve_user_email" {
258	report "abuse" "This message is spam!" "abuse@example.com";
259
260	if not test_result_execute {
261		test_fail "failed to execute notify";
262	}
263
264	test_message :smtp 0;
265
266	if not body :raw :contains "Dovecot-Reporting-User: <newuser@example.com>" {
267		test_fail "Reporting-User field is wrong.";
268	}
269}