Make the malformed-nonce test independent of the proof of work

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Heimdall 2026-11-11 08:56:35 +00:00
commit 3d385ecb73

View file

@ -140,15 +140,20 @@ public sealed class RegistrationGateTests(RegistrationGateFactory factory) : ICl
new { identity = NewIdentity(), challenge, nonce = wrong, acceptedNoticeVersion = TrainingNotice.Version });
}
// Each malformed shape is padded until it meets the difficulty, so only the nonce-format guard can refuse it.
[Theory]
[InlineData("")]
[InlineData("-1")]
[InlineData("1e3")]
[InlineData("123456789012345678901")]
public async Task A_malformed_nonce_is_refused(string nonce)
[InlineData("x", "")]
[InlineData("-", "")]
[InlineData("", "e")]
[InlineData("000000000000000000000", "")]
public async Task A_malformed_nonce_is_refused_even_when_its_hash_would_pass(string prefix, string suffix)
{
using var client = Client();
var (challenge, _) = await SolvedAsync(client);
var nonce = Enumerable.Range(0, int.MaxValue)
.Select(i => prefix + i + suffix)
.First(n => RegistrationChallengeService.LeadingZeroBits(
System.Security.Cryptography.SHA256.HashData(System.Text.Encoding.UTF8.GetBytes(challenge + ":" + n))) >= 4);
await AssertRefusedCreatesNothingAsync(
client,