public void TestOpenConnection() { SecureTunnel t = new SecureTunnel(tunnelSocket); DuplexPipe connection = new DuplexPipe(t, 0); Assert.IsFalse(t.OpenPipe(connection), "Shouldn't have been able to assign 0 to the abstract connection"); connection = new DuplexPipe(t, 100); Assert.IsTrue(t.OpenPipe(connection), "Should've been able to assign a new connection with ID of 100"); Assert.IsTrue(t.PipeIDs.Contains((uint)100)); connection = new DuplexPipe(t, 100); Assert.IsFalse(t.OpenPipe(connection), "Shouldn't have been able to create a duplicate connection with the same ID"); }
public void TestCloseConnection() { SecureTunnel t = new SecureTunnel(tunnelSocket); byte[] privateKey, publicKey; privateKey = new byte[0]; publicKey = new byte[0]; this.SetupTunnelComms(t, out privateKey, out publicKey); tunnelSocket.InterceptOutgoingPacket(p => { //we should recieve a close connection packet EncryptedPacket packet = (EncryptedPacket)p; packet.DecryptPacket(privateKey, publicKey); var x = packet.RPCs.First; Assert.IsTrue(x.SerializationTag == (byte)RPCType.ClosePipe); }); DuplexPipe connection = new DuplexPipe(t, 100); Assert.IsTrue(t.OpenPipe(connection)); Assert.IsTrue(t.PipeIDs.Contains((uint)100)); Assert.IsTrue(t.ClosePipe((uint)100)); Assert.IsFalse(t.PipeIDs.Contains((uint)100)); }