From bba4ebd15450e86c6c6b838133c55c6ba4f6e878 Mon Sep 17 00:00:00 2001 From: vis2k Date: Wed, 26 Feb 2020 10:27:36 +0100 Subject: [PATCH] NetworkServerTest: CommandTest tries invalid netid and command without authority too --- .../Mirror/Tests/Editor/NetworkServerTest.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs index 74d9da9d8..6ed0c7d60 100644 --- a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs +++ b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs @@ -631,6 +631,27 @@ public void CommandMessageCallsCommandTest() Assert.That(comp0.called, Is.EqualTo(0)); Assert.That(comp1.called, Is.EqualTo(1)); + // sending a command without authority should fail + // (= if connectionToClient is not what we received the data on) + identity.connectionToClient = new ULocalConnectionToClient(); // set wrong authority + comp0.called = 0; + comp1.called = 0; + Transport.activeTransport.OnServerDataReceived.Invoke(0, segment, 0); + Assert.That(comp0.called, Is.EqualTo(0)); + Assert.That(comp1.called, Is.EqualTo(0)); + identity.connectionToClient = connection; // restore authority + + // sending a component with wrong netId should fail + message.netId += 1; // wrong netid + writer = new NetworkWriter(); + MessagePacker.Pack(message, writer); // need to serialize the message again with wrong netid + ArraySegment segmentWrongNetId = writer.ToArraySegment(); + comp0.called = 0; + comp1.called = 0; + Transport.activeTransport.OnServerDataReceived.Invoke(0, segmentWrongNetId, 0); + Assert.That(comp0.called, Is.EqualTo(0)); + Assert.That(comp1.called, Is.EqualTo(0)); + // clean up NetworkIdentity.spawned.Clear(); NetworkBehaviour.ClearDelegates();