Skip to content

Commit 7ef3ddc

Browse files
committed
Tests: added has_feature() tests for IO::Socket::SSL.
The following distinct features supported: - "socket_ssl", which requires IO::Socket::SSL and also implies existance of the IO::Socket::SSL::SSL_VERIFY_NONE() symbol. It is used by most of the tests. - "socket_ssl_sni", which requires IO::Socket::SSL with the can_client_sni() function (1.84), and SNI support available in Net::SSLeay and the OpenSSL library being used. Used by ssl_sni.t, ssl_sni_sessions.t, stream_ssl_preread.t. Additional Net::SSLeay testing is believed to be unneeded and was removed. - "socket_ssl_alpn", which requires IO::Socket::SSL with ALPN support (2.009), and ALPN support in Net::SSLeay and the OpenSSL library being used. Used by h2_ssl.t, h2_ssl_verify_client.t, stream_ssl_alpn.t, stream_ssl_preread_alpn.t. - "socket_ssl_sslversion", which requires IO::Socket::SSL with the get_sslversion() and get_sslversion_int() methods (1.964). Used by mail_imap_ssl.t. - "socket_ssl_reused", which requires IO::Socket::SSL with the get_session_reused() method (2.057). To be used in the following patches. This makes it possible to simplify and unify various SSL tests.
1 parent 1348a82 commit 7ef3ddc

27 files changed

+74
-224
lines changed

h2_ssl.t

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use Test::Nginx::HTTP2;
2525
select STDERR; $| = 1;
2626
select STDOUT; $| = 1;
2727

28-
my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2/)
28+
my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 socket_ssl_alpn/)
2929
->has_daemon('openssl');
3030

3131
$t->write_file_expand('nginx.conf', <<'EOF');
@@ -55,15 +55,6 @@ http {
5555
5656
EOF
5757

58-
eval { require IO::Socket::SSL; die if $IO::Socket::SSL::VERSION < 1.56; };
59-
plan(skip_all => 'IO::Socket::SSL version >= 1.56 required') if $@;
60-
61-
eval { IO::Socket::SSL->can_alpn() or die; };
62-
plan(skip_all => 'IO::Socket::SSL with OpenSSL ALPN support required') if $@;
63-
64-
eval { exists &Net::SSLeay::P_alpn_selected or die; };
65-
plan(skip_all => 'Net::SSLeay with OpenSSL ALPN support required') if $@;
66-
6758
$t->write_file('openssl.conf', <<EOF);
6859
[ req ]
6960
default_bits = 2048

h2_ssl_proxy_cache.t

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ use Test::Nginx::HTTP2;
2323
select STDERR; $| = 1;
2424
select STDOUT; $| = 1;
2525

26-
eval { require IO::Socket::SSL; };
27-
plan(skip_all => 'IO::Socket::SSL not installed') if $@;
28-
29-
my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 proxy cache/)
26+
my $t = Test::Nginx->new()
27+
->has(qw/http http_ssl http_v2 proxy cache socket_ssl/)
3028
->has_daemon('openssl');
3129

3230
$t->write_file_expand('nginx.conf', <<'EOF');

h2_ssl_variables.t

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ use Test::Nginx::HTTP2;
2323
select STDERR; $| = 1;
2424
select STDOUT; $| = 1;
2525

26-
eval { require IO::Socket::SSL; };
27-
plan(skip_all => 'IO::Socket::SSL not installed') if $@;
28-
eval { IO::Socket::SSL::SSL_VERIFY_NONE(); };
29-
plan(skip_all => 'IO::Socket::SSL too old') if $@;
30-
31-
my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 rewrite/)
26+
my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 rewrite socket_ssl/)
3227
->has_daemon('openssl')->plan(8);
3328

3429
$t->write_file_expand('nginx.conf', <<'EOF');

h2_ssl_verify_client.t

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,7 @@ use Test::Nginx::HTTP2;
2323
select STDERR; $| = 1;
2424
select STDOUT; $| = 1;
2525

26-
eval { require IO::Socket::SSL; };
27-
plan(skip_all => 'IO::Socket::SSL not installed') if $@;
28-
eval { IO::Socket::SSL->can_client_sni() or die; };
29-
plan(skip_all => 'IO::Socket::SSL with OpenSSL SNI support required') if $@;
30-
eval { IO::Socket::SSL->can_alpn() or die; };
31-
plan(skip_all => 'OpenSSL ALPN support required') if $@;
32-
33-
my $t = Test::Nginx->new()->has(qw/http http_ssl sni http_v2/)
26+
my $t = Test::Nginx->new()->has(qw/http http_ssl sni http_v2 socket_ssl_alpn/)
3427
->has_daemon('openssl');
3528

3629
$t->write_file_expand('nginx.conf', <<'EOF');

lib/Test/Nginx.pm

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,31 @@ sub has_feature($) {
241241
return $^O ne 'MSWin32';
242242
}
243243

244+
if ($feature =~ /^socket_ssl/) {
245+
eval { require IO::Socket::SSL; };
246+
return 0 if $@;
247+
eval { IO::Socket::SSL::SSL_VERIFY_NONE(); };
248+
return 0 if $@;
249+
if ($feature eq 'socket_ssl') {
250+
return 1;
251+
}
252+
if ($feature eq 'socket_ssl_sni') {
253+
eval { IO::Socket::SSL->can_client_sni() or die; };
254+
return !$@;
255+
}
256+
if ($feature eq 'socket_ssl_alpn') {
257+
eval { IO::Socket::SSL->can_alpn() or die; };
258+
return !$@;
259+
}
260+
if ($feature eq 'socket_ssl_sslversion') {
261+
return IO::Socket::SSL->can('get_sslversion');
262+
}
263+
if ($feature eq 'socket_ssl_reused') {
264+
return IO::Socket::SSL->can('get_session_reused');
265+
}
266+
return 0;
267+
}
268+
244269
return 0;
245270
}
246271

mail_imap_ssl.t

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,10 @@ use Test::Nginx::IMAP;
2626
select STDERR; $| = 1;
2727
select STDOUT; $| = 1;
2828

29-
eval { require IO::Socket::SSL; };
30-
plan(skip_all => 'IO::Socket::SSL not installed') if $@;
31-
eval { IO::Socket::SSL::SSL_VERIFY_NONE(); };
32-
plan(skip_all => 'IO::Socket::SSL too old') if $@;
33-
3429
local $SIG{PIPE} = 'IGNORE';
3530

36-
my $t = Test::Nginx->new()->has(qw/mail mail_ssl imap http rewrite/)
31+
my $t = Test::Nginx->new()
32+
->has(qw/mail mail_ssl imap http rewrite socket_ssl_sslversion/)
3733
->has_daemon('openssl')->plan(13)
3834
->write_file_expand('nginx.conf', <<'EOF');
3935
@@ -215,12 +211,10 @@ $s->read();
215211

216212
my ($cipher, $sslversion);
217213

218-
if ($IO::Socket::SSL::VERSION >= 1.964) {
219-
$s = get_ssl_socket(8143);
220-
$cipher = $s->get_cipher();
221-
$sslversion = $s->get_sslversion();
222-
$sslversion =~ s/_/./;
223-
}
214+
$s = get_ssl_socket(8143);
215+
$cipher = $s->get_cipher();
216+
$sslversion = $s->get_sslversion();
217+
$sslversion =~ s/_/./;
224218

225219
undef $s;
226220

@@ -239,10 +233,6 @@ like($f, qr!^on:SUCCESS:(/?CN=2.example.com):\1:\w+:\w+:[^:]+:s4$!m,
239233
like($f, qr!^on:SUCCESS:(/?CN=3.example.com):\1:\w+:\w+:[^:]+:s5$!m,
240234
'log - trusted cert');
241235

242-
SKIP: {
243-
skip 'IO::Socket::SSL version >= 1.964 required', 1
244-
if $IO::Socket::SSL::VERSION < 1.964;
245-
246236
TODO: {
247237
local $TODO = 'not yet' unless $t->has_version('1.21.2');
248238

@@ -251,8 +241,6 @@ like($f, qr|^$cipher:$sslversion$|m, 'log - cipher sslversion');
251241

252242
}
253243

254-
}
255-
256244
###############################################################################
257245

258246
sub get_ssl_socket {

mail_resolver.t

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,9 @@ use Test::Nginx::SMTP;
2323
select STDERR; $| = 1;
2424
select STDOUT; $| = 1;
2525

26-
eval { require IO::Socket::SSL; };
27-
plan(skip_all => 'IO::Socket::SSL not installed') if $@;
28-
eval { IO::Socket::SSL::SSL_VERIFY_NONE(); };
29-
plan(skip_all => 'IO::Socket::SSL too old') if $@;
30-
3126
local $SIG{PIPE} = 'IGNORE';
3227

33-
my $t = Test::Nginx->new()->has(qw/mail mail_ssl smtp http rewrite/)
28+
my $t = Test::Nginx->new()->has(qw/mail mail_ssl smtp http rewrite socket_ssl/)
3429
->has_daemon('openssl')->plan(11)
3530
->write_file_expand('nginx.conf', <<'EOF');
3631

proxy_ssl.t

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ use Test::Nginx;
2121
select STDERR; $| = 1;
2222
select STDOUT; $| = 1;
2323

24-
eval { require IO::Socket::SSL; };
25-
plan(skip_all => 'IO::Socket::SSL not installed') if $@;
26-
27-
my $t = Test::Nginx->new()->has(qw/http proxy http_ssl/)->has_daemon('openssl')
28-
->plan(8)->write_file_expand('nginx.conf', <<'EOF');
24+
my $t = Test::Nginx->new()->has(qw/http proxy http_ssl socket_ssl/)
25+
->has_daemon('openssl')->plan(8)
26+
->write_file_expand('nginx.conf', <<'EOF');
2927
3028
%%TEST_GLOBALS%%
3129

ssl.t

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ use Test::Nginx;
2525
select STDERR; $| = 1;
2626
select STDOUT; $| = 1;
2727

28-
eval { require IO::Socket::SSL; };
29-
plan(skip_all => 'IO::Socket::SSL not installed') if $@;
30-
eval { IO::Socket::SSL::SSL_VERIFY_NONE(); };
31-
plan(skip_all => 'IO::Socket::SSL too old') if $@;
32-
33-
my $t = Test::Nginx->new()->has(qw/http http_ssl rewrite proxy/)
28+
my $t = Test::Nginx->new()->has(qw/http http_ssl rewrite proxy socket_ssl/)
3429
->has_daemon('openssl')->plan(21);
3530

3631
$t->write_file_expand('nginx.conf', <<'EOF');

ssl_certificate_chain.t

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ use Test::Nginx;
2222
select STDERR; $| = 1;
2323
select STDOUT; $| = 1;
2424

25-
eval { require IO::Socket::SSL; };
26-
plan(skip_all => 'IO::Socket::SSL not installed') if $@;
27-
eval { IO::Socket::SSL::SSL_VERIFY_NONE(); };
28-
plan(skip_all => 'IO::Socket::SSL too old') if $@;
29-
30-
my $t = Test::Nginx->new()->has(qw/http http_ssl/)
25+
my $t = Test::Nginx->new()->has(qw/http http_ssl socket_ssl/)
3126
->has_daemon('openssl')->plan(3);
3227

3328
$t->write_file_expand('nginx.conf', <<'EOF');

0 commit comments

Comments
 (0)