@@ -10,6 +10,22 @@ local os = require('os')
10
10
test :plan (1 )
11
11
mails = fiber .channel (100 )
12
12
13
+ function write_reply_code (s , l )
14
+ if l :find (' 3xx' ) then
15
+ s :write (' 354 Start mail input\r\n ' )
16
+ elseif l :find (' 4xx' ) then
17
+ s :write (' 421 Service not available, closing transmission channel\r\n ' )
18
+ elseif l :find (' 5xx' ) then
19
+ s :write (' 510 Bad email address\r\n ' )
20
+ elseif l :find (' breakconnect' ) then
21
+ s :write (' Breaking connection\r\n ' )
22
+ return - 1
23
+ else
24
+ s :write (' 250 OK\r\n ' )
25
+ end
26
+ return 1
27
+ end
28
+
13
29
local function smtp_h (s )
14
30
s :write (' 220 localhost ESMTP Tarantool\r\n ' )
15
31
local l
@@ -26,10 +42,14 @@ local function smtp_h(s)
26
42
s :write (' 250 HELP\r\n ' )
27
43
elseif l :find (' MAIL FROM:' ) then
28
44
mail .from = l :sub (11 ):sub (1 , - 3 )
29
- s :write (' 250 OK\r\n ' )
45
+ if write_reply_code (s , l ) == - 1 then
46
+ return
47
+ end
30
48
elseif l :find (' RCPT TO:' ) then
31
49
mail .rcpt [# mail .rcpt + 1 ] = l :sub (9 ):sub (1 , - 3 )
32
- s :write (' 250 OK\r\n ' )
50
+ if write_reply_code (s , l ) == - 1 then
51
+ return
52
+ end
33
53
elseif l == ' DATA\r\n ' then
34
54
s :write (' 354 Enter message, ending with "." on a line by itself\r\n ' )
35
55
while true do
@@ -56,7 +76,7 @@ local server = socket.tcp_server('127.0.0.1', 0, smtp_h)
56
76
local addr = ' smtp://127.0.0.1:' .. server :name ().port
57
77
58
78
test :test (" smtp.client" , function (test )
59
- test :plan (10 )
79
+ test :plan (26 )
60
80
local r
61
81
local m
62
82
@@ -146,6 +166,54 @@ test:test("smtp.client", function(test)
146
166
m .text ,
147
167
" Subject: =%?utf%-8%?b%?YWJjZGVmZ2hpamvRj2xtbm9wcXJzdHV2d3h5eg==%?=" , " " ))
148
168
test :is (subj , 1 , ' subject codes >127' )
149
- end )
150
169
170
+ r = client :
request (
addr ,
' [email protected] ' ,
171
+
172
+ ' mail.body' )
173
+ test :is (r .reason , ' MAIL failed: 354' , ' errors 3xx' )
174
+ test :is (r .status , 354 , ' expected code' )
175
+
176
+ r = client :
request (
addr ,
' [email protected] ' ,
177
+
178
+ ' mail.body' )
179
+ test :is (r .reason , ' MAIL failed: 421' , ' service unavailable' )
180
+ test :is (r .status , 421 , ' expected code' )
181
+
182
+ r = client :
request (
addr ,
' [email protected] ' ,
183
+
184
+ ' mail.body' )
185
+ test :is (r .reason , ' MAIL failed: 510' , ' unexisting recipient' )
186
+ test :is (r .status , 510 , ' expected code' )
187
+
188
+ r = client :
request (
addr ,
' [email protected] ' ,
189
+
190
+ ' mail.body' )
191
+ test :is (r .reason , ' response reading failed' , ' unexpected response code' )
192
+ test :is (r .status , - 1 , ' expected code' )
193
+
194
+ r = client :
request (
addr ,
' [email protected] ' ,
195
+
196
+ ' mail.body' )
197
+ test :is (r .reason , ' RCPT failed: 354' , ' errors 3xx' )
198
+ test :is (r .status , 354 , ' expected code' )
199
+
200
+ r = client :
request (
addr ,
' [email protected] ' ,
201
+
202
+ ' mail.body' )
203
+ test :is (r .reason , ' RCPT failed: 421' , ' service unavailable' )
204
+ test :is (r .status , 421 , ' expected code' )
205
+
206
+ r = client :
request (
addr ,
' [email protected] ' ,
207
+
208
+ ' mail.body' )
209
+ test :is (r .reason , ' RCPT failed: 510' , ' unexisting recipient' )
210
+ test :is (r .status , 510 , ' expected code' )
211
+
212
+ r = client :
request (
addr ,
' [email protected] ' ,
213
+
214
+ ' mail.body' )
215
+ test :is (r .reason , ' response reading failed' , ' unexpected response code' )
216
+ test :is (r .status , - 1 , ' expected code' )
217
+
218
+ end )
151
219
os.exit (test :check () == true and 0 or - 1 )
0 commit comments