Mercurial > hg > nginx-tests
comparison mail_imap.t @ 148:b714d6df958c
Tests: rename some tests for better sorting.
Use underscore instead of dash. Addtionally, rename some tests to better
match "module" + "details" scheme used: use "http_" prefix for http core
module tests, use "mail_" prefix for mail module tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 04 Mar 2011 16:07:15 +0300 |
parents | imap.t@8ac1faaddd2c |
children | 1c39b7edc593 |
comparison
equal
deleted
inserted
replaced
147:fd865ada95c8 | 148:b714d6df958c |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for nginx mail imap module. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 | |
14 use IO::Socket; | |
15 use MIME::Base64; | |
16 use Socket qw/ CRLF /; | |
17 | |
18 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
19 | |
20 use lib 'lib'; | |
21 use Test::Nginx; | |
22 use Test::Nginx::IMAP; | |
23 | |
24 ############################################################################### | |
25 | |
26 select STDERR; $| = 1; | |
27 select STDOUT; $| = 1; | |
28 | |
29 local $SIG{PIPE} = 'IGNORE'; | |
30 | |
31 my $t = Test::Nginx->new() | |
32 ->has(qw/mail imap http rewrite/)->plan(8) | |
33 ->run_daemon(\&Test::Nginx::IMAP::imap_test_daemon) | |
34 ->write_file_expand('nginx.conf', <<'EOF')->run(); | |
35 | |
36 %%TEST_GLOBALS%% | |
37 | |
38 master_process off; | |
39 daemon off; | |
40 | |
41 events { | |
42 } | |
43 | |
44 mail { | |
45 proxy_pass_error_message on; | |
46 auth_http http://127.0.0.1:8080/mail/auth; | |
47 | |
48 server { | |
49 listen 127.0.0.1:8143; | |
50 protocol imap; | |
51 } | |
52 } | |
53 | |
54 http { | |
55 %%TEST_GLOBALS_HTTP%% | |
56 | |
57 server { | |
58 listen 127.0.0.1:8080; | |
59 server_name localhost; | |
60 | |
61 location = /mail/auth { | |
62 set $reply ERROR; | |
63 | |
64 if ($http_auth_smtp_to ~ example.com) { | |
65 set $reply OK; | |
66 } | |
67 | |
68 set $userpass "$http_auth_user:$http_auth_pass"; | |
69 if ($userpass ~ '^test@example.com:secret$') { | |
70 set $reply OK; | |
71 } | |
72 | |
73 add_header Auth-Status $reply; | |
74 add_header Auth-Server 127.0.0.1; | |
75 add_header Auth-Port 8144; | |
76 add_header Auth-Wait 1; | |
77 return 204; | |
78 } | |
79 } | |
80 } | |
81 | |
82 EOF | |
83 | |
84 ############################################################################### | |
85 | |
86 my $s = Test::Nginx::IMAP->new(); | |
87 $s->ok('greeting'); | |
88 | |
89 # auth plain | |
90 | |
91 $s->send('1 AUTHENTICATE PLAIN ' . encode_base64("\0test\@example.com\0bad", '')); | |
92 $s->check(qr/^\S+ NO/, 'auth plain with bad password'); | |
93 | |
94 $s->send('1 AUTHENTICATE PLAIN ' . encode_base64("\0test\@example.com\0secret", '')); | |
95 $s->ok('auth plain'); | |
96 | |
97 # auth login simple | |
98 | |
99 $s = Test::Nginx::IMAP->new(); | |
100 $s->read(); | |
101 | |
102 $s->send('1 AUTHENTICATE LOGIN'); | |
103 $s->check(qr/\+ VXNlcm5hbWU6/, 'auth login username challenge'); | |
104 | |
105 $s->send(encode_base64('test@example.com', '')); | |
106 $s->check(qr/\+ UGFzc3dvcmQ6/, 'auth login password challenge'); | |
107 | |
108 $s->send(encode_base64('secret', '')); | |
109 $s->ok('auth login simple'); | |
110 | |
111 # auth login with username | |
112 | |
113 $s = Test::Nginx::IMAP->new(); | |
114 $s->read(); | |
115 | |
116 $s->send('1 AUTHENTICATE LOGIN ' . encode_base64('test@example.com', '')); | |
117 $s->check(qr/\+ UGFzc3dvcmQ6/, 'auth login with username password challenge'); | |
118 | |
119 $s->send(encode_base64('secret', '')); | |
120 $s->ok('auth login with username'); | |
121 | |
122 ############################################################################### |