Networking tests: pin the write-side depth check on ToRawRecord with no binding
Some checks failed
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Has been cancelled
Some checks failed
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Has been cancelled
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1b794987d9
commit
4f747d4567
1 changed files with 32 additions and 1 deletions
|
|
@ -21,7 +21,15 @@ namespace GameCult.Networking.Tests
|
|||
[Key(1)] public int N = 3;
|
||||
}
|
||||
|
||||
private static readonly CultDocumentRegistry Documents = CultDocumentRegistry.ForTypes(new[] { typeof(TailDoc) });
|
||||
[CultDocument("tests.bytes_after_deep", "tests.bytes_after_deep.v1")]
|
||||
[MessagePackObject]
|
||||
public sealed class DeepDoc
|
||||
{
|
||||
[Key(0)] [CultName] public string Id = "a";
|
||||
[Key(1)] public DeepDoc Inner;
|
||||
}
|
||||
|
||||
private static readonly CultDocumentRegistry Documents = CultDocumentRegistry.ForTypes(new[] { typeof(TailDoc), typeof(DeepDoc) });
|
||||
|
||||
private static byte[] WithTail() =>
|
||||
CultDocumentMessagePackSerialization.SerializeUntyped(new TailDoc(), typeof(TailDoc), Documents).Concat(new byte[] { 0xc0 }).ToArray();
|
||||
|
|
@ -58,5 +66,28 @@ namespace GameCult.Networking.Tests
|
|||
var registry = new CultNetDocumentRegistry(Documents);
|
||||
Refuses(() => registry.DeserializeRawDocument(Raw(registry, WithTail())));
|
||||
}
|
||||
|
||||
// The write side of the same rule: a record with no binding is serialized by SerializeUntyped, and a payload nested past
|
||||
// the limit is refused there, before it can reach the wire.
|
||||
[Test]
|
||||
public void ToRawRecordWithNoBindingRefusesAPayloadNestedPastTheLimit()
|
||||
{
|
||||
var registry = new CultNetDocumentRegistry(Documents);
|
||||
var descriptor = Documents.GetRequired(typeof(DeepDoc));
|
||||
DeepDoc Chain(int links)
|
||||
{
|
||||
var head = new DeepDoc();
|
||||
var tip = head;
|
||||
for (var i = 0; i < links; i++) tip = tip.Inner = new DeepDoc();
|
||||
return head;
|
||||
}
|
||||
|
||||
// Each link is one array; the root is depth 1, so 255 links is depth 256 (at the limit) and 256 links is 257.
|
||||
Assert.That(registry.ToRawRecord(descriptor, new CultRecordKey("a"), Chain(255), "1970-01-01T00:00:00.000Z").Payload, Is.Not.Empty);
|
||||
var refused = Assert.Throws<MessagePackSerializationException>(
|
||||
() => registry.ToRawRecord(descriptor, new CultRecordKey("a"), Chain(256), "1970-01-01T00:00:00.000Z"))!;
|
||||
Assert.That(refused.Message, Does.Contain("refused on write"));
|
||||
Assert.That(refused.Message, Does.Contain(typeof(DeepDoc).FullName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue