use strict; use warnings; use FindBin (); use lib "$FindBin::Bin/lib"; use HTTP::Tiny; use Test::More; use TestServer qw(se_address json new_client); use Time::HiRes (); use Cepis; my ($expected) = HTTP::Tiny->can('can_ssl') ? HTTP::Tiny->can_ssl : (1); my ( $ok, $why ) = Cepis::Client::tls_available(); is( !!$ok, !!$expected, 'tls_available agrees with HTTP::Tiny->can_ssl' ); SKIP: { skip 'this Perl has HTTPS support', 6 if $ok; ok( defined $why && length $why, 'the reason is reported' ); my $client = Cepis::Client->new( base_url => 'https://cep.is', max_attempts => 3, backoff_base => 30, backoff_max => 30, ); my $started = Time::HiRes::time(); my $done = eval { $client->lookup('01001000'); 1 }; my $err = $@; ok( !$done, 'an https call without TLS support throws' ); isa_ok( $err, 'Cepis::Error::Network' ); like( "$err", qr/IO::Socket::SSL/, 'the message names IO::Socket::SSL' ); like( "$err", qr/Net::SSLeay/, 'and Net::SSLeay' ); cmp_ok( Time::HiRes::time() - $started, '<', 5, 'and it fails at once rather than retrying a missing module' ); } SKIP: { skip 'this Perl has no HTTPS support', 1 unless $ok; is( $why, undef, 'no reason is reported when HTTPS works' ); } { my $server = TestServer->new( routes => { '/01001000' => [ 200, json( se_address() ), {} ] } ); my $client = new_client($server); is( $client->lookup('01001000')->uf, 'SP', 'an http base_url is never blocked by the TLS guard' ); $server->stop; } done_testing();