diff --git a/MANIFEST b/MANIFEST index e77ce8f..a02184a 100644 --- a/MANIFEST +++ b/MANIFEST @@ -71,4 +71,3 @@ t/Net-ACME2-PromiseUtil.t t/Net-ACME2-RetryAfter.t t/Net-ACME2-revoke.t t/Net-ACME2.t -t/Net-ACME2_pre_rename.t diff --git a/t/Net-ACME2-Error.t b/t/Net-ACME2-Error.t index b0bb996..d288e69 100644 --- a/t/Net-ACME2-Error.t +++ b/t/Net-ACME2-Error.t @@ -114,4 +114,81 @@ use Net::ACME2::Error (); ); } +# Test type() defaults to 'about:blank' when unset +{ + my $err = Net::ACME2::Error->new(); + + is( + $err->type(), + 'about:blank', + 'type() defaults to about:blank', + ); +} + +# Test description() with known ACME URN types +{ + my @known_types = ( + [ 'badNonce' => qr/unacceptable anti-replay nonce/ ], + [ 'rateLimited' => qr/rate limit/ ], + [ 'unauthorized' => qr/lacks sufficient authorization/ ], + [ 'serverInternal' => qr/internal error/ ], + [ 'malformed' => qr/malformed/ ], + [ 'badCSR' => qr/unacceptable/ ], + [ 'rejectedIdentifier'=> qr/will not issue/ ], + [ 'caa' => qr/CAA/ ], + [ 'dns' => qr/DNS query/ ], + ); + + for my $t (@known_types) { + my ($short_type, $desc_re) = @$t; + + my $err = Net::ACME2::Error->new( + type => "urn:ietf:params:acme:error:$short_type", + ); + + like( + $err->description(), + $desc_re, + "description() for $short_type", + ); + } +} + +# Test description() returns undef for unknown types +{ + my $err = Net::ACME2::Error->new( + type => 'urn:ietf:params:acme:error:totallyMadeUp', + ); + + is( $err->description(), undef, 'description() undef for unknown type' ); +} + +# Test to_string() includes description for known URN types +{ + my $err = Net::ACME2::Error->new( + status => 429, + type => 'urn:ietf:params:acme:error:rateLimited', + detail => 'too many requests', + ); + + my $str = $err->to_string(); + + like( $str, qr/429/, 'to_string has status' ); + like( $str, qr/rateLimited/, 'to_string has type' ); + like( $str, qr/rate limit/, 'to_string has description' ); + like( $str, qr/too many/, 'to_string has detail' ); +} + +# Test subproblems() in list context enforcement +{ + my $err = Net::ACME2::Error->new( + status => 400, + type => 'urn:ietf:params:acme:error:rejectedIdentifier', + ); + + # subproblems() requires list context + my @subs = $err->subproblems(); + is( scalar @subs, 0, 'subproblems() returns empty list when none' ); +} + done_testing(); diff --git a/t/Net-ACME2.t b/t/Net-ACME2.t index 288e1c7..6a5c929 100644 --- a/t/Net-ACME2.t +++ b/t/Net-ACME2.t @@ -171,4 +171,27 @@ for my $t (@alg_key) { ); } +# Legacy aliases (create_new_account, create_new_order) +{ + my $SERVER_OBJ = Test::ACME2_Server->new( + ca_class => 'MyCA', + ); + + my $acme = MyCA->new( key => $_P256_KEY ); + + my $created = $acme->create_new_account( + termsOfServiceAgreed => 1, + ); + + is( $created, 1, 'create_new_account() alias works' ); + + my $order = $acme->create_new_order( + identifiers => [ + { type => 'dns', value => 'example.com' }, + ], + ); + + isa_ok( $order, 'Net::ACME2::Order', 'create_new_order() alias works' ); +} + done_testing(); diff --git a/t/Net-ACME2_pre_rename.t b/t/Net-ACME2_pre_rename.t deleted file mode 100644 index 27fab97..0000000 --- a/t/Net-ACME2_pre_rename.t +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; - -use Test::More; -use Test::Exception; -use Test::FailWarnings; - -use Digest::MD5; -use HTTP::Status; -use URI; -use JSON; - -use Crypt::Format (); - -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 $_RSA_KEY = < $_RSA_KEY ], - [ p256 => $_P256_KEY ], - [ p384 => $_P384_KEY ], -); - -for my $t (@alg_key) { - my ($alg, $key_pem) = @$t; - - my $key_der = Crypt::Format::pem2der($key_pem); - - my @formats = ( - [ pem => $key_pem ], - [ der => $key_der ], - ); - - for my $tt (@formats) { - my ($format, $key_str) = @$tt; - - diag "$alg, $format"; - - lives_ok( - sub { - my $SERVER_OBJ = Test::ACME2_Server->new( - ca_class => 'MyCA', - ); - - #---------------------------------------------------------------------- - # new() - - my $acme = MyCA->new( key => $key_str ); - isa_ok( $acme, 'MyCA', 'new() response' ); - - #---------------------------------------------------------------------- - # get_terms_of_service() - - my $tos = $acme->get_terms_of_service(); - - is( $tos, $SERVER_OBJ->TOS_URL(), 'get_terms_of_service' ); - - #---------------------------------------------------------------------- - - my $created = $acme->create_account( - termsOfServiceAgreed => 1, - ); - - is( $created, 1, 'create_account() on new account creation' ); - - my $key_id = $acme->key_id(); - ok( $key_id, 'key_id() gets updated' ); - - $created = $acme->create_account(); - is( $created, 0, 'create_account() if account already exists' ); - - is( $acme->key_id(), $key_id, 'key_id() stays the same' ); - }, - "no errors: $alg, $format", - ); - } -} - -done_testing();