Commit c753a31e authored by David Golden's avatar David Golden

enhance can_ssl to check object with SSL parametes

parent 5ac67e38
......@@ -87,6 +87,8 @@ BEGIN {
}
sub can_ssl {
my ($self) = @_;
my($ok, $reason) = (1, '');
# Need IO::Socket::SSL 1.42 for SSL_create_ctx_callback
......@@ -101,6 +103,18 @@ sub can_ssl {
$reason .= qq/Net::SSLeay 1.49 must be installed for https support\n/;
}
# If an object, check that SSL config lets us get a CA if necessary
if ( ref $self && $self->{verify_SSL} ) {
my $handle = HTTP::Tiny::Handle->new(
SSL_options => $self->{SSL_options},
verify_SSL => $self->{verify_SSL},
);
unless ( eval { $handle->_find_CA_file; 1} ) {
$ok = 0;
$reason .= "$@";
}
}
wantarray ? ($ok, $reason) : $ok;
}
......@@ -1380,7 +1394,7 @@ sub can_write {
}
sub _assert_ssl {
my($ok, $reason) = HTTP::Tiny::can_ssl();
my($ok, $reason) = HTTP::Tiny->can_ssl();
die $reason unless $ok;
}
......
......@@ -53,7 +53,21 @@ my $data = {
default_should_yield => '',
}
};
plan tests => scalar keys %$data;
plan tests => 1+ scalar keys %$data;
subtest "can_ssl" => sub {
ok( HTTP::Tiny->can_ssl, "class method" );
ok( HTTP::Tiny->new->can_ssl, "object method, default params" );
ok( HTTP::Tiny->new(verify_SSL => 1)->can_ssl, "object method, verify_SSL" );
my $ht = HTTP::Tiny->new(
verify_SSL => 1,
SSL_options => { SSL_ca_file => 'adlfadkfadlfad' },
);
my ($ok, $why) = $ht->can_ssl;
ok( ! $ok, "object methods, verify_SSL, bogus CA file (FAILS)" );
like( $why, qr/not found or not readable/, "failure reason" );
};
while (my ($url, $data) = each %$data) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment