annotate pop3.t @ 103:4ae2198b97ec

Tests: limit_req tests for 0.8.18 changes and bug. 1. Make sure rejected requests are not counted, as leaky bucket algorithm suggests (finally correctly done in 0.8.18). 2. Make sure negative excess values are handled properly (bug appeared in 0.8.18, fixed in 0.8.19).
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 09 Oct 2009 21:05:42 +0400
parents ecff5407867c
children 1c0ec30614c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
1 #!/usr/bin/perl
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
2
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
3 # (C) Maxim Dounin
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
4
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
5 # Tests for nginx mail pop3 module.
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
6
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
7 ###############################################################################
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
8
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
9 use warnings;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
10 use strict;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
11
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
12 use Test::More;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
13
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
14 use IO::Socket;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
15 use MIME::Base64;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
16 use Socket qw/ CRLF /;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
17
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
18 BEGIN { use FindBin; chdir($FindBin::Bin); }
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
19
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
20 use lib 'lib';
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21 use Test::Nginx;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
22 use Test::Nginx::POP3;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
23
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
24 ###############################################################################
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
25
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
26 select STDERR; $| = 1;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
27 select STDOUT; $| = 1;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
28
96
ecff5407867c Tests: better handle unexpected connection close from nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 75
diff changeset
29 local $SIG{PIPE} = 'IGNORE';
ecff5407867c Tests: better handle unexpected connection close from nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 75
diff changeset
30
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
31 my $t = Test::Nginx->new()
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
32 ->has('mail')->plan(8)
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
33 ->run_daemon(\&Test::Nginx::POP3::pop3_test_daemon)
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
34 ->write_file_expand('nginx.conf', <<'EOF')->run();
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
35
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
36 master_process off;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
37 daemon off;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
38
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
39 events {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
40 }
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
41
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
42 mail {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
43 proxy_pass_error_message on;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
44 auth_http http://127.0.0.1:8080/mail/auth;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
45
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
46 server {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
47 listen 127.0.0.1:8110;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
48 protocol pop3;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
49 }
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
50 }
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
51
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
52 http {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
53 access_log off;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
54
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
55 client_body_temp_path %%TESTDIR%%/client_body_temp;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
56 fastcgi_temp_path %%TESTDIR%%/fastcgi_temp;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
57 proxy_temp_path %%TESTDIR%%/proxy_temp;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
58
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
59 server {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
60 listen 127.0.0.1:8080;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
61 server_name localhost;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
62
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
63 location = /mail/auth {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
64 set $reply ERROR;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
65
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
66 if ($http_auth_smtp_to ~ example.com) {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
67 set $reply OK;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
68 }
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
69
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
70 set $userpass "$http_auth_user:$http_auth_pass";
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
71 if ($userpass ~ '^test@example.com:secret$') {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
72 set $reply OK;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
73 }
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
74
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
75 add_header Auth-Status $reply;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
76 add_header Auth-Server 127.0.0.1;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
77 add_header Auth-Port 8111;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
78 add_header Auth-Wait 1;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
79 return 204;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
80 }
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
81 }
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
82 }
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
83
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
84 EOF
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
85
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
86 ###############################################################################
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
87
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
88 my $s = Test::Nginx::POP3->new();
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
89 $s->ok('greeting');
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
90
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
91 # auth plain
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
92
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
93 $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0bad", ''));
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
94 $s->check(qr/^-ERR/, 'auth plain with bad password');
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
95
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
96 $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", ''));
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
97 $s->ok('auth plain');
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
98
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
99 # auth login simple
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
100
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
101 $s = Test::Nginx::POP3->new();
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
102 $s->read();
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
103
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
104 $s->send('AUTH LOGIN');
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
105 $s->check(qr/\+ VXNlcm5hbWU6/, 'auth login username challenge');
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
106
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
107 $s->send(encode_base64('test@example.com', ''));
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
108 $s->check(qr/\+ UGFzc3dvcmQ6/, 'auth login password challenge');
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
109
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
110 $s->send(encode_base64('secret', ''));
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
111 $s->ok('auth login simple');
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
112
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
113 # auth login with username
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
114
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
115 $s = Test::Nginx::POP3->new();
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
116 $s->read();
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
117
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
118 $s->send('AUTH LOGIN ' . encode_base64('test@example.com', ''));
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
119 $s->check(qr/\+ UGFzc3dvcmQ6/, 'auth login with username password challenge');
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
120
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
121 $s->send(encode_base64('secret', ''));
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
122 $s->ok('auth login with username');
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
123
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
124 ###############################################################################