Test the IPv6 /64 and mapped-IPv4 keying of the registration budget

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Heimdall 2026-11-11 10:15:45 +00:00
commit 74edb30a2d

View file

@ -163,6 +163,34 @@ public sealed class RegistrationBudgetTests(RegistrationBudgetFactory factory) :
Assert.Equal(HttpStatusCode.OK, other.StatusCode);
}
[Fact]
public async Task An_IPv6_caller_owns_its_slash_64_and_a_mapped_IPv4_shares_its_IPv4_key()
{
using var client = factory.CreateClient();
string[] sameSlash64 = ["2001:db8:1:2::1", "2001:db8:1:2::2", "2001:db8:1:2:aaaa::3", "2001:db8:1:2:ffff:ffff:ffff:ffff", "2001:db8:1:2::5"];
var statuses = new List<HttpStatusCode>();
foreach (var peer in sameSlash64)
{
using var response = await ChallengeAsync(client, peer);
statuses.Add(response.StatusCode);
}
Assert.Equal(
[HttpStatusCode.OK, HttpStatusCode.OK, HttpStatusCode.OK, HttpStatusCode.TooManyRequests, HttpStatusCode.TooManyRequests],
statuses);
using var otherSlash64 = await ChallengeAsync(client, "2001:db8:1:3::1");
Assert.Equal(HttpStatusCode.OK, otherSlash64.StatusCode);
for (var i = 0; i < 3; i++)
{
using var ok = await ChallengeAsync(client, "203.0.113.50");
Assert.Equal(HttpStatusCode.OK, ok.StatusCode);
}
using var mapped = await ChallengeAsync(client, "::ffff:203.0.113.50");
Assert.Equal(HttpStatusCode.TooManyRequests, mapped.StatusCode);
}
[Fact]
public async Task Challenge_and_register_spend_one_budget_and_a_refused_register_creates_nothing()
{