Skip to content

Commit c91ab82

Browse files
committed
Tests: additional IMAP tests.
1 parent 4952bfd commit c91ab82

File tree

1 file changed

+69
-4
lines changed

1 file changed

+69
-4
lines changed

mail_imap.t

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use strict;
1212
use Test::More;
1313

1414
use MIME::Base64;
15+
use Socket qw/ CRLF /;
1516

1617
BEGIN { use FindBin; chdir($FindBin::Bin); }
1718

@@ -60,7 +61,10 @@ http {
6061
set $passw "";
6162
6263
set $userpass "$http_auth_user:$http_auth_pass";
63-
if ($userpass ~ '^[email protected]:secret$') {
64+
if ($userpass = '[email protected]:secret') {
65+
set $reply OK;
66+
}
67+
if ($userpass = 'te\\"[email protected]:se\\"cret') {
6468
set $reply OK;
6569
}
6670
@@ -71,7 +75,7 @@ http {
7175
}
7276
7377
set $userpass "$http_auth_method:$http_auth_user:$http_auth_pass";
74-
if ($userpass ~ '^external:[email protected]:$') {
78+
if ($userpass = 'external:[email protected]:') {
7579
set $reply OK;
7680
set $passw secret;
7781
}
@@ -89,16 +93,30 @@ http {
8993
EOF
9094

9195
$t->run_daemon(\&Test::Nginx::IMAP::imap_test_daemon);
92-
$t->run()->plan(14);
96+
$t->run()->plan(23);
9397

9498
$t->waitforsocket('127.0.0.1:' . port(8144));
9599

96100
###############################################################################
97101

102+
# login
103+
98104
my $s = Test::Nginx::IMAP->new();
99105
$s->ok('greeting');
100106

101-
# bad auth
107+
$s->send('a01 LOGIN');
108+
$s->check(qr/^a01 BAD/, 'login without arguments');
109+
110+
$s->send('a02 LOGIN [email protected] bad');
111+
$s->check(qr/^a02 NO/, 'login with bad password');
112+
113+
$s->send('a03 LOGIN [email protected] secret');
114+
$s->ok('login');
115+
116+
# auth
117+
118+
$s = Test::Nginx::IMAP->new();
119+
$s->read();
102120

103121
$s->send('1 AUTHENTICATE');
104122
$s->check(qr/^\S+ BAD/, 'auth without arguments');
@@ -166,4 +184,51 @@ $s->read();
166184
$s->send('1 AUTHENTICATE EXTERNAL ' . encode_base64('[email protected]', ''));
167185
$s->ok('auth external with username');
168186

187+
# quoted strings
188+
189+
$s = Test::Nginx::IMAP->new();
190+
$s->read();
191+
192+
$s->send('a01 LOGIN "te\\\\\"[email protected]" "se\\\\\"cret"');
193+
$s->ok('quoted strings');
194+
195+
# literals
196+
197+
$s = Test::Nginx::IMAP->new();
198+
$s->read();
199+
200+
$s->send('a01 LOGIN {18}');
201+
$s->check(qr/\+ /, 'login username literal continue');
202+
203+
$s->send('te\"[email protected]' . ' {8}');
204+
$s->check(qr/\+ /, 'login password literal continue');
205+
206+
$s->send('se\"cret');
207+
$s->ok('login literals');
208+
209+
# non-synchronizing literals
210+
211+
$s = Test::Nginx::IMAP->new();
212+
$s->read();
213+
214+
$s->send('a01 LOGIN {18+}' . CRLF
215+
. 'te\"[email protected]' . ' {8+}' . CRLF
216+
. 'se\"cret');
217+
$s->ok('login non-sync literals');
218+
219+
# backslash in quotes and literals
220+
221+
$s = Test::Nginx::IMAP->new();
222+
$s->read();
223+
224+
$s->send('a01 LOGIN {18+}' . CRLF
225+
. 'te\"[email protected]' . ' "se\\\\\"cret"');
226+
227+
TODO: {
228+
local $TODO = 'not yet' unless $t->has_version('1.21.0');
229+
230+
$s->ok('backslash in literal');
231+
232+
}
233+
169234
###############################################################################

0 commit comments

Comments
 (0)