diff mail_pop3.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_pop3.t
+++ b/mail_pop3.t
@@ -26,7 +26,7 @@ select STDOUT; $| = 1;
 
 local $SIG{PIPE} = 'IGNORE';
 
-my $t = Test::Nginx->new()->has(qw/mail pop3 http rewrite/)->plan(8)
+my $t = Test::Nginx->new()->has(qw/mail pop3 http rewrite/)->plan(15)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
@@ -43,6 +43,7 @@ mail {
     server {
         listen     127.0.0.1:8110;
         protocol   pop3;
+        pop3_auth  plain apop 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_8111%%;
+            add_header Auth-Pass $passw;
             add_header Auth-Wait 1;
             return 204;
         }
@@ -84,8 +93,30 @@ EOF
 my $s = Test::Nginx::POP3->new();
 $s->ok('greeting');
 
+# user / pass
+
+$s->send('USER test@example.com');
+$s->ok('user');
+
+$s->send('PASS secret');
+$s->ok('pass');
+
+# apop
+
+$s = Test::Nginx::POP3->new();
+$s->check(qr/<.*\@.*>/, 'apop salt');
+
+$s->send('APOP test@example.com ' . ('1' x 32));
+$s->check(qr/^-ERR/, 'apop error');
+
+$s->send('APOP test@example.com ' . ('0' x 32));
+$s->ok('apop');
+
 # auth plain
 
+$s = Test::Nginx::POP3->new();
+$s->read();
+
 $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0bad", ''));
 $s->check(qr/^-ERR/, 'auth plain with bad password');
 
@@ -117,4 +148,15 @@ my $s = Test::Nginx::POP3->new();
 $s->send(encode_base64('secret', ''));
 $s->ok('auth login with username');
 
+# auth cram-md5
+
+$s = Test::Nginx::POP3->new();
+$s->read();
+
+$s->send('AUTH CRAM-MD5');
+$s->check(qr/\+ /, 'auth cram-md5 challenge');
+
+$s->send(encode_base64('test@example.com ' . ('0' x 32), ''));
+$s->ok('auth cram-md5');
+
 ###############################################################################