Mercurial > hg > nginx-tests
diff stream_ssl_session_reuse.t @ 1863:dbb7561a9441
Tests: reworked stream SSL tests to use IO::Socket::SSL.
Relevant infrastructure is provided in Test::Nginx::Stream. This also
ensures that SSL handshake and various read operations are guarded
with timeouts.
The stream_ssl_verify_client.t test uses IO::Socket::SSL::_get_ssl_object()
to access the Net::SSLeay object directly, as it seems to be the only
way to obtain CA list with IO::Socket::SSL. While not exactly correct,
this seems to be good enough for tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 18 May 2023 18:07:12 +0300 |
parents | df96e9d6c095 |
children | f7f1f349dd26 |
line wrap: on
line diff
--- a/stream_ssl_session_reuse.t Thu May 18 18:07:10 2023 +0300 +++ b/stream_ssl_session_reuse.t Thu May 18 18:07:12 2023 +0300 @@ -19,23 +19,17 @@ use lib 'lib'; use Test::Nginx; +use Test::Nginx::Stream qw/ stream /; ############################################################################### select STDERR; $| = 1; select STDOUT; $| = 1; -eval { - require Net::SSLeay; - Net::SSLeay::load_error_strings(); - Net::SSLeay::SSLeay_add_ssl_algorithms(); - Net::SSLeay::randomize(); -}; -plan(skip_all => 'Net::SSLeay not installed') if $@; +my $t = Test::Nginx->new()->has(qw/stream stream_ssl socket_ssl_sslversion/) + ->has_daemon('openssl')->plan(7); -my $t = Test::Nginx->new()->has(qw/stream stream_ssl/)->has_daemon('openssl'); - -$t->plan(7)->write_file_expand('nginx.conf', <<'EOF'); +$t->write_file_expand('nginx.conf', <<'EOF'); %%TEST_GLOBALS%% @@ -124,8 +118,6 @@ or die "Can't create certificate for $name: $!\n"; } -my $ctx = Net::SSLeay::CTX_new() or die("Failed to create SSL_CTX $!"); - $t->run_daemon(\&http_daemon); $t->run(); @@ -145,6 +137,10 @@ # - only cache off TODO: { +local $TODO = 'no TLSv1.3 sessions, old Net::SSLeay' + if $Net::SSLeay::VERSION < 1.88 && test_tls13(); +local $TODO = 'no TLSv1.3 sessions, old IO::Socket::SSL' + if $IO::Socket::SSL::VERSION < 2.061 && test_tls13(); local $TODO = 'no TLSv1.3 sessions in LibreSSL' if $t->has_module('LibreSSL') && test_tls13(); @@ -168,29 +164,30 @@ ############################################################################### sub test_tls13 { - my ($s, $ssl) = get_ssl_socket(8443); - return (Net::SSLeay::version($ssl) > 0x303); + my $s = stream( + PeerAddr => '127.0.0.1:' . port(8443), + SSL => 1 + ); + return ($s->socket()->get_sslversion_int() > 0x303); } sub test_reuse { my ($port) = @_; - my ($s, $ssl) = get_ssl_socket($port); - Net::SSLeay::write($ssl, "GET / HTTP/1.0$CRLF$CRLF"); - Net::SSLeay::read($ssl); - my $ses = Net::SSLeay::get_session($ssl); - ($s, $ssl) = get_ssl_socket($port, $ses); - return Net::SSLeay::session_reused($ssl); -} + + my $s = stream( + PeerAddr => '127.0.0.1:' . port($port), + SSL => 1, + SSL_session_cache_size => 100 + ); + $s->io("GET / HTTP/1.0$CRLF$CRLF"); -sub get_ssl_socket { - my ($port, $ses) = @_; + $s = stream( + PeerAddr => '127.0.0.1:' . port($port), + SSL => 1, + SSL_reuse_ctx => $s->socket() + ); - my $s = IO::Socket::INET->new('127.0.0.1:' . port($port)); - my $ssl = Net::SSLeay::new($ctx) or die("Failed to create SSL $!"); - Net::SSLeay::set_session($ssl, $ses) if defined $ses; - Net::SSLeay::set_fd($ssl, fileno($s)); - Net::SSLeay::connect($ssl) or die("ssl connect"); - return ($s, $ssl); + return $s->socket()->get_session_reused(); } ###############################################################################