Skip to content

Commit fb3f4b5

Browse files
committed
Tests: added $ssl_server_name tests with SSL session reuse.
1 parent bba405c commit fb3f4b5

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

ssl.t

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ eval { IO::Socket::SSL::SSL_VERIFY_NONE(); };
3131
plan(skip_all => 'IO::Socket::SSL too old') if $@;
3232

3333
my $t = Test::Nginx->new()->has(qw/http http_ssl rewrite proxy/)
34-
->has_daemon('openssl')->plan(23);
34+
->has_daemon('openssl')->plan(25);
3535

3636
$t->write_file_expand('nginx.conf', <<'EOF');
3737
@@ -62,6 +62,9 @@ http {
6262
location /reuse {
6363
return 200 "body $ssl_session_reused";
6464
}
65+
location /sni {
66+
return 200 "body $ssl_session_reused:$ssl_server_name";
67+
}
6568
location /id {
6669
return 200 "body $ssl_session_id";
6770
}
@@ -224,6 +227,27 @@ like(get('/', 8083), qr/^body \.$/m, 'session not reused 1');
224227
like(get('/', 8084), qr/^body \.$/m, 'reused off initial session');
225228
like(get('/', 8084), qr/^body \.$/m, 'session not reused 2');
226229

230+
# ssl_server_name
231+
232+
SKIP: {
233+
skip 'no sni', 2 unless $t->has_module('sni');
234+
235+
$ctx = new IO::Socket::SSL::SSL_Context(
236+
SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
237+
SSL_session_cache_size => 100);
238+
239+
like(get('/sni', 8085), qr/^body \.:localhost$/m, 'ssl server name');
240+
241+
TODO: {
242+
local $TODO = 'not yet' if $t->has_module('OpenSSL (1.1.1|3)')
243+
&& !$t->has_version('1.15.10');
244+
245+
like(get('/sni', 8085), qr/^body r:localhost$/m, 'ssl server name - reused');
246+
247+
}
248+
249+
}
250+
227251
# ssl certificate inheritance
228252

229253
my $s = get_ssl_socket($ctx, port(8081));
@@ -307,6 +331,7 @@ sub get_ssl_socket {
307331
PeerPort => $port,
308332
SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
309333
SSL_reuse_ctx => $ctx,
334+
SSL_hostname => 'localhost',
310335
SSL_error_trap => sub { die $_[1] },
311336
%extra
312337
);

stream_ssl_variables.t

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ eval {
4040
};
4141
plan(skip_all => 'Net::SSLeay with OpenSSL SNI support required') if $@;
4242

43-
my $t = Test::Nginx->new()->has(qw/stream stream_ssl sni stream_return/)
43+
my $t = Test::Nginx->new()->has(qw/stream stream_ssl stream_return/)
4444
->has_daemon('openssl');
4545

4646
$t->write_file_expand('nginx.conf', <<'EOF');
@@ -55,13 +55,12 @@ events {
5555
stream {
5656
ssl_certificate_key localhost.key;
5757
ssl_certificate localhost.crt;
58+
ssl_session_cache builtin;
5859
5960
server {
6061
listen 127.0.0.1:8080;
6162
listen 127.0.0.1:8081 ssl;
6263
return $ssl_session_reused:$ssl_session_id:$ssl_cipher:$ssl_protocol;
63-
64-
ssl_session_cache builtin;
6564
}
6665
6766
server {
@@ -90,7 +89,7 @@ foreach my $name ('localhost') {
9089
or die "Can't create certificate for $name: $!\n";
9190
}
9291

93-
$t->run()->plan(5);
92+
$t->run()->plan(6);
9493

9594
###############################################################################
9695

@@ -107,12 +106,27 @@ my $ses = Net::SSLeay::get_session($ssl);
107106
like(Net::SSLeay::read($ssl), qr/^r:\w{64}:[\w-]+:(TLS|SSL)v(\d|\.)+$/,
108107
'ssl variables - session reused');
109108

109+
SKIP: {
110+
skip 'no sni', 3 unless $t->has_module('sni');
111+
110112
($s, $ssl) = get_ssl_socket(port(8082), undef, 'example.com');
111113
is(Net::SSLeay::ssl_read_all($ssl), 'example.com', 'ssl server name');
112114

115+
TODO: {
116+
local $TODO = 'not yet' if $t->has_module('OpenSSL (1.1.1|3)')
117+
&& !$t->has_version('1.15.10');
118+
119+
my $ses = Net::SSLeay::get_session($ssl);
120+
($s, $ssl) = get_ssl_socket(port(8082), $ses);
121+
is(Net::SSLeay::ssl_read_all($ssl), 'example.com', 'ssl server name - reused');
122+
123+
}
124+
113125
($s, $ssl) = get_ssl_socket(port(8082));
114126
is(Net::SSLeay::ssl_read_all($ssl), '', 'ssl server name empty');
115127

128+
}
129+
116130
###############################################################################
117131

118132
sub get_ssl_socket {

0 commit comments

Comments
 (0)