NetworkServerTest: CommandTest tries invalid netid and command without authority too

This commit is contained in:
vis2k 2020-02-26 10:27:36 +01:00
parent 038e3c1969
commit bba4ebd154

View File

@ -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<byte> 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();