diff --git a/MANIFEST b/MANIFEST index c57481d..2b2c5fa 100644 --- a/MANIFEST +++ b/MANIFEST @@ -54,6 +54,7 @@ README.md SECURITY.md t/lib/Test/ACME2_Server.pm t/lib/Test/Crypt.pm +t/Net-ACME2-api-guards.t t/Net-ACME2-AccountKey.t t/Net-ACME2-Authorization.t t/Net-ACME2-Challenge-dns_01.t diff --git a/lib/Net/ACME2.pm b/lib/Net/ACME2.pm index 3fccf94..64a054b 100644 --- a/lib/Net/ACME2.pm +++ b/lib/Net/ACME2.pm @@ -1144,8 +1144,6 @@ sub _set_http { return; } -our $_POST_METHOD; - sub _post { my ( $self, $link_name, $data ) = @_; diff --git a/t/Net-ACME2-api-guards.t b/t/Net-ACME2-api-guards.t new file mode 100644 index 0000000..e10ae59 --- /dev/null +++ b/t/Net-ACME2-api-guards.t @@ -0,0 +1,115 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More; +use Test::Exception; +use Test::FailWarnings; + +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::ACME2_Server; + +#---------------------------------------------------------------------- + +{ + package MyCA; + + use parent qw( Net::ACME2 ); + + use constant { + HOST => 'acme.someca.net', + DIRECTORY_PATH => '/acme-directory', + }; +} + +my $_P256_KEY = < sub { + my $SERVER_OBJ = Test::ACME2_Server->new( + ca_class => 'MyCA', + ); + + throws_ok( + sub { MyCA->new() }, + qr/key/i, + 'new() dies without key', + ); +}; + +#---------------------------------------------------------------------- +# http_timeout() - sync mode passthrough + +subtest 'http_timeout() in sync mode' => sub { + my $SERVER_OBJ = Test::ACME2_Server->new( + ca_class => 'MyCA', + ); + + my $acme = MyCA->new( key => $_P256_KEY ); + + my $timeout = $acme->http_timeout(); + ok( defined $timeout, 'http_timeout() returns a value in sync mode' ); + + lives_ok( + sub { $acme->http_timeout(30) }, + 'http_timeout() accepts a new value', + ); + + is( $acme->http_timeout(), 30, 'http_timeout() reflects the new value' ); +}; + +#---------------------------------------------------------------------- +# http_timeout() - async mode dies + +subtest 'http_timeout() in async mode dies' => sub { + my $SERVER_OBJ = Test::ACME2_Server->new( + ca_class => 'MyCA', + ); + + { + package MockAsyncUA; + + sub new { bless {}, shift } + sub request { die "should not be called" } + } + + my $acme = MyCA->new( + key => $_P256_KEY, + async_ua => MockAsyncUA->new(), + ); + + throws_ok( + sub { $acme->http_timeout() }, + qr/asynchronous mode/, + 'http_timeout() dies in async mode', + ); +}; + +#---------------------------------------------------------------------- +# update_account() without key_id + +subtest 'update_account() without key_id throws' => sub { + my $SERVER_OBJ = Test::ACME2_Server->new( + ca_class => 'MyCA', + ); + + my $acme = MyCA->new( key => $_P256_KEY ); + + throws_ok( + sub { $acme->update_account( contact => ['mailto:test@example.com'] ) }, + qr/key ID/i, + 'update_account() dies without key_id', + ); +}; + +done_testing();