# HG changeset patch # User Maxim Dounin # Date 1621387991 -10800 # Node ID 869b312c214e813827f6229540607c82ca5a3e5e # Parent e7f0b4ca0a1acd192b7a8f8ead748979f1d91f33 Tests: additional IMAP tests. diff --git a/mail_imap.t b/mail_imap.t --- a/mail_imap.t +++ b/mail_imap.t @@ -12,6 +12,7 @@ use strict; use Test::More; use MIME::Base64; +use Socket qw/ CRLF /; BEGIN { use FindBin; chdir($FindBin::Bin); } @@ -60,7 +61,10 @@ http { set $passw ""; set $userpass "$http_auth_user:$http_auth_pass"; - if ($userpass ~ '^test@example.com:secret$') { + if ($userpass = 'test@example.com:secret') { + set $reply OK; + } + if ($userpass = 'te\\"st@example.com:se\\"cret') { set $reply OK; } @@ -71,7 +75,7 @@ http { } set $userpass "$http_auth_method:$http_auth_user:$http_auth_pass"; - if ($userpass ~ '^external:test@example.com:$') { + if ($userpass = 'external:test@example.com:') { set $reply OK; set $passw secret; } @@ -89,16 +93,30 @@ http { EOF $t->run_daemon(\&Test::Nginx::IMAP::imap_test_daemon); -$t->run()->plan(14); +$t->run()->plan(23); $t->waitforsocket('127.0.0.1:' . port(8144)); ############################################################################### +# login + my $s = Test::Nginx::IMAP->new(); $s->ok('greeting'); -# bad auth +$s->send('a01 LOGIN'); +$s->check(qr/^a01 BAD/, 'login without arguments'); + +$s->send('a02 LOGIN test@example.com bad'); +$s->check(qr/^a02 NO/, 'login with bad password'); + +$s->send('a03 LOGIN test@example.com secret'); +$s->ok('login'); + +# auth + +$s = Test::Nginx::IMAP->new(); +$s->read(); $s->send('1 AUTHENTICATE'); $s->check(qr/^\S+ BAD/, 'auth without arguments'); @@ -166,4 +184,51 @@ my $s = Test::Nginx::IMAP->new(); $s->send('1 AUTHENTICATE EXTERNAL ' . encode_base64('test@example.com', '')); $s->ok('auth external with username'); +# quoted strings + +$s = Test::Nginx::IMAP->new(); +$s->read(); + +$s->send('a01 LOGIN "te\\\\\"st@example.com" "se\\\\\"cret"'); +$s->ok('quoted strings'); + +# literals + +$s = Test::Nginx::IMAP->new(); +$s->read(); + +$s->send('a01 LOGIN {18}'); +$s->check(qr/\+ /, 'login username literal continue'); + +$s->send('te\"st@example.com' . ' {8}'); +$s->check(qr/\+ /, 'login password literal continue'); + +$s->send('se\"cret'); +$s->ok('login literals'); + +# non-synchronizing literals + +$s = Test::Nginx::IMAP->new(); +$s->read(); + +$s->send('a01 LOGIN {18+}' . CRLF + . 'te\"st@example.com' . ' {8+}' . CRLF + . 'se\"cret'); +$s->ok('login non-sync literals'); + +# backslash in quotes and literals + +$s = Test::Nginx::IMAP->new(); +$s->read(); + +$s->send('a01 LOGIN {18+}' . CRLF + . 'te\"st@example.com' . ' "se\\\\\"cret"'); + +TODO: { +local $TODO = 'not yet' unless $t->has_version('1.21.0'); + +$s->ok('backslash in literal'); + +} + ###############################################################################