File: envelope.svtest

package info (click to toggle)
dovecot 1%3A2.2.13-12~deb8u4
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 38,792 kB
  • sloc: ansic: 341,472; sh: 16,920; makefile: 5,393; cpp: 1,474; perl: 265; xml: 44; python: 34; pascal: 27
file content (246 lines) | stat: -rw-r--r-- 7,197 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
require "vnd.dovecot.testsuite";

require "envelope";

/*
 * Empty envelope addresses
 */

/* RFC 5228, Section 5.4: The null reverse-path is matched against as the empty
 * string, regardless of the ADDRESS-PART argument specified.
 */

test "Envelope - from empty" {
	/* Return_path: "" */

	test_set "envelope.from" "";

	if not envelope :all :is "from" "" {
		test_fail "failed to (:all :is)-match a \"\" return path";
	}

	if not envelope :all :contains "from" "" {
		test_fail "failed to (:all :contains)-match a \"\" return path";
	}

	if not envelope :domain :is "from" "" {
		test_fail "failed to (:domain :is)-match a \"\" return path";
	}

	if not envelope :domain :contains "from" "" {
		test_fail "failed to (:domain :contains)-match a \"\" return path";
	}

	/* Return path: <> */

	test_set "envelope.from" "<>";

	if not envelope :all :is "from" "" {
		test_fail "failed to (:all :is)-match a <> return path";
	}

	if not envelope :all :contains "from" "" {
		test_fail "failed to (:all :contains)-match a <> return path";
	}

	if not envelope :domain :is "from" "" {
		test_fail "failed to (:domain :is)-match a <> return path";
	}

	if not envelope :domain :contains "from" "" {
		test_fail "failed to (:domain :contains)-match a <> return path";
	}

	if envelope :all :is "from" "nico@frop.example.org" {
		test_fail "envelope test matches nonsense";
	}

	/* Forward path: <> */

	test_set "envelope.to" "<>";

	if envelope :all :is "to" "" {
		test_fail "successfully matched a <> forward path, which is wrong";
	}
}

/*
 * Invalid envelope addresses
 */

test "Envelope - invalid paths" {
	/* Return_path: "hutsefluts" */

	test_set "envelope.from" "hutsefluts@";
	test_set "envelope.to" "knurft@";

	if not envelope :all :is "from" "hutsefluts@" {
		test_fail ":all address part mangled syntactically incorrect reverse path";
	}

	if envelope :localpart :is "from" "hutsefluts" {
		test_fail ":localpart address part matched syntactically incorrect reverse path";
	}

	if envelope :domain :contains "from" "" {
		test_fail ":domain address part matched syntactically incorrect reverse path";
	}

	if not envelope :all :is "to" "knurft@" {
		test_fail ":all address part mangled syntactically incorrect forward path";
	}

	if envelope :localpart :is "to" "knurft" {
		test_fail ":localpart address part matched syntactically incorrect forward path";
	}

	if envelope :domain :contains "to" "" {
		test_fail ":domain address part matched syntactically incorrect forward path";
	}
}

/*
 * Syntax errors
 */

test "Envelope - syntax errors" {
	/* Control */
	test_set "envelope.from" "<stephan@example.org>";
	if not envelope :all :is "from" "stephan@example.org" {
		test_fail "correct control test failed";
	}

	# Duplicate <
	test_set "envelope.from" "<<stephan@example.org>";
	if envelope :all :is "from" "stephan@example.org" {
		test_fail "failed to recognize syntax error (1)";
	}

	# Spurious >
	test_set "envelope.from" "stephan@example.org>";
	if envelope :all :is "from" "stephan@example.org" {
		test_fail "failed to recognize syntax error (2)";
	}

	# Missing >
	test_set "envelope.from" "<stephan@example.org";
	if envelope :all :is "from" "stephan@example.org" {
		test_fail "failed to recognize syntax error (3)";
	}

	# No @
	test_set "envelope.from" "<stephan example.org>";
	if envelope :domain :contains "from" "" {
		test_fail "failed to recognize syntax error (4)";
	}

	# Duplicate @
	test_set "envelope.from" "<stephan@@example.org>";
	if envelope :domain :contains "from" "" {
		test_fail "failed to recognize syntax error (5)";
	}
}

/*
 * Ignoring source routes
 */

test "Envelope - source route" {
	/* Single */
	test_set "envelope.from" "<@cola.example.org:stephan@example.org>";
	if not envelope :localpart :is "from" "stephan" {
		test_fail "parsing path with source route (single) failed";
	}

	/* Dual */
	test_set "envelope.from" "<@cola.example.org,@mx.utwente.nl:stephan@example.org>";
	if not envelope :localpart :is "from" "stephan" {
		test_fail "parsing path with source route (dual) failed";
	}

	/* Multiple */
	test_set "envelope.from" "<@cola.example.org,@mx.utwente.nl,@smtp.example.net:stephan@example.org>";
	if not envelope :localpart :is "from" "stephan" {
		test_fail "parsing path with source route (multiple) failed";
	}

	/* Bare */
	test_set "envelope.from" "@cola.example.org,@mx.utwente.nl,@smtp.example.net:stephan@example.org";
	if not envelope :domain :is "from" "example.org" {
		test_fail "parsing path with source route (bare) failed";
	}

	/* Whitespace */
	test_set "envelope.from" "   < @ cola . example . org , @ mx . utwente .   nl , 	@ smtp  .  iki  . fi	:   stephan		@     example   .		org >  ";
	if not envelope :domain :is "from" "example.org" {
		test_fail "parsing path with source route (whitespace) failed";
	}
}

test "Envelope - source route errors" {
	test_set "envelope.to" "<cola.example.org:stephan@example.org>";
	if envelope :domain :contains "to" "" {
		test_fail "parsing syntactically incorrect path should have failed (1)";
	}

	test_set "envelope.to" "<@.example.org:stephan@example.org>";
	if envelope :domain :contains "to" "" {
		test_fail "parsing syntactically incorrect path should have failed (2)";
	}

	test_set "envelope.to" "<@cola..nl:stephan@example.org>";
	if envelope :domain :contains "to" "" {
		test_fail "parsing syntactically incorrect path should have failed (3)";
	}

	test_set "envelope.to" "<@cola.example.orgstephan@example.org>";
	if envelope :domain :contains "to" "" {
		test_fail "parsing syntactically incorrect path should have failed (4)";
	}

	test_set "envelope.to" "<@cola.example.org@mx.utwente.nl:stephan@example.org>";
	if envelope :domain :contains "to" "" {
		test_fail "parsing syntactically incorrect path should have failed (5)";
	}

	test_set "envelope.to" "<@cola.example.org,mx.utwente.nl:stephan@example.org>";
	if envelope :domain :contains "to" "" {
		test_fail "parsing syntactically incorrect path should have failed (6)";
	}

	test_set "envelope.to" "<@cola.example.org,@mx.utwente.nl,stephan@example.org>";
	if envelope :domain :contains "to" "" {
		test_fail "parsing syntactically incorrect path should have failed (7)";
	}

	if not envelope :all :is "to" "<@cola.example.org,@mx.utwente.nl,stephan@example.org>" {
		test_fail ":all address part mangled syntactically incorrect path";
	}
}

test "Envelope - local part only" {
	test_set "envelope.to" "<MAILER-DAEMON>";
	if not envelope :is "to" "MAILER-DAEMON" {
		test_fail "failed to parse local_part only path";
	}

	test_set "envelope.to" "MAILER-DAEMON@";
	if envelope :is "to" "MAILER-DAEMON" {
		test_fail "parsing syntactically incorrect path with missing domain";
	}

	test_set "envelope.to" "<MAILER-DAEMON>";
	if not envelope :is "to" "MAILER-DAEMON" {
		test_fail "failed to parse local_part only path with angle brackets";
	}

	test_set "envelope.to" "<MAILER-DAEMON  >";
	if not envelope :is "to" "MAILER-DAEMON" {
		test_fail "failed to parse local_part only path with angle brackets and whitespace";
	}

	test_set "envelope.to" "   MAILER-DAEMON   ";
	if not envelope :is "to" "MAILER-DAEMON" {
		test_fail "failed to parse local_part only path with whitespace";
	}
}