diff mail_imap.t @ 1109:59d5c8ca7e4d

Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 12 Jan 2017 11:46:11 +0300
parents a8b8dd6e8ae1
children b9b115a2a28d
line wrap: on
line diff
--- a/mail_imap.t
+++ b/mail_imap.t
@@ -26,7 +26,7 @@ select STDOUT; $| = 1;
 
 local $SIG{PIPE} = 'IGNORE';
 
-my $t = Test::Nginx->new()->has(qw/mail imap http rewrite/)->plan(9)
+my $t = Test::Nginx->new()->has(qw/mail imap http rewrite/)->plan(11)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
@@ -43,6 +43,7 @@ mail {
     server {
         listen     127.0.0.1:8143;
         protocol   imap;
+        imap_auth  plain cram-md5;
     }
 }
 
@@ -55,6 +56,7 @@ http {
 
         location = /mail/auth {
             set $reply ERROR;
+            set $passw "";
 
             if ($http_auth_smtp_to ~ example.com) {
                 set $reply OK;
@@ -65,9 +67,16 @@ http {
                 set $reply OK;
             }
 
+            set $userpass "$http_auth_user:$http_auth_salt:$http_auth_pass";
+            if ($userpass ~ '^test@example.com:<.*@.*>:0{32}$') {
+                set $reply OK;
+                set $passw secret;
+            }
+
             add_header Auth-Status $reply;
             add_header Auth-Server 127.0.0.1;
             add_header Auth-Port %%PORT_8144%%;
+            add_header Auth-Pass $passw;
             add_header Auth-Wait 1;
             return 204;
         }
@@ -122,4 +131,15 @@ my $s = Test::Nginx::IMAP->new();
 $s->send(encode_base64('secret', ''));
 $s->ok('auth login with username');
 
+# auth cram-md5
+
+$s = Test::Nginx::IMAP->new();
+$s->read();
+
+$s->send('1 AUTHENTICATE CRAM-MD5');
+$s->check(qr/\+ /, 'auth cram-md5 challenge');
+
+$s->send(encode_base64('test@example.com ' . ('0' x 32), ''));
+$s->ok('auth cram-md5');
+
 ###############################################################################