Mercurial > hg > nginx-tests
comparison 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 |
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 pop3 http rewrite/)->plan(8) | 29 my $t = Test::Nginx->new()->has(qw/mail pop3 http rewrite/)->plan(15) |
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:8110; | 44 listen 127.0.0.1:8110; |
45 protocol pop3; | 45 protocol pop3; |
46 pop3_auth plain apop 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_8111%%; | 78 add_header Auth-Port %%PORT_8111%%; |
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 } |
82 ############################################################################### | 91 ############################################################################### |
83 | 92 |
84 my $s = Test::Nginx::POP3->new(); | 93 my $s = Test::Nginx::POP3->new(); |
85 $s->ok('greeting'); | 94 $s->ok('greeting'); |
86 | 95 |
96 # user / pass | |
97 | |
98 $s->send('USER test@example.com'); | |
99 $s->ok('user'); | |
100 | |
101 $s->send('PASS secret'); | |
102 $s->ok('pass'); | |
103 | |
104 # apop | |
105 | |
106 $s = Test::Nginx::POP3->new(); | |
107 $s->check(qr/<.*\@.*>/, 'apop salt'); | |
108 | |
109 $s->send('APOP test@example.com ' . ('1' x 32)); | |
110 $s->check(qr/^-ERR/, 'apop error'); | |
111 | |
112 $s->send('APOP test@example.com ' . ('0' x 32)); | |
113 $s->ok('apop'); | |
114 | |
87 # auth plain | 115 # auth plain |
116 | |
117 $s = Test::Nginx::POP3->new(); | |
118 $s->read(); | |
88 | 119 |
89 $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0bad", '')); | 120 $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0bad", '')); |
90 $s->check(qr/^-ERR/, 'auth plain with bad password'); | 121 $s->check(qr/^-ERR/, 'auth plain with bad password'); |
91 | 122 |
92 $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", '')); | 123 $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", '')); |
115 $s->check(qr/\+ UGFzc3dvcmQ6/, 'auth login with username password challenge'); | 146 $s->check(qr/\+ UGFzc3dvcmQ6/, 'auth login with username password challenge'); |
116 | 147 |
117 $s->send(encode_base64('secret', '')); | 148 $s->send(encode_base64('secret', '')); |
118 $s->ok('auth login with username'); | 149 $s->ok('auth login with username'); |
119 | 150 |
151 # auth cram-md5 | |
152 | |
153 $s = Test::Nginx::POP3->new(); | |
154 $s->read(); | |
155 | |
156 $s->send('AUTH CRAM-MD5'); | |
157 $s->check(qr/\+ /, 'auth cram-md5 challenge'); | |
158 | |
159 $s->send(encode_base64('test@example.com ' . ('0' x 32), '')); | |
160 $s->ok('auth cram-md5'); | |
161 | |
120 ############################################################################### | 162 ############################################################################### |