Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions lib/Net/ACME2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1144,8 +1144,6 @@ sub _set_http {
return;
}

our $_POST_METHOD;

sub _post {
my ( $self, $link_name, $data ) = @_;

Expand Down
115 changes: 115 additions & 0 deletions t/Net-ACME2-api-guards.t
Original file line number Diff line number Diff line change
@@ -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 = <<END;
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIKDv8TBijBVbTYB7lfUnwLn4qjqWD0GD7XOXzdp0wb61oAoGCCqGSM49
AwEHoUQDQgAEBJIULcFadtIBc0TuNzT80UFcfkQ0U7+EPqEJNXamG1H4/z8xVgE7
3hoBfX4xbN2Hx2p26eNIptt+1jj2H/M44g==
-----END EC PRIVATE KEY-----
END

#----------------------------------------------------------------------
# new() requires key

subtest 'new() without key throws' => 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();
Loading