view stream_udp_stream.t @ 1571:1b4ceab9cb1c

Tests: fixed ssl_certificate.t with LibreSSL client. Net::SSLeay::connect() that manages TLS handshake could return unexpected error when receiving server alert, as seen in server certificate tests if it could not been selected. Typically, it returns the expected error -1, but with certain libssl implementations it can be 0, as explained below. The error is propagated from libssl's SSL_connect(), which is usually -1. In modern OpenSSL versions, it is the default error code used in the state machine returned when something went wrong with parsing TLS message header. In versions up to OpenSSL 1.0.2, with SSLv23_method() used by default, -1 is the only error code in the ssl_connect() method implementation which is used as well if receiving alert while parsing ServerHello. BoringSSL also seems to return -1. But it is not so with LibreSSL that returns zero. Previously, tests failed with client built with LibreSSL with SSLv3 removed. Here, the error is propagated directly from ssl_read_bytes() method, which is always implemented as ssl3_read_bytes() in all TLS methods. It could be also seen with OpenSSL up to 1.0.2 with non-default methods explicitly set.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 29 May 2020 23:10:20 +0300
parents 144c6ce732e4
children f3ba4c74de31
line wrap: on
line source

#!/usr/bin/perl

# (C) Nginx, Inc.

# Tests for UDP stream.

###############################################################################

use warnings;
use strict;

use Test::More;

BEGIN { use FindBin; chdir($FindBin::Bin); }

use lib 'lib';
use Test::Nginx;
use Test::Nginx::Stream qw/ dgram /;

###############################################################################

select STDERR; $| = 1;
select STDOUT; $| = 1;

my $t = Test::Nginx->new()->has(qw/stream stream_return udp/)->plan(8)
	->write_file_expand('nginx.conf', <<'EOF');

%%TEST_GLOBALS%%

daemon off;

events {
}

stream {
    proxy_timeout   1s;

    server {
        listen      127.0.0.1:%%PORT_8980_UDP%% udp;
        proxy_pass  127.0.0.1:%%PORT_8981_UDP%%;
    }

    server {
        listen      127.0.0.1:%%PORT_8981_UDP%% udp;
        return      $remote_port;
    }
}

EOF

$t->run();

###############################################################################

my $s = dgram('127.0.0.1:' . port(8980));
my $data = $s->io('1', read_timeout => 0.5);
isnt($data, '', 'udp_stream response 1');

my $s2 = dgram('127.0.0.1:' . port(8980));
my $data2 = $s2->io('1', read_timeout => 0.5);
isnt($data2, '', 'udp_stream response 2');

isnt($data, $data2, 'udp_stream two sessions');

is($s->io('1'), $data, 'udp_stream session 1');
is($s->io('1'), $data, 'udp_stream session 2');

is($s2->io('1'), $data2, 'udp_stream another session 1');
is($s2->io('1'), $data2, 'udp_stream another session 2');

select undef, undef, undef, 1.1;

isnt($s->io('1'), $data, 'udp_stream new session');

###############################################################################