VoterIdentity: anchor the device id grammar at \z so a trailing newline or control char is no second identity
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d171713ab1
commit
abb0986508
2 changed files with 20 additions and 1 deletions
|
|
@ -8,7 +8,7 @@ public sealed record VoterIdentity(string Key, VoterClass Class, Guid? UserAccou
|
|||
{
|
||||
public const int MaxKeyLength = 120;
|
||||
|
||||
private static readonly Regex DeviceIdShape = new("^[A-Za-z0-9_-]{1,100}$", RegexOptions.CultureInvariant);
|
||||
private static readonly Regex DeviceIdShape = new(@"^[A-Za-z0-9_-]{1,100}\z", RegexOptions.CultureInvariant);
|
||||
|
||||
// The one place a voter key and class are decided. Never reads vote weight.
|
||||
public static VoterIdentity? For(CurrentBifrostActor actor, string? deviceId)
|
||||
|
|
|
|||
|
|
@ -39,10 +39,29 @@ public sealed class ConceptAppraisalServiceTests
|
|||
|
||||
Assert.Null(VoterIdentity.For(CurrentBifrostActor.Anonymous, null));
|
||||
Assert.Null(VoterIdentity.For(CurrentBifrostActor.Anonymous, "has:colon"));
|
||||
Assert.Null(VoterIdentity.For(CurrentBifrostActor.Anonymous, string.Empty));
|
||||
Assert.Equal(CastResult.NoVoter, await f.Cast("ship-a", null, ConceptStance.Up));
|
||||
Assert.Empty(f.Db.ConceptAppraisals);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("abc\n")]
|
||||
[InlineData("abc\r\n")]
|
||||
[InlineData("abc ")]
|
||||
[InlineData("abc\t")]
|
||||
[InlineData("abc\0")]
|
||||
public async Task A_device_id_with_trailing_whitespace_or_control_char_cannot_cast_beside_its_bare_form(string forged)
|
||||
{
|
||||
await using var f = new Fixture();
|
||||
await f.AddSubject("ship-a");
|
||||
|
||||
Assert.Equal(CastResult.Recorded, await f.Cast("ship-a", f.Anonymous("abc"), ConceptStance.Up));
|
||||
|
||||
Assert.Null(VoterIdentity.For(CurrentBifrostActor.Anonymous, forged));
|
||||
Assert.Equal(CastResult.NoVoter, await f.Cast("ship-a", VoterIdentity.For(CurrentBifrostActor.Anonymous, forged), ConceptStance.Down));
|
||||
Assert.Single(f.Db.ConceptAppraisals);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Voter_class_is_stamped_at_cast()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue