public void Load_ForwardedTcpipChannelInfo() { var localChannelNumber = (uint)_random.Next(0, int.MaxValue); var initialWindowSize = (uint)_random.Next(0, int.MaxValue); var maximumPacketSize = (uint)_random.Next(0, int.MaxValue); var info = new ForwardedTcpipChannelInfo("connected", 25, "originator", 21); var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info); var bytes = target.GetBytes(); target.Load(bytes); Assert.AreEqual(info.ChannelType, _ascii.GetString(target.ChannelType)); Assert.IsNotNull(target.Info); Assert.AreEqual(initialWindowSize, target.InitialWindowSize); Assert.AreEqual(localChannelNumber, target.LocalChannelNumber); Assert.AreEqual(maximumPacketSize, target.MaximumPacketSize); var forwardedTcpipChannelInfo = target.Info as ForwardedTcpipChannelInfo; Assert.IsNotNull(forwardedTcpipChannelInfo); Assert.AreEqual(info.ChannelType, forwardedTcpipChannelInfo.ChannelType); Assert.AreEqual(info.ConnectedAddress, forwardedTcpipChannelInfo.ConnectedAddress); Assert.AreEqual(info.ConnectedPort, forwardedTcpipChannelInfo.ConnectedPort); Assert.AreEqual(info.OriginatorAddress, forwardedTcpipChannelInfo.OriginatorAddress); Assert.AreEqual(info.OriginatorPort, forwardedTcpipChannelInfo.OriginatorPort); }
public void Load_DirectTcpipChannelInfo() { var localChannelNumber = (uint)_random.Next(0, int.MaxValue); var initialWindowSize = (uint)_random.Next(0, int.MaxValue); var maximumPacketSize = (uint)_random.Next(0, int.MaxValue); var info = new DirectTcpipChannelInfo("host", 22, "originator", 25); var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info); var bytes = target.GetBytes(); target.Load(bytes); Assert.AreEqual(info.ChannelType, _ascii.GetString(target.ChannelType)); Assert.IsNotNull(target.Info); Assert.AreEqual(initialWindowSize, target.InitialWindowSize); Assert.AreEqual(localChannelNumber, target.LocalChannelNumber); Assert.AreEqual(maximumPacketSize, target.MaximumPacketSize); var directTcpChannelInfo = target.Info as DirectTcpipChannelInfo; Assert.IsNotNull(directTcpChannelInfo); Assert.AreEqual(info.ChannelType, directTcpChannelInfo.ChannelType); Assert.AreEqual(info.HostToConnect, directTcpChannelInfo.HostToConnect); Assert.AreEqual(info.OriginatorAddress, directTcpChannelInfo.OriginatorAddress); Assert.AreEqual(info.OriginatorPort, directTcpChannelInfo.OriginatorPort); Assert.AreEqual(info.PortToConnect, directTcpChannelInfo.PortToConnect); }
public void Load_X11ChannelOpenInfo() { var localChannelNumber = (uint)_random.Next(0, int.MaxValue); var initialWindowSize = (uint)_random.Next(0, int.MaxValue); var maximumPacketSize = (uint)_random.Next(0, int.MaxValue); var info = new X11ChannelOpenInfo("address", 26); var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info); var bytes = target.GetBytes(); target.Load(bytes); #if TUNING Assert.AreEqual(info.ChannelType, _ascii.GetString(target.ChannelType)); #else Assert.AreEqual(info.ChannelType, target.ChannelType); #endif Assert.IsNotNull(target.Info); Assert.AreEqual(initialWindowSize, target.InitialWindowSize); Assert.AreEqual(localChannelNumber, target.LocalChannelNumber); Assert.AreEqual(maximumPacketSize, target.MaximumPacketSize); var x11ChannelOpenInfo = target.Info as X11ChannelOpenInfo; Assert.IsNotNull(x11ChannelOpenInfo); Assert.AreEqual(info.ChannelType, x11ChannelOpenInfo.ChannelType); Assert.AreEqual(info.OriginatorAddress, x11ChannelOpenInfo.OriginatorAddress); Assert.AreEqual(info.OriginatorPort, x11ChannelOpenInfo.OriginatorPort); }
public void Load_SessionChannelOpenInfo() { var localChannelNumber = (uint)_random.Next(0, int.MaxValue); var initialWindowSize = (uint)_random.Next(0, int.MaxValue); var maximumPacketSize = (uint)_random.Next(0, int.MaxValue); var info = new SessionChannelOpenInfo(); var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info); var bytes = target.GetBytes(); target.Load(bytes); #if TUNING Assert.AreEqual(info.ChannelType, _ascii.GetString(target.ChannelType)); #else Assert.AreEqual(info.ChannelType, target.ChannelType); #endif Assert.IsNotNull(target.Info); Assert.AreEqual(initialWindowSize, target.InitialWindowSize); Assert.AreEqual(localChannelNumber, target.LocalChannelNumber); Assert.AreEqual(maximumPacketSize, target.MaximumPacketSize); var sessionChannelOpenInfo = target.Info as SessionChannelOpenInfo; Assert.IsNotNull(sessionChannelOpenInfo); Assert.AreEqual(info.ChannelType, sessionChannelOpenInfo.ChannelType); }
public void GetBytes() { var localChannelNumber = (uint)_random.Next(0, int.MaxValue); var initialWindowSize = (uint)_random.Next(0, int.MaxValue); var maximumPacketSize = (uint)_random.Next(0, int.MaxValue); var info = new DirectTcpipChannelInfo("host", 22, "originator", 25); var infoBytes = info.GetBytes(); var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info); var bytes = target.GetBytes(); var expectedBytesLength = 1; // Type expectedBytesLength += 4; // ChannelType length expectedBytesLength += target.ChannelType.Length; // ChannelType expectedBytesLength += 4; // LocalChannelNumber expectedBytesLength += 4; // InitialWindowSize expectedBytesLength += 4; // MaximumPacketSize expectedBytesLength += infoBytes.Length; // Info Assert.AreEqual(expectedBytesLength, bytes.Length); var sshDataStream = new SshDataStream(bytes); Assert.AreEqual(ChannelOpenMessage.MessageNumber, sshDataStream.ReadByte()); var actualChannelTypeLength = sshDataStream.ReadUInt32(); Assert.AreEqual((uint)target.ChannelType.Length, actualChannelTypeLength); #if TUNING var actualChannelType = new byte[actualChannelTypeLength]; sshDataStream.Read(actualChannelType, 0, (int)actualChannelTypeLength); Assert.IsTrue(target.ChannelType.SequenceEqual(actualChannelType)); #else var actualChannelType = new byte[actualChannelTypeLength]; sshDataStream.Read(actualChannelType, 0, (int)actualChannelTypeLength); Assert.AreEqual(target.ChannelType, SshData.Ascii.GetString(actualChannelType)); #endif Assert.AreEqual(localChannelNumber, sshDataStream.ReadUInt32()); Assert.AreEqual(initialWindowSize, sshDataStream.ReadUInt32()); Assert.AreEqual(maximumPacketSize, sshDataStream.ReadUInt32()); var actualInfo = new byte[infoBytes.Length]; sshDataStream.Read(actualInfo, 0, actualInfo.Length); Assert.IsTrue(infoBytes.SequenceEqual(actualInfo)); Assert.IsTrue(sshDataStream.IsEndOfData); }