summaryrefslogtreecommitdiffstats
path: root/t/08-tls.t
diff options
context:
space:
mode:
authorMurilo Ijanc <[email protected]>2026-07-26 14:40:05 -0300
committerMurilo Ijanc <[email protected]>2026-07-26 14:40:05 -0300
commit0bc578d6d334c7f1ccaf329cd61bb8bce76b7f59 (patch)
tree86f73108f0432fd8330edcaab8b8ae7018322dee /t/08-tls.t
downloadperl-0bc578d6d334c7f1ccaf329cd61bb8bce76b7f59.tar.gz
Initial importv0.1.0
Diffstat (limited to 't/08-tls.t')
-rw-r--r--t/08-tls.t58
1 files changed, 58 insertions, 0 deletions
diff --git a/t/08-tls.t b/t/08-tls.t
new file mode 100644
index 0000000..950fef3
--- /dev/null
+++ b/t/08-tls.t
@@ -0,0 +1,58 @@
+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();