annotate mail_imap.t @ 1974:b5036a0f9ae0 default tip

Tests: improved compatibility when using recent "openssl" app. Starting with OpenSSL 3.0, "openssl genrsa" generates encrypted keys in PKCS#8 format instead of previously used PKCS#1 format. Further, since OpenSSL 1.1.0 such keys are using PBKDF2 hmacWithSHA256. Such keys are not supported by old SSL libraries, notably by OpenSSL before 1.0.0 (OpenSSL 0.9.8 only supports hmacWithSHA1) and by BoringSSL before May 21, 2019 (support for hmacWithSHA256 was added in 302a4dee6c), and trying to load such keys into nginx compiled with an old SSL library results in "unsupported prf" errors. To facilitate testing with old SSL libraries, keys are now generated with "openssl genrsa -traditional" if the flag is available.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 06 May 2024 00:04:26 +0300
parents 2a0a6035a1af
children
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 imap 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;
1685
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
15 use Socket qw/ CRLF /;
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
16
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
17 BEGIN { use FindBin; chdir($FindBin::Bin); }
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
18
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
19 use lib 'lib';
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
20 use Test::Nginx;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21 use Test::Nginx::IMAP;
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
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
25 select STDERR; $| = 1;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
26 select STDOUT; $| = 1;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
27
96
ecff5407867c Tests: better handle unexpected connection close from nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 75
diff changeset
28 local $SIG{PIPE} = 'IGNORE';
ecff5407867c Tests: better handle unexpected connection close from nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 75
diff changeset
29
1111
6c2538ad642d Tests: auth external in mail is explicitly enabled since 1.11.9.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1110
diff changeset
30 my $t = Test::Nginx->new()->has(qw/mail imap http rewrite/)
976
a8b8dd6e8ae1 Tests: changed startup order in mail tests for consistency.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 970
diff changeset
31 ->write_file_expand('nginx.conf', <<'EOF');
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
32
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 96
diff changeset
33 %%TEST_GLOBALS%%
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 96
diff changeset
34
249
6a0d934950bc Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
35 daemon off;
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
36
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
37 events {
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
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
40 mail {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
41 proxy_pass_error_message on;
1679
74986ebee2fd Tests: added proxy_timeout in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
42 proxy_timeout 15s;
970
c227348453db Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 952
diff changeset
43 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
44
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
45 server {
970
c227348453db Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 952
diff changeset
46 listen 127.0.0.1:8143;
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
47 protocol imap;
1111
6c2538ad642d Tests: auth external in mail is explicitly enabled since 1.11.9.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1110
diff changeset
48 imap_auth plain cram-md5 external;
59
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 {
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 96
diff changeset
53 %%TEST_GLOBALS_HTTP%%
59
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 server {
970
c227348453db Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 952
diff changeset
56 listen 127.0.0.1:8080;
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
57 server_name localhost;
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 location = /mail/auth {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
60 set $reply ERROR;
1109
59d5c8ca7e4d Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 976
diff changeset
61 set $passw "";
59
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";
1685
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
64 if ($userpass = 'test@example.com:secret') {
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
65 set $reply OK;
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
66 }
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
67 if ($userpass = 'te\\"st@example.com:se\\"cret') {
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
68 set $reply OK;
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
1109
59d5c8ca7e4d Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 976
diff changeset
71 set $userpass "$http_auth_user:$http_auth_salt:$http_auth_pass";
59d5c8ca7e4d Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 976
diff changeset
72 if ($userpass ~ '^test@example.com:<.*@.*>:0{32}$') {
59d5c8ca7e4d Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 976
diff changeset
73 set $reply OK;
59d5c8ca7e4d Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 976
diff changeset
74 set $passw secret;
59d5c8ca7e4d Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 976
diff changeset
75 }
59d5c8ca7e4d Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 976
diff changeset
76
1110
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
77 set $userpass "$http_auth_method:$http_auth_user:$http_auth_pass";
1685
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
78 if ($userpass = 'external:test@example.com:') {
1110
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
79 set $reply OK;
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
80 set $passw secret;
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
81 }
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
82
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
83 add_header Auth-Status $reply;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
84 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
85 add_header Auth-Port %%PORT_8144%%;
1109
59d5c8ca7e4d Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 976
diff changeset
86 add_header Auth-Pass $passw;
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
87 add_header Auth-Wait 1;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
88 return 204;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
89 }
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 }
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 EOF
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
94
976
a8b8dd6e8ae1 Tests: changed startup order in mail tests for consistency.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 970
diff changeset
95 $t->run_daemon(\&Test::Nginx::IMAP::imap_test_daemon);
1686
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
96 $t->run()->plan(29);
1111
6c2538ad642d Tests: auth external in mail is explicitly enabled since 1.11.9.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1110
diff changeset
97
6c2538ad642d Tests: auth external in mail is explicitly enabled since 1.11.9.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1110
diff changeset
98 $t->waitforsocket('127.0.0.1:' . port(8144));
976
a8b8dd6e8ae1 Tests: changed startup order in mail tests for consistency.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 970
diff changeset
99
59
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
1685
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
102 # login
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
103
970
c227348453db Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 952
diff changeset
104 my $s = Test::Nginx::IMAP->new();
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
105 $s->ok('greeting');
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
106
1685
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
107 $s->send('a01 LOGIN');
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
108 $s->check(qr/^a01 BAD/, 'login without arguments');
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
109
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
110 $s->send('a02 LOGIN test@example.com bad');
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
111 $s->check(qr/^a02 NO/, 'login with bad password');
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
112
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
113 $s->send('a03 LOGIN test@example.com secret');
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
114 $s->ok('login');
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
115
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
116 # auth
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
117
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
118 $s = Test::Nginx::IMAP->new();
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
119 $s->read();
151
1c39b7edc593 Tests: make sure imap authenticate without arguments fails.
Maxim Dounin <mdounin@mdounin.ru>
parents: 148
diff changeset
120
1c39b7edc593 Tests: make sure imap authenticate without arguments fails.
Maxim Dounin <mdounin@mdounin.ru>
parents: 148
diff changeset
121 $s->send('1 AUTHENTICATE');
1c39b7edc593 Tests: make sure imap authenticate without arguments fails.
Maxim Dounin <mdounin@mdounin.ru>
parents: 148
diff changeset
122 $s->check(qr/^\S+ BAD/, 'auth without arguments');
1c39b7edc593 Tests: make sure imap authenticate without arguments fails.
Maxim Dounin <mdounin@mdounin.ru>
parents: 148
diff changeset
123
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
124 # auth plain
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
125
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
126 $s->send('1 AUTHENTICATE PLAIN ' . encode_base64("\0test\@example.com\0bad", ''));
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
127 $s->check(qr/^\S+ NO/, 'auth plain with bad password');
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
128
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
129 $s->send('1 AUTHENTICATE PLAIN ' . encode_base64("\0test\@example.com\0secret", ''));
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
130 $s->ok('auth plain');
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
131
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
132 # auth login simple
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
133
970
c227348453db Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 952
diff changeset
134 $s = Test::Nginx::IMAP->new();
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
135 $s->read();
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
136
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
137 $s->send('1 AUTHENTICATE LOGIN');
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
138 $s->check(qr/\+ VXNlcm5hbWU6/, 'auth login username challenge');
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
139
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
140 $s->send(encode_base64('test@example.com', ''));
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
141 $s->check(qr/\+ UGFzc3dvcmQ6/, 'auth login password challenge');
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
142
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
143 $s->send(encode_base64('secret', ''));
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
144 $s->ok('auth login simple');
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
145
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
146 # auth login with username
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
147
970
c227348453db Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 952
diff changeset
148 $s = Test::Nginx::IMAP->new();
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
149 $s->read();
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
150
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
151 $s->send('1 AUTHENTICATE LOGIN ' . encode_base64('test@example.com', ''));
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
152 $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
153
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
154 $s->send(encode_base64('secret', ''));
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
155 $s->ok('auth login with username');
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
156
1109
59d5c8ca7e4d Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 976
diff changeset
157 # auth cram-md5
59d5c8ca7e4d Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 976
diff changeset
158
59d5c8ca7e4d Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 976
diff changeset
159 $s = Test::Nginx::IMAP->new();
59d5c8ca7e4d Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 976
diff changeset
160 $s->read();
59d5c8ca7e4d Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 976
diff changeset
161
59d5c8ca7e4d Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 976
diff changeset
162 $s->send('1 AUTHENTICATE CRAM-MD5');
59d5c8ca7e4d Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 976
diff changeset
163 $s->check(qr/\+ /, 'auth cram-md5 challenge');
59d5c8ca7e4d Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 976
diff changeset
164
59d5c8ca7e4d Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 976
diff changeset
165 $s->send(encode_base64('test@example.com ' . ('0' x 32), ''));
59d5c8ca7e4d Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 976
diff changeset
166 $s->ok('auth cram-md5');
59d5c8ca7e4d Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 976
diff changeset
167
1110
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
168 # auth external
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
169
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
170 $s = Test::Nginx::IMAP->new();
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
171 $s->read();
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
172
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
173 $s->send('1 AUTHENTICATE EXTERNAL');
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
174 $s->check(qr/\+ VXNlcm5hbWU6/, 'auth external challenge');
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
175
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
176 $s->send(encode_base64('test@example.com', ''));
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
177 $s->ok('auth external');
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
178
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
179 # auth external with username
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
180
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
181 $s = Test::Nginx::IMAP->new();
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
182 $s->read();
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
183
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
184 $s->send('1 AUTHENTICATE EXTERNAL ' . encode_base64('test@example.com', ''));
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
185 $s->ok('auth external with username');
b9b115a2a28d Tests: auth external mail tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1109
diff changeset
186
1685
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
187 # quoted strings
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
188
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
189 $s = Test::Nginx::IMAP->new();
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
190 $s->read();
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
191
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
192 $s->send('a01 LOGIN "te\\\\\"st@example.com" "se\\\\\"cret"');
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
193 $s->ok('quoted strings');
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
194
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
195 # literals
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
196
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
197 $s = Test::Nginx::IMAP->new();
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
198 $s->read();
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
199
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
200 $s->send('a01 LOGIN {18}');
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
201 $s->check(qr/\+ /, 'login username literal continue');
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
202
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
203 $s->send('te\"st@example.com' . ' {8}');
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
204 $s->check(qr/\+ /, 'login password literal continue');
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
205
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
206 $s->send('se\"cret');
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
207 $s->ok('login literals');
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
208
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
209 # non-synchronizing literals
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
210
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
211 $s = Test::Nginx::IMAP->new();
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
212 $s->read();
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
213
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
214 $s->send('a01 LOGIN {18+}' . CRLF
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
215 . 'te\"st@example.com' . ' {8+}' . CRLF
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
216 . 'se\"cret');
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
217 $s->ok('login non-sync literals');
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
218
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
219 # backslash in quotes and literals
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
220
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
221 $s = Test::Nginx::IMAP->new();
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
222 $s->read();
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
223
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
224 $s->send('a01 LOGIN {18+}' . CRLF
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
225 . 'te\"st@example.com' . ' "se\\\\\"cret"');
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
226 $s->ok('backslash in literal');
869b312c214e Tests: additional IMAP tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1680
diff changeset
227
1686
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
228 # pipelining
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
229
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
230 $s = Test::Nginx::IMAP->new();
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
231 $s->read();
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
232
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
233 $s->send('a01 INVALID COMMAND WITH ARGUMENTS' . CRLF
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
234 . 'a02 NOOP');
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
235 $s->check(qr/^a01 BAD/, 'pipelined invalid command');
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
236 $s->ok('pipelined noop after invalid command');
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
237
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
238 $s->send('a03 FOOBAR {10+}' . CRLF
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
239 . 'test test ' . CRLF
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
240 . 'a04 NOOP');
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
241 $s->check(qr/^a03 BAD/, 'invalid with non-sync literal');
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
242 $s->check(qr/^(a04 |$)/, 'literal not command');
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
243
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
244 # skipped without a fix, since with level-triggered event methods
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
245 # this hogs cpu till the connection is closed by the backend server,
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
246 # and generates a lot of debug logs
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
247
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
248 $s = Test::Nginx::IMAP->new();
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
249 $s->read();
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
250
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
251 $s->send('a01 LOGIN test@example.com secret' . CRLF
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
252 . 'a02 LOGOUT');
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
253 $s->ok('pipelined login');
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
254 $s->ok('pipelined logout');
156cb84b3c23 Tests: IMAP pipelining tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1685
diff changeset
255
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
256 ###############################################################################