Skip to content

Commit 3daf08a

Browse files
committed
Tests: moved $ssl_server_name tests in http to ssl_sni.t.
The tests need appropriate checks for ancient IO::Socket::SSL versions.
1 parent 8e6c78f commit 3daf08a

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

ssl.t

+1-26
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(25);
34+
->has_daemon('openssl')->plan(23);
3535

3636
$t->write_file_expand('nginx.conf', <<'EOF');
3737
@@ -62,9 +62,6 @@ 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-
}
6865
location /id {
6966
return 200 "body $ssl_session_id";
7067
}
@@ -227,27 +224,6 @@ like(get('/', 8083), qr/^body \.$/m, 'session not reused 1');
227224
like(get('/', 8084), qr/^body \.$/m, 'reused off initial session');
228225
like(get('/', 8084), qr/^body \.$/m, 'session not reused 2');
229226

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-
251227
# ssl certificate inheritance
252228

253229
my $s = get_ssl_socket($ctx, port(8081));
@@ -331,7 +307,6 @@ sub get_ssl_socket {
331307
PeerPort => $port,
332308
SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
333309
SSL_reuse_ctx => $ctx,
334-
SSL_hostname => 'localhost',
335310
SSL_error_trap => sub { die $_[1] },
336311
%extra
337312
);

ssl_sni.t

+34-3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ http {
5959
return 200 $server_name;
6060
}
6161
}
62+
63+
server {
64+
listen 127.0.0.1:8081 ssl;
65+
server_name localhost;
66+
67+
ssl_certificate_key localhost.key;
68+
ssl_certificate localhost.crt;
69+
70+
location / {
71+
return 200 $ssl_session_reused:$ssl_server_name;
72+
}
73+
}
6274
}
6375
6476
EOF
@@ -80,7 +92,7 @@ eval {
8092
};
8193
plan(skip_all => 'Net::SSLeay with OpenSSL SNI support required') if $@;
8294

83-
$t->plan(6);
95+
$t->plan(8);
8496

8597
$t->write_file('openssl.conf', <<EOF);
8698
[ req ]
@@ -124,10 +136,28 @@ like(https_get_host('example.org', 'example.com'), qr!400 Bad Request!,
124136

125137
}
126138

139+
# $ssl_server_name in sessions
140+
141+
my $ctx = new IO::Socket::SSL::SSL_Context(
142+
SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
143+
SSL_session_cache_size => 100);
144+
145+
like(http_get('/', socket => get_ssl_socket('localhost', 8081, $ctx)),
146+
qr/^\.:localhost$/m, 'ssl server name');
147+
148+
TODO: {
149+
local $TODO = 'not yet' if $t->has_module('OpenSSL (1.1.1|3)')
150+
&& !$t->has_version('1.15.10');
151+
152+
like(http_get('/', socket => get_ssl_socket('localhost', 8081, $ctx)),
153+
qr/^r:localhost$/m, 'ssl server name - reused');
154+
155+
}
156+
127157
###############################################################################
128158

129159
sub get_ssl_socket {
130-
my ($host) = @_;
160+
my ($host, $port, $ctx) = @_;
131161
my $s;
132162

133163
eval {
@@ -136,8 +166,9 @@ sub get_ssl_socket {
136166
alarm(8);
137167
$s = IO::Socket::SSL->new(
138168
Proto => 'tcp',
139-
PeerAddr => '127.0.0.1:' . port(8080),
169+
PeerAddr => '127.0.0.1:' . port($port || 8080),
140170
SSL_hostname => $host,
171+
SSL_reuse_ctx => $ctx,
141172
SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
142173
SSL_error_trap => sub { die $_[1] }
143174
);

0 commit comments

Comments
 (0)