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:
parent
513d614c25
commit
3d385ecb73
1 changed files with 10 additions and 5 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue