comparison imap.t @ 59:bc3351f157ef

Tests: add basic pop3 and imap tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 12 Jan 2009 06:08:05 +0300
parents
children 726c3c2a8b8c
comparison
equal deleted inserted replaced
58:d053b4bf6ec6 59:bc3351f157ef
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 my $t = Test::Nginx->new()
30 ->has('mail')->plan(8)
31 ->run_daemon(\&Test::Nginx::IMAP::imap_test_daemon)
32 ->write_file_expand('nginx.conf', <<'EOF')->run();
33
34 master_process off;
35 daemon off;
36
37 events {
38 worker_connections 1024;
39 }
40
41 mail {
42 proxy_pass_error_message on;
43 auth_http http://127.0.0.1:8080/mail/auth;
44
45 server {
46 listen 127.0.0.1:8143;
47 protocol imap;
48 smtp_auth login plain;
49 }
50 }
51
52 http {
53 access_log off;
54
55 client_body_temp_path %%TESTDIR%%/client_body_temp;
56 fastcgi_temp_path %%TESTDIR%%/fastcgi_temp;
57 proxy_temp_path %%TESTDIR%%/proxy_temp;
58
59 server {
60 listen 127.0.0.1:8080;
61 server_name localhost;
62
63 location = /mail/auth {
64 set $reply ERROR;
65
66 if ($http_auth_smtp_to ~ example.com) {
67 set $reply OK;
68 }
69
70 set $userpass "$http_auth_user:$http_auth_pass";
71 if ($userpass ~ '^test@example.com:secret$') {
72 set $reply OK;
73 }
74
75 add_header Auth-Status $reply;
76 add_header Auth-Server 127.0.0.1;
77 add_header Auth-Port 8144;
78 add_header Auth-Wait 1;
79 return 204;
80 }
81 }
82 }
83
84 EOF
85
86 ###############################################################################
87
88 my $s = Test::Nginx::IMAP->new();
89 $s->ok('greeting');
90
91 # auth plain
92
93 $s->send('1 AUTHENTICATE PLAIN ' . encode_base64("\0test\@example.com\0bad", ''));
94 $s->check(qr/^\S+ NO/, 'auth plain with bad password');
95
96 $s->send('1 AUTHENTICATE PLAIN ' . encode_base64("\0test\@example.com\0secret", ''));
97 $s->ok('auth plain');
98
99 # auth login simple
100
101 $s = Test::Nginx::IMAP->new();
102 $s->read();
103
104 $s->send('1 AUTHENTICATE LOGIN');
105 $s->check(qr/\+ VXNlcm5hbWU6/, 'auth login username challenge');
106
107 $s->send(encode_base64('test@example.com', ''));
108 $s->check(qr/\+ UGFzc3dvcmQ6/, 'auth login password challenge');
109
110 $s->send(encode_base64('secret', ''));
111 $s->ok('auth login simple');
112
113 # auth login with username
114
115 TODO: {
116 local $TODO = 'not supported yet';
117
118 $s = Test::Nginx::IMAP->new();
119 $s->read();
120
121 $s->send('1 AUTHENTICATE LOGIN ' . encode_base64('test@example.com', ''));
122 $s->check(qr/\+ UGFzc3dvcmQ6/, 'auth login with username password challenge');
123
124 $s->send(encode_base64('secret', ''));
125 $s->ok('auth login with username');
126
127 }
128
129 ###############################################################################