Skip to content
Merged
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
5 changes: 2 additions & 3 deletions lib/Net/ACME2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -923,9 +923,8 @@ sub _parse_link_alternates {

my @alt_urls;
for my $link (@links) {
if ($link =~ m{<([^>]+)>\s*;\s*rel="alternate"}i) {
push @alt_urls, $1;
}
next unless $link =~ m{;\s*rel="alternate"}i;
push @alt_urls, $1 if $link =~ m{<([^>]+)>};
}

return @alt_urls;
Expand Down
68 changes: 62 additions & 6 deletions t/Net-ACME2-link-alternates.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use Test::More;
use Test::FailWarnings;

# _parse_link_alternates is a private function in Net::ACME2.
# We test it directly to verify RFC 8288 compliance (case-insensitive
# relation types).
# We test it directly to verify RFC 8288 compliance:
# - relation types are case-insensitive (section 2.1.1)
# - link parameters may appear in any order (section 3)

use Net::ACME2 ();

Expand All @@ -33,7 +34,7 @@ use Net::ACME2 ();
is( scalar @urls, 0, 'no Link header returns empty list' );
}

# --- Single alternate link (lowercase) ---
# --- Single alternate link ---
{
my $resp = MockResponse->new(
link => '<https://ca.example/cert/alt1>;rel="alternate"',
Expand All @@ -42,7 +43,7 @@ use Net::ACME2 ();
is_deeply(
\@urls,
['https://ca.example/cert/alt1'],
'single lowercase alternate link',
'single alternate link',
);
}

Expand Down Expand Up @@ -87,7 +88,7 @@ use Net::ACME2 ();
);
}

# --- RFC 8288: relation types are case-insensitive ---
# --- RFC 8288 section 2.1.1: relation types are case-insensitive ---
{
my $resp = MockResponse->new(
link => '<https://ca.example/cert/alt1>;rel="Alternate"',
Expand All @@ -112,7 +113,7 @@ use Net::ACME2 ();
);
}

# --- Whitespace variations in Link header ---
# --- Whitespace variations ---
{
my $resp = MockResponse->new(
link => '<https://ca.example/cert/alt1> ; rel="alternate"',
Expand All @@ -125,4 +126,59 @@ use Net::ACME2 ();
);
}

# --- RFC 8288 section 3: parameters may appear in any order ---
# The rel parameter does not need to be the first parameter after the URI.
{
my $resp = MockResponse->new(
link => '<https://ca.example/cert/alt1>; title="cross-signed"; rel="alternate"',
);
my @urls = Net::ACME2::_parse_link_alternates($resp);
is_deeply(
\@urls,
['https://ca.example/cert/alt1'],
'rel after other params (title before rel)',
);
}

{
my $resp = MockResponse->new(
link => '<https://ca.example/cert/alt1>; type="application/pem-certificate-chain"; rel="alternate"',
);
my @urls = Net::ACME2::_parse_link_alternates($resp);
is_deeply(
\@urls,
['https://ca.example/cert/alt1'],
'rel after type param',
);
}

{
my $resp = MockResponse->new(
link => '<https://ca.example/cert/alt1>; rel="alternate"; title="ISRG Root X2"',
);
my @urls = Net::ACME2::_parse_link_alternates($resp);
is_deeply(
\@urls,
['https://ca.example/cert/alt1'],
'rel before other params (rel then title)',
);
}

# --- rel in any position with mixed links ---
{
my $resp = MockResponse->new(
link => [
'<https://ca.example/directory>; rel="index"',
'<https://ca.example/cert/alt1>; title="cross-signed"; rel="alternate"',
'<https://ca.example/cert/alt2>; rel="alternate"; title="ISRG Root X2"',
],
);
my @urls = Net::ACME2::_parse_link_alternates($resp);
is_deeply(
\@urls,
['https://ca.example/cert/alt1', 'https://ca.example/cert/alt2'],
'mixed links with rel in various positions',
);
}

done_testing();
Loading