Mercurial > hg > nginx-tests
comparison mail_resolver.t @ 1496:e1eb3432487b
Tests: added mail resolver tests with ssl.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 01 Aug 2019 14:22:46 +0300 |
parents | 1356e7374c57 |
children | 74986ebee2fd |
comparison
equal
deleted
inserted
replaced
1495:b8b92ed90485 | 1496:e1eb3432487b |
---|---|
21 ############################################################################### | 21 ############################################################################### |
22 | 22 |
23 select STDERR; $| = 1; | 23 select STDERR; $| = 1; |
24 select STDOUT; $| = 1; | 24 select STDOUT; $| = 1; |
25 | 25 |
26 eval { require IO::Socket::SSL; }; | |
27 plan(skip_all => 'IO::Socket::SSL not installed') if $@; | |
28 eval { IO::Socket::SSL::SSL_VERIFY_NONE(); }; | |
29 plan(skip_all => 'IO::Socket::SSL too old') if $@; | |
30 | |
26 local $SIG{PIPE} = 'IGNORE'; | 31 local $SIG{PIPE} = 'IGNORE'; |
27 | 32 |
28 my $t = Test::Nginx->new()->has(qw/mail smtp http rewrite/)->plan(10) | 33 my $t = Test::Nginx->new()->has(qw/mail mail_ssl smtp http rewrite/) |
34 ->has_daemon('openssl')->plan(11) | |
29 ->write_file_expand('nginx.conf', <<'EOF'); | 35 ->write_file_expand('nginx.conf', <<'EOF'); |
30 | 36 |
31 %%TEST_GLOBALS%% | 37 %%TEST_GLOBALS%% |
32 | 38 |
33 daemon off; | 39 daemon off; |
87 listen 127.0.0.1:8032; | 93 listen 127.0.0.1:8032; |
88 protocol smtp; | 94 protocol smtp; |
89 resolver 127.0.0.1:%%PORT_8987_UDP%%; | 95 resolver 127.0.0.1:%%PORT_8987_UDP%%; |
90 } | 96 } |
91 | 97 |
98 server { | |
99 ssl_certificate_key localhost.key; | |
100 ssl_certificate localhost.crt; | |
101 | |
102 listen 127.0.0.1:8033 ssl; | |
103 protocol smtp; | |
104 resolver 127.0.0.1:%%PORT_8983_UDP%%; | |
105 } | |
92 } | 106 } |
93 | 107 |
94 http { | 108 http { |
95 %%TEST_GLOBALS_HTTP%% | 109 %%TEST_GLOBALS_HTTP%% |
96 | 110 |
113 } | 127 } |
114 } | 128 } |
115 | 129 |
116 EOF | 130 EOF |
117 | 131 |
132 $t->write_file('openssl.conf', <<EOF); | |
133 [ req ] | |
134 default_bits = 2048 | |
135 encrypt_key = no | |
136 distinguished_name = req_distinguished_name | |
137 [ req_distinguished_name ] | |
138 EOF | |
139 | |
140 my $d = $t->testdir(); | |
141 | |
142 foreach my $name ('localhost') { | |
143 system('openssl req -x509 -new ' | |
144 . "-config $d/openssl.conf -subj /CN=$name/ " | |
145 . "-out $d/$name.crt -keyout $d/$name.key " | |
146 . ">>$d/openssl.out 2>&1") == 0 | |
147 or die "Can't create certificate for $name: $!\n"; | |
148 } | |
149 | |
118 $t->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon); | 150 $t->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon); |
119 $t->run_daemon(\&dns_daemon, port($_), $t) foreach (8981 .. 8987); | 151 $t->run_daemon(\&dns_daemon, port($_), $t) foreach (8981 .. 8987); |
120 | 152 |
121 $t->run(); | 153 $t->run(); |
122 | 154 |
257 $s->send('RCPT TO:<test@example.com>'); | 289 $s->send('RCPT TO:<test@example.com>'); |
258 $s->ok('CNAME with PTR'); | 290 $s->ok('CNAME with PTR'); |
259 | 291 |
260 $s->send('QUIT'); | 292 $s->send('QUIT'); |
261 $s->read(); | 293 $s->read(); |
294 | |
295 # before 1.17.3, read event while in resolving resulted in duplicate resolving | |
296 | |
297 TODO: { | |
298 todo_skip 'leaves coredump', 1 unless $ENV{TEST_NGINX_UNSAFE} | |
299 or $t->has_version('1.17.3'); | |
300 | |
301 my %ssl = ( | |
302 SSL => 1, | |
303 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(), | |
304 SSL_error_trap => sub { die $_[1] }, | |
305 ); | |
306 | |
307 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8033), %ssl); | |
308 $s->send('EHLO example.com'); | |
309 $s->read(); | |
310 $s->send('MAIL FROM:<test@example.com> SIZE=100'); | |
311 $s->read(); | |
312 $s->read(); | |
313 | |
314 $s->send('RCPT TO:<test@example.com>'); | |
315 $s->check(qr/TEMPUNAVAIL/, 'PTR SSL empty'); | |
316 | |
317 $s->send('QUIT'); | |
318 $s->read(); | |
319 | |
320 } | |
262 | 321 |
263 ############################################################################### | 322 ############################################################################### |
264 | 323 |
265 sub reply_handler { | 324 sub reply_handler { |
266 my ($recv_data, $port) = @_; | 325 my ($recv_data, $port) = @_; |