Mercurial > hg > nginx-tests
annotate mail_pop3.t @ 1104:b3d5a2f8a00b
Tests: stream ssl_verify_client tests.
author | Andrey Zelenkov <zelenkov@nginx.com> |
---|---|
date | Thu, 29 Dec 2016 18:54:04 +0300 |
parents | a8b8dd6e8ae1 |
children | 59d5c8ca7e4d |
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 MIME::Base64; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 BEGIN { use FindBin; chdir($FindBin::Bin); } |
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 use lib 'lib'; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 use Test::Nginx; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 use Test::Nginx::POP3; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 ############################################################################### |
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 select STDERR; $| = 1; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
96
ecff5407867c
Tests: better handle unexpected connection close from nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents:
75
diff
changeset
|
27 local $SIG{PIPE} = 'IGNORE'; |
ecff5407867c
Tests: better handle unexpected connection close from nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents:
75
diff
changeset
|
28 |
976
a8b8dd6e8ae1
Tests: changed startup order in mail tests for consistency.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
970
diff
changeset
|
29 my $t = Test::Nginx->new()->has(qw/mail pop3 http rewrite/)->plan(8) |
a8b8dd6e8ae1
Tests: changed startup order in mail tests for consistency.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
970
diff
changeset
|
30 ->write_file_expand('nginx.conf', <<'EOF'); |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
96
diff
changeset
|
32 %%TEST_GLOBALS%% |
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
96
diff
changeset
|
33 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
34 daemon off; |
59
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 events { |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 } |
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 mail { |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 proxy_pass_error_message on; |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
41 auth_http http://127.0.0.1:8080/mail/auth; |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 server { |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
44 listen 127.0.0.1:8110; |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 protocol pop3; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 } |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 } |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 http { |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
96
diff
changeset
|
50 %%TEST_GLOBALS_HTTP%% |
59
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 server { |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
53 listen 127.0.0.1:8080; |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 server_name localhost; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 location = /mail/auth { |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 set $reply ERROR; |
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 if ($http_auth_smtp_to ~ example.com) { |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 set $reply OK; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 } |
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 set $userpass "$http_auth_user:$http_auth_pass"; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 if ($userpass ~ '^test@example.com:secret$') { |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 set $reply OK; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 } |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 add_header Auth-Status $reply; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 add_header Auth-Server 127.0.0.1; |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
70 add_header Auth-Port %%PORT_8111%%; |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 add_header Auth-Wait 1; |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 return 204; |
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 } |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 EOF |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 |
976
a8b8dd6e8ae1
Tests: changed startup order in mail tests for consistency.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
970
diff
changeset
|
79 $t->run_daemon(\&Test::Nginx::POP3::pop3_test_daemon); |
a8b8dd6e8ae1
Tests: changed startup order in mail tests for consistency.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
970
diff
changeset
|
80 $t->run()->waitforsocket('127.0.0.1:' . port(8111)); |
a8b8dd6e8ae1
Tests: changed startup order in mail tests for consistency.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
970
diff
changeset
|
81 |
59
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 |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
84 my $s = Test::Nginx::POP3->new(); |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 $s->ok('greeting'); |
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 # auth plain |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 $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
|
90 $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
|
91 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 $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
|
93 $s->ok('auth plain'); |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 # auth login simple |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
97 $s = Test::Nginx::POP3->new(); |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 $s->read(); |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 $s->send('AUTH LOGIN'); |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 $s->check(qr/\+ VXNlcm5hbWU6/, 'auth login username challenge'); |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 $s->send(encode_base64('test@example.com', '')); |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 $s->check(qr/\+ UGFzc3dvcmQ6/, 'auth login password challenge'); |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
106 $s->send(encode_base64('secret', '')); |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
107 $s->ok('auth login simple'); |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
108 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
109 # auth login with username |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
110 |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
111 $s = Test::Nginx::POP3->new(); |
59
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
112 $s->read(); |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
113 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
114 $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
|
115 $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
|
116 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
117 $s->send(encode_base64('secret', '')); |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
118 $s->ok('auth login with username'); |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
119 |
bc3351f157ef
Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
120 ############################################################################### |