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