changeset 1685:869b312c214e

Tests: additional IMAP tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 19 May 2021 04:33:11 +0300
parents e7f0b4ca0a1a
children 156cb84b3c23
files mail_imap.t
diffstat 1 files changed, 69 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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');
+
+}
+
 ###############################################################################