comparison mail_ssl.t @ 1742:7bfa47410cc0

Tests: basic ALPN tests in the mail module.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 21 Oct 2021 13:56:16 +0300
parents fd440d324700
children 2318ed01ce53
comparison
equal deleted inserted replaced
1741:3408029c09f5 1742:7bfa47410cc0
31 Net::SSLeay::SSLeay_add_ssl_algorithms(); 31 Net::SSLeay::SSLeay_add_ssl_algorithms();
32 Net::SSLeay::randomize(); 32 Net::SSLeay::randomize();
33 }; 33 };
34 plan(skip_all => 'Net::SSLeay not installed') if $@; 34 plan(skip_all => 'Net::SSLeay not installed') if $@;
35 35
36 eval { exists &Net::SSLeay::P_alpn_selected or die; };
37 plan(skip_all => 'Net::SSLeay with OpenSSL ALPN support required') if $@;
38
36 my $t = Test::Nginx->new()->has(qw/mail mail_ssl imap pop3 smtp/) 39 my $t = Test::Nginx->new()->has(qw/mail mail_ssl imap pop3 smtp/)
37 ->has_daemon('openssl')->plan(20); 40 ->has_daemon('openssl')->plan(22);
38 41
39 $t->write_file_expand('nginx.conf', <<'EOF'); 42 $t->write_file_expand('nginx.conf', <<'EOF');
40 43
41 %%TEST_GLOBALS%% 44 %%TEST_GLOBALS%%
42 45
208 like(Net::SSLeay::dump_peer_certificate($ssl), qr/CN=localhost/, 'CN'); 211 like(Net::SSLeay::dump_peer_certificate($ssl), qr/CN=localhost/, 'CN');
209 212
210 ($s, $ssl) = get_ssl_socket(8148); 213 ($s, $ssl) = get_ssl_socket(8148);
211 like(Net::SSLeay::dump_peer_certificate($ssl), qr/CN=inherits/, 'CN inner'); 214 like(Net::SSLeay::dump_peer_certificate($ssl), qr/CN=inherits/, 'CN inner');
212 215
216 # alpn
217
218 ok(get_ssl_socket(8148, undef, ['imap']), 'alpn');
219
220 TODO: {
221 local $TODO = 'not yet' unless $t->has_version('1.21.4');
222
223 ok(!get_ssl_socket(8148, undef, ['unknown']), 'alpn rejected');
224
225 }
226
213 # starttls imap 227 # starttls imap
214 228
215 $s = Test::Nginx::IMAP->new(PeerAddr => '127.0.0.1:' . port(8149)); 229 $s = Test::Nginx::IMAP->new(PeerAddr => '127.0.0.1:' . port(8149));
216 $s->read(); 230 $s->read();
217 231
289 $s->ok('smtp starttls only'); 303 $s->ok('smtp starttls only');
290 304
291 ############################################################################### 305 ###############################################################################
292 306
293 sub get_ssl_socket { 307 sub get_ssl_socket {
294 my ($port, $ses) = @_; 308 my ($port, $ses, $alpn) = @_;
295 309
296 my $s = IO::Socket::INET->new('127.0.0.1:' . port($port)); 310 my $s = IO::Socket::INET->new('127.0.0.1:' . port($port));
297 my $ssl = Net::SSLeay::new($ctx) or die("Failed to create SSL $!"); 311 my $ssl = Net::SSLeay::new($ctx) or die("Failed to create SSL $!");
298 Net::SSLeay::set_session($ssl, $ses) if defined $ses; 312 Net::SSLeay::set_session($ssl, $ses) if defined $ses;
313 Net::SSLeay::set_alpn_protos($ssl, $alpn) if defined $alpn;
299 Net::SSLeay::set_fd($ssl, fileno($s)); 314 Net::SSLeay::set_fd($ssl, fileno($s));
300 Net::SSLeay::connect($ssl) or die("ssl connect"); 315 Net::SSLeay::connect($ssl) == 1 or return;
301 return ($s, $ssl); 316 return ($s, $ssl);
302 } 317 }
303 318
304 ############################################################################### 319 ###############################################################################