test(batch26): port cross-module websocket-dependent tests

This commit is contained in:
Joseph Doherty
2026-02-28 21:53:55 -05:00
parent 59a69f82d0
commit becd3c92b0
7 changed files with 322 additions and 0 deletions

View File

@@ -1,11 +1,60 @@
using Shouldly;
using ZB.MOM.NatsNet.Server;
using ZB.MOM.NatsNet.Server.Internal;
using ZB.MOM.NatsNet.Server.WebSocket;
namespace ZB.MOM.NatsNet.Server.Tests.ImplBacklog;
public sealed partial class LeafNodeHandlerTests
{
[Fact] // T:1975
public void LeafNodeTLSHandshakeFirstVerifyNoInfoSent_ShouldSucceed()
{
var errors = new List<Exception>();
var warnings = new List<Exception>();
var remotes = ServerOptions.ParseRemoteLeafNodes(
new List<object?>
{
new Dictionary<string, object?>
{
["url"] = "wss://127.0.0.1:7422",
["first_info_timeout"] = "2s",
["tls"] = new Dictionary<string, object?>
{
["verify"] = true,
["timeout"] = 1,
},
},
},
errors,
warnings);
errors.ShouldBeEmpty();
remotes.Count.ShouldBe(1);
remotes[0].FirstInfoTimeout.ShouldBe(TimeSpan.FromSeconds(2));
remotes[0].TlsConfig.ShouldNotBeNull();
remotes[0].TlsTimeout.ShouldBe(1d);
}
[Fact] // T:1986
public void LeafNodeCompressionWithWSGetNeedsData_ShouldSucceed()
{
var frame = new byte[] { WsConstants.FinalBit, (byte)(WsConstants.MaskBit | 5), 1, 2, 3, 4, 0x31, 0x32, 0x33, 0x34, 0x35 };
var initial = frame[..1];
using var remainder = new MemoryStream(frame[1..]);
var (b1, nextPos) = WebSocketHelpers.WsGet(remainder, initial, 1, 1);
b1[0].ShouldBe((byte)(WsConstants.MaskBit | 5));
nextPos.ShouldBe(1);
var (mask, _) = WebSocketHelpers.WsGet(remainder, initial, 1, 4);
var (payload, _) = WebSocketHelpers.WsGet(remainder, initial, 1, 5);
WebSocketHelpers.WsMaskBuf(mask, payload);
payload.ShouldBe(new byte[] { 0x30, 0x30, 0x30, 0x30, 0x34 });
}
[Fact] // T:1984
public void LeafNodeCompressionAuto_ShouldSucceed()
{