feat(server): harden hostile input and overload behavior (#15)
quality-gate / quality (push) Failing after 1m5s
quality-gate / quality (push) Failing after 1m5s
This commit is contained in:
@@ -5,6 +5,57 @@ namespace FinalFactory.Rendezvous.Tests.State;
|
||||
|
||||
public sealed class InMemoryEphemeralRendezvousStoreTests
|
||||
{
|
||||
[Fact]
|
||||
public void DeterministicHostileStateTransitionsStayTypedAndCapacityBounded()
|
||||
{
|
||||
const int seed = 0x15_57A7E;
|
||||
Random random = new(seed);
|
||||
EphemeralStateFixture fixture = new(new EphemeralStoreOptions
|
||||
{
|
||||
MaxJoinAttempts = 32,
|
||||
});
|
||||
StoredListing listing = fixture.CreateVisibleListing(out _);
|
||||
|
||||
for (int iteration = 0; iteration < 1_000; iteration++)
|
||||
{
|
||||
CreateJoinAttemptCommand command = fixture.AttemptCommand(listing);
|
||||
command = random.Next(4) switch
|
||||
{
|
||||
0 => command with
|
||||
{
|
||||
Scope = new(new GameId("other-game"), new EnvironmentId("test")),
|
||||
},
|
||||
1 => command with { ProtocolVersion = command.ProtocolVersion + 1 },
|
||||
_ => command,
|
||||
};
|
||||
StoreResult<StoredJoinAttempt> created = fixture.Store.CreateJoinAttempt(command);
|
||||
Assert.True(Enum.IsDefined(created.Code));
|
||||
if (!created.Succeeded || created.Value is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
SecretFingerprint supplied = random.Next(3) == 0
|
||||
? EphemeralStateFixture.Fingerprint($"wrong-{iteration}")
|
||||
: created.Value.ClientCapabilityFingerprint;
|
||||
StoreResult<StoredJoinAttempt> bound = fixture.Store.BindAttemptEndpoint(new(
|
||||
created.Value.MediationHandle,
|
||||
AttemptPeerRole.Client,
|
||||
supplied,
|
||||
EphemeralStateFixture.OtherPublicEndpoint(20_000 + iteration),
|
||||
null));
|
||||
Assert.True(Enum.IsDefined(bound.Code));
|
||||
}
|
||||
|
||||
StoreResult<IReadOnlyList<StoredJoinAttempt>> attempts =
|
||||
fixture.Store.BrowseHostJoinAttempts(new(
|
||||
listing.Definition.ListingId,
|
||||
listing.Definition.LeaseFingerprint,
|
||||
100));
|
||||
Assert.True(attempts.Succeeded);
|
||||
Assert.InRange(attempts.Value!.Count, 1, 32);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdempotencyRetentionMustCoverResourceLifetimes()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user