comparison 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
comparison
equal deleted inserted replaced
1108:ff1a37f37419 1109:59d5c8ca7e4d
24 select STDERR; $| = 1; 24 select STDERR; $| = 1;
25 select STDOUT; $| = 1; 25 select STDOUT; $| = 1;
26 26
27 local $SIG{PIPE} = 'IGNORE'; 27 local $SIG{PIPE} = 'IGNORE';
28 28
29 my $t = Test::Nginx->new()->has(qw/mail imap http rewrite/)->plan(9) 29 my $t = Test::Nginx->new()->has(qw/mail imap http rewrite/)->plan(11)
30 ->write_file_expand('nginx.conf', <<'EOF'); 30 ->write_file_expand('nginx.conf', <<'EOF');
31 31
32 %%TEST_GLOBALS%% 32 %%TEST_GLOBALS%%
33 33
34 daemon off; 34 daemon off;
41 auth_http http://127.0.0.1:8080/mail/auth; 41 auth_http http://127.0.0.1:8080/mail/auth;
42 42
43 server { 43 server {
44 listen 127.0.0.1:8143; 44 listen 127.0.0.1:8143;
45 protocol imap; 45 protocol imap;
46 imap_auth plain cram-md5;
46 } 47 }
47 } 48 }
48 49
49 http { 50 http {
50 %%TEST_GLOBALS_HTTP%% 51 %%TEST_GLOBALS_HTTP%%
53 listen 127.0.0.1:8080; 54 listen 127.0.0.1:8080;
54 server_name localhost; 55 server_name localhost;
55 56
56 location = /mail/auth { 57 location = /mail/auth {
57 set $reply ERROR; 58 set $reply ERROR;
59 set $passw "";
58 60
59 if ($http_auth_smtp_to ~ example.com) { 61 if ($http_auth_smtp_to ~ example.com) {
60 set $reply OK; 62 set $reply OK;
61 } 63 }
62 64
63 set $userpass "$http_auth_user:$http_auth_pass"; 65 set $userpass "$http_auth_user:$http_auth_pass";
64 if ($userpass ~ '^test@example.com:secret$') { 66 if ($userpass ~ '^test@example.com:secret$') {
65 set $reply OK; 67 set $reply OK;
66 } 68 }
67 69
70 set $userpass "$http_auth_user:$http_auth_salt:$http_auth_pass";
71 if ($userpass ~ '^test@example.com:<.*@.*>:0{32}$') {
72 set $reply OK;
73 set $passw secret;
74 }
75
68 add_header Auth-Status $reply; 76 add_header Auth-Status $reply;
69 add_header Auth-Server 127.0.0.1; 77 add_header Auth-Server 127.0.0.1;
70 add_header Auth-Port %%PORT_8144%%; 78 add_header Auth-Port %%PORT_8144%%;
79 add_header Auth-Pass $passw;
71 add_header Auth-Wait 1; 80 add_header Auth-Wait 1;
72 return 204; 81 return 204;
73 } 82 }
74 } 83 }
75 } 84 }
120 $s->check(qr/\+ UGFzc3dvcmQ6/, 'auth login with username password challenge'); 129 $s->check(qr/\+ UGFzc3dvcmQ6/, 'auth login with username password challenge');
121 130
122 $s->send(encode_base64('secret', '')); 131 $s->send(encode_base64('secret', ''));
123 $s->ok('auth login with username'); 132 $s->ok('auth login with username');
124 133
134 # auth cram-md5
135
136 $s = Test::Nginx::IMAP->new();
137 $s->read();
138
139 $s->send('1 AUTHENTICATE CRAM-MD5');
140 $s->check(qr/\+ /, 'auth cram-md5 challenge');
141
142 $s->send(encode_base64('test@example.com ' . ('0' x 32), ''));
143 $s->ok('auth cram-md5');
144
125 ############################################################################### 145 ###############################################################################