Mercurial > hg > nginx-tests
comparison smtp.t @ 14:d4b74207a627
Tests: refactor common functions.
Let it be something more structured, avoid globals.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 12 Sep 2008 20:50:35 +0400 |
parents | f772e2a1a13f |
children | 7e28c64edf55 |
comparison
equal
deleted
inserted
replaced
13:e8edb765595d | 14:d4b74207a627 |
---|---|
14 use MIME::Base64; | 14 use MIME::Base64; |
15 use Socket qw/ CRLF /; | 15 use Socket qw/ CRLF /; |
16 | 16 |
17 BEGIN { use FindBin; chdir($FindBin::Bin); } | 17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
18 | 18 |
19 use _common; | 19 use lib 'lib'; |
20 use Test::Nginx; | |
21 use Test::Nginx::SMTP; | |
20 | 22 |
21 ############################################################################### | 23 ############################################################################### |
22 | 24 |
23 select STDERR; $| = 1; | 25 select STDERR; $| = 1; |
24 select STDOUT; $| = 1; | 26 select STDOUT; $| = 1; |
25 | 27 |
26 start_nginx('smtp.conf'); | 28 my $t = Test::Nginx->new()->run('smtp.conf'); |
27 | 29 |
28 ############################################################################### | 30 ############################################################################### |
29 | 31 |
30 my $s = smtp_connect(); | 32 my $s = Test::Nginx::SMTP->new(); |
31 smtp_check(qr/^220 /, "greeting"); | 33 $s->check(qr/^220 /, "greeting"); |
32 | 34 |
33 smtp_send('EHLO example.com'); | 35 $s->send('EHLO example.com'); |
34 smtp_check(qr/^250 /, "ehlo"); | 36 $s->check(qr/^250 /, "ehlo"); |
35 | 37 |
36 smtp_send('AUTH PLAIN ' . encode_base64("test\@example.com\0\0bad", '')); | 38 $s->send('AUTH PLAIN ' . encode_base64("test\@example.com\0\0bad", '')); |
37 smtp_check(qr/^5.. /, 'auth plain with bad password'); | 39 $s->check(qr/^5.. /, 'auth plain with bad password'); |
38 | 40 |
39 smtp_send('AUTH PLAIN ' . encode_base64("test\@example.com\0\0secret", '')); | 41 $s->send('AUTH PLAIN ' . encode_base64("test\@example.com\0\0secret", '')); |
40 smtp_ok('auth plain'); | 42 $s->ok('auth plain'); |
41 | 43 |
42 # We are talking to backend from this point | 44 # We are talking to backend from this point |
43 | 45 |
44 smtp_send('MAIL FROM:<test@example.com> SIZE=100'); | 46 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
45 smtp_ok('mail from after auth'); | 47 $s->ok('mail from after auth'); |
46 | 48 |
47 smtp_send('RSET'); | 49 $s->send('RSET'); |
48 smtp_ok('rset'); | 50 $s->ok('rset'); |
49 | 51 |
50 smtp_send('MAIL FROM:<test@xn--e1afmkfd.xn--80akhbyknj4f> SIZE=100'); | 52 $s->send('MAIL FROM:<test@xn--e1afmkfd.xn--80akhbyknj4f> SIZE=100'); |
51 smtp_ok("idn mail from (example.test in russian)"); | 53 $s->ok("idn mail from (example.test in russian)"); |
52 | 54 |
53 smtp_send('QUIT'); | 55 $s->send('QUIT'); |
54 smtp_ok("quit"); | 56 $s->ok("quit"); |
55 | 57 |
56 # Try auth plain with pipelining | 58 # Try auth plain with pipelining |
57 | 59 |
58 $s = smtp_connect(); | 60 $s = Test::Nginx::SMTP->new(); |
59 smtp_check(qr/^220 /, "greeting"); | 61 $s->check(qr/^220 /, "greeting"); |
60 | 62 |
61 smtp_send('EHLO example.com'); | 63 $s->send('EHLO example.com'); |
62 smtp_check(qr/^250 /, "ehlo"); | 64 $s->check(qr/^250 /, "ehlo"); |
63 | 65 |
64 smtp_send('INVALID COMMAND WITH ARGUMENTS' . CRLF | 66 $s->send('INVALID COMMAND WITH ARGUMENTS' . CRLF |
65 . 'RSET'); | 67 . 'RSET'); |
66 smtp_read(); | 68 $s->read(); |
67 smtp_ok('pipelined rset after invalid command'); | 69 $s->ok('pipelined rset after invalid command'); |
68 | 70 |
69 smtp_send('AUTH PLAIN ' | 71 $s->send('AUTH PLAIN ' |
70 . encode_base64("test\@example.com\0\0bad", '') . CRLF | 72 . encode_base64("test\@example.com\0\0bad", '') . CRLF |
71 . 'MAIL FROM:<test@example.com> SIZE=100'); | 73 . 'MAIL FROM:<test@example.com> SIZE=100'); |
72 smtp_read(); | 74 $s->read(); |
73 smtp_ok('mail from after failed pipelined auth'); | 75 $s->ok('mail from after failed pipelined auth'); |
74 | 76 |
75 smtp_send('AUTH PLAIN ' | 77 $s->send('AUTH PLAIN ' |
76 . encode_base64("test\@example.com\0\0secret", '') . CRLF | 78 . encode_base64("test\@example.com\0\0secret", '') . CRLF |
77 . 'MAIL FROM:<test@example.com> SIZE=100'); | 79 . 'MAIL FROM:<test@example.com> SIZE=100'); |
78 smtp_read(); | 80 $s->read(); |
79 smtp_ok('mail from after pipelined auth'); | 81 $s->ok('mail from after pipelined auth'); |
80 | 82 |
81 # Try auth none | 83 # Try auth none |
82 | 84 |
83 $s = smtp_connect(); | 85 $s = Test::Nginx::SMTP->new(); |
84 smtp_check(qr/^220 /, "greeting"); | 86 $s->check(qr/^220 /, "greeting"); |
85 | 87 |
86 smtp_send('EHLO example.com'); | 88 $s->send('EHLO example.com'); |
87 smtp_check(qr/^250 /, "ehlo"); | 89 $s->check(qr/^250 /, "ehlo"); |
88 | 90 |
89 smtp_send('MAIL FROM:<test@example.com> SIZE=100'); | 91 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
90 smtp_ok('auth none - mail from'); | 92 $s->ok('auth none - mail from'); |
91 | 93 |
92 smtp_send('RCPT TO:<test@example.com>'); | 94 $s->send('RCPT TO:<test@example.com>'); |
93 smtp_ok('auth none - rcpt to'); | 95 $s->ok('auth none - rcpt to'); |
94 | 96 |
95 smtp_send('RSET'); | 97 $s->send('RSET'); |
96 smtp_ok('auth none - rset, should go to backend'); | 98 $s->ok('auth none - rset, should go to backend'); |
97 | 99 |
98 # Auth none with pipelining | 100 # Auth none with pipelining |
99 | 101 |
100 $s = smtp_connect(); | 102 $s = Test::Nginx::SMTP->new(); |
101 smtp_check(qr/^220 /, "greeting"); | 103 $s->check(qr/^220 /, "greeting"); |
102 | 104 |
103 smtp_send('EHLO example.com'); | 105 $s->send('EHLO example.com'); |
104 smtp_check(qr/^250 /, "ehlo"); | 106 $s->check(qr/^250 /, "ehlo"); |
105 | 107 |
106 smtp_send('MAIL FROM:<test@example.com> SIZE=100' . CRLF | 108 $s->send('MAIL FROM:<test@example.com> SIZE=100' . CRLF |
107 . 'RCPT TO:<test@example.com>' . CRLF | 109 . 'RCPT TO:<test@example.com>' . CRLF |
108 . 'RSET'); | 110 . 'RSET'); |
109 | 111 |
110 smtp_ok('pipelined mail from'); | 112 $s->ok('pipelined mail from'); |
111 | 113 |
112 smtp_ok('pipelined rcpt to'); | 114 $s->ok('pipelined rcpt to'); |
113 smtp_ok('pipelined rset'); | 115 $s->ok('pipelined rset'); |
114 | 116 |
115 # Connection must stay even if error returned to rcpt to command | 117 # Connection must stay even if error returned to rcpt to command |
116 | 118 |
117 $s = smtp_connect(); | 119 $s = Test::Nginx::SMTP->new(); |
118 smtp_read(); # skip greeting | 120 $s->read(); # skip greeting |
119 | 121 |
120 smtp_send('EHLO example.com'); | 122 $s->send('EHLO example.com'); |
121 smtp_read(); # skip ehlo reply | 123 $s->read(); # skip ehlo reply |
122 | 124 |
123 smtp_send('MAIL FROM:<test@example.com> SIZE=100'); | 125 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
124 smtp_read(); # skip mail from reply | 126 $s->read(); # skip mail from reply |
125 | 127 |
126 smtp_send('RCPT TO:<example.com>'); | 128 $s->send('RCPT TO:<example.com>'); |
127 smtp_check(qr/^5.. /, "bad rcpt to"); | 129 $s->check(qr/^5.. /, "bad rcpt to"); |
128 | 130 |
129 smtp_send('RCPT TO:<test@example.com>'); | 131 $s->send('RCPT TO:<test@example.com>'); |
130 smtp_ok('good rcpt to'); | 132 $s->ok('good rcpt to'); |
131 | 133 |
132 # Make sure command splitted into many packets processed correctly | 134 # Make sure command splitted into many packets processed correctly |
133 | 135 |
134 $s = smtp_connect(); | 136 $s = Test::Nginx::SMTP->new(); |
135 smtp_read(); | 137 $s->read(); |
136 | 138 |
137 log_out('HEL'); | 139 log_out('HEL'); |
138 $s->print('HEL'); | 140 $s->print('HEL'); |
139 smtp_send('O example.com'); | 141 $s->send('O example.com'); |
140 smtp_ok('splitted command'); | 142 $s->ok('splitted command'); |
141 | 143 |
142 # With smtp_greeting_delay session expected to be closed after first error | 144 # With smtp_greeting_delay session expected to be closed after first error |
143 # message if client sent something before greeting. Use 10026 port | 145 # message if client sent something before greeting. Use 10026 port |
144 # configured with smtp_greeting_delay 0.1s to check this. | 146 # configured with smtp_greeting_delay 0.1s to check this. |
145 | 147 |
146 $s = smtp_connect(PeerPort => 10026); | 148 $s = Test::Nginx::SMTP->new(PeerPort => 10026); |
147 smtp_send('HELO example.com'); | 149 $s->send('HELO example.com'); |
148 smtp_check(qr/^5.. /, "command before greeting - session must be rejected"); | 150 $s->check(qr/^5.. /, "command before greeting - session must be rejected"); |
149 ok($s->eof(), "session have to be closed"); | 151 ok($s->eof(), "session have to be closed"); |
150 | 152 |
151 ############################################################################### | 153 ############################################################################### |