Mercurial > hg > nginx-tests
annotate mail_capability.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 | ce4a06d72256 |
children |
rev | line source |
---|---|
1146
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for imap/pop3/smtp capabilities. |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx::IMAP; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx::POP3; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 use Test::Nginx::SMTP; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 ############################################################################### |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDERR; $| = 1; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 select STDOUT; $| = 1; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
1856
ce4a06d72256
Tests: SIGPIPE handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1488
diff
changeset
|
28 local $SIG{PIPE} = 'IGNORE'; |
ce4a06d72256
Tests: SIGPIPE handling in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1488
diff
changeset
|
29 |
1146
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 my $t = Test::Nginx->new()->has(qw/mail mail_ssl imap pop3 smtp/) |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 ->has_daemon('openssl')->plan(17); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 $t->write_file_expand('nginx.conf', <<'EOF'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 %%TEST_GLOBALS%% |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 daemon off; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 events { |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 } |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 mail { |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 ssl_certificate_key localhost.key; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 ssl_certificate localhost.crt; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 auth_http http://127.0.0.1:8080; # unused |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 pop3_auth plain apop cram-md5; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 server { |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 listen 127.0.0.1:8143; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 protocol imap; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 imap_capabilities SEE-THIS; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 } |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 server { |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 listen 127.0.0.1:8144; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 protocol imap; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 starttls on; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 } |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 server { |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 listen 127.0.0.1:8145; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 protocol imap; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 starttls only; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 } |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 server { |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 listen 127.0.0.1:8110; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 protocol pop3; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 } |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 server { |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 listen 127.0.0.1:8111; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 protocol pop3; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 starttls on; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 } |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 server { |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 listen 127.0.0.1:8112; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 protocol pop3; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 starttls only; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 } |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 server { |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 listen 127.0.0.1:8025; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 protocol smtp; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 starttls off; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 } |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 server { |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 listen 127.0.0.1:8026; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 protocol smtp; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 starttls on; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 } |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 server { |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 listen 127.0.0.1:8027; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 protocol smtp; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 starttls only; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 } |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 } |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 EOF |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 $t->write_file('openssl.conf', <<EOF); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 [ req ] |
1488
dbce8fb5f5f8
Tests: align with OpenSSL security level 2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
108 default_bits = 2048 |
1146
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 encrypt_key = no |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 distinguished_name = req_distinguished_name |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 [ req_distinguished_name ] |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 EOF |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 my $d = $t->testdir(); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 foreach my $name ('localhost') { |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 system('openssl req -x509 -new ' |
1220
0af58b78df35
Tests: removed single quotes from system() calls.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1151
diff
changeset
|
118 . "-config $d/openssl.conf -subj /CN=$name/ " |
0af58b78df35
Tests: removed single quotes from system() calls.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1151
diff
changeset
|
119 . "-out $d/$name.crt -keyout $d/$name.key " |
1146
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 . ">>$d/openssl.out 2>&1") == 0 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 or die "Can't create certificate for $name: $!\n"; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 } |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 $t->run(); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 ############################################################################### |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 # imap, custom capabilities |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 my $s = Test::Nginx::IMAP->new(); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 $s->read(); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 $s->send('1 CAPABILITY'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 $s->check(qr/^\* CAPABILITY SEE-THIS AUTH=PLAIN/, 'imap capability'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 $s->ok('imap capability completed'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 # imap starttls |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 $s = Test::Nginx::IMAP->new(PeerAddr => '127.0.0.1:' . port(8144)); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 $s->read(); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 $s->send('1 CAPABILITY'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 $s->check(qr/^\* CAPABILITY IMAP4 IMAP4rev1 UIDPLUS AUTH=PLAIN STARTTLS/, |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 'imap capability starttls'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 # imap starttls only |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 $s = Test::Nginx::IMAP->new(PeerAddr => '127.0.0.1:' . port(8145)); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 $s->read(); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 $s->send('1 CAPABILITY'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 $s->check(qr/^\* CAPABILITY IMAP4 IMAP4rev1 UIDPLUS STARTTLS LOGINDISABLED/, |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 'imap capability starttls only'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 # pop3 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 $s = Test::Nginx::POP3->new(PeerAddr => '127.0.0.1:' . port(8110)); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 $s->read(); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 $s->send('CAPA'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 $s->ok('pop3 capa'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 my $caps = get_auth_caps($s); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 like($caps, qr/USER/, 'pop3 - user'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 like($caps, qr/SASL (PLAIN LOGIN|LOGIN PLAIN) CRAM-MD5/, 'pop3 - methods'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 unlike($caps, qr/STLS/, 'pop3 - no stls'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 # pop3 starttls |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 $s = Test::Nginx::POP3->new(PeerAddr => '127.0.0.1:' . port(8111)); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 $s->read(); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 $s->send('CAPA'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 $caps = get_auth_caps($s); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 like($caps, qr/USER/, 'pop3 starttls - user'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 like($caps, qr/SASL (PLAIN LOGIN|LOGIN PLAIN) CRAM-MD5/, |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 'pop3 starttls - methods'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 like($caps, qr/STLS/, 'pop3 startls - stls'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 # pop3 starttls only |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 $s = Test::Nginx::POP3->new(PeerAddr => '127.0.0.1:' . port(8112)); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
184 $s->read(); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
186 $s->send('CAPA'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
187 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 $caps = get_auth_caps($s); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 unlike($caps, qr/USER/, 'pop3 starttls only - no user'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
190 unlike($caps, qr/SASL/, 'pop3 starttls only - no methods'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
191 like($caps, qr/STLS/, 'pop3 startls only - stls'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
192 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
193 # smtp |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
194 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
195 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8025)); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
196 $s->read(); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
197 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
198 $s->send('EHLO example.com'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
199 $s->check(qr/^250 AUTH PLAIN LOGIN\x0d\x0a?/, 'smtp ehlo'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
200 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
201 # smtp starttls |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
202 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
203 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8026)); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
204 $s->read(); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
205 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
206 $s->send('EHLO example.com'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
207 $s->check(qr/^250 STARTTLS/, 'smtp ehlo - starttls'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
208 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
209 # smtp starttls only |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
210 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
211 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8027)); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
212 $s->read(); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
213 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
214 $s->send('EHLO example.com'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
215 $s->check(qr/^250 STARTTLS/, 'smtp ehlo - starttls only'); |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
216 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
217 ############################################################################### |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
218 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
219 sub get_auth_caps { |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
220 my ($s) = @_; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
221 my @meth; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
222 |
1151
57673c7257a3
Tests: unbreak mail tests in case of EOF.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1146
diff
changeset
|
223 while ($s->read()) { |
57673c7257a3
Tests: unbreak mail tests in case of EOF.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1146
diff
changeset
|
224 last if /^\./; |
1146
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
225 push @meth, $1 if /(.*?)\x0d\x0a?/ms; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
226 } |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
227 join ':', @meth; |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
228 } |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
229 |
2634d0ef48d3
Tests: mail capability tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
230 ############################################################################### |