From 3d385ecb739de97b0eeebab90f26b2a7b0066ce6 Mon Sep 17 00:00:00 2001 From: Heimdall Date: Wed, 11 Nov 2026 08:56:35 +0000 Subject: [PATCH] Make the malformed-nonce test independent of the proof of work Co-Authored-By: Claude Sonnet 5.5 --- tests/Bifrost.Web.Tests/RegistrationGateTests.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/Bifrost.Web.Tests/RegistrationGateTests.cs b/tests/Bifrost.Web.Tests/RegistrationGateTests.cs index fe74115..c448b8e 100644 --- a/tests/Bifrost.Web.Tests/RegistrationGateTests.cs +++ b/tests/Bifrost.Web.Tests/RegistrationGateTests.cs @@ -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,