Наследование: System.Globalization.Message
Пример #1
0
 public void ChannelTypeTest()
 {
     ChannelOpenMessage target = new ChannelOpenMessage(); // TODO: Initialize to an appropriate value
     string actual;
     actual = target.ChannelType;
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
Пример #2
0
 public void ChannelOpenMessageConstructorTest1()
 {
     uint channelNumber = 0; // TODO: Initialize to an appropriate value
     uint initialWindowSize = 0; // TODO: Initialize to an appropriate value
     uint maximumPacketSize = 0; // TODO: Initialize to an appropriate value
     ChannelOpenInfo info = null; // TODO: Initialize to an appropriate value
     ChannelOpenMessage target = new ChannelOpenMessage(channelNumber, initialWindowSize, maximumPacketSize, info);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
Пример #3
0
        public void DefaultConstructor()
        {
            var target = new ChannelOpenMessage();

            Assert.IsNull(target.ChannelType);
            Assert.IsNull(target.Info);
            Assert.AreEqual(default(uint), target.InitialWindowSize);
            Assert.AreEqual(default(uint), target.LocalChannelNumber);
            Assert.AreEqual(default(uint), target.MaximumPacketSize);
        }
Пример #4
0
        public void Constructor_LocalChannelNumberAndInitialWindowSizeAndMaximumPacketSizeAndInfo()
        {
            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);

            Assert.AreEqual(info.ChannelType, _ascii.GetString(target.ChannelType));
            Assert.AreSame(info, target.Info);
            Assert.AreEqual(initialWindowSize, target.InitialWindowSize);
            Assert.AreEqual(localChannelNumber, target.LocalChannelNumber);
            Assert.AreEqual(maximumPacketSize, target.MaximumPacketSize);
        }
Пример #5
0
        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);

            var actualChannelType = new byte[actualChannelTypeLength];
            sshDataStream.Read(actualChannelType, 0, (int) actualChannelTypeLength);
            Assert.IsTrue(target.ChannelType.SequenceEqual(actualChannelType));

            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);
        }
Пример #6
0
 /// <summary>
 /// Send message to open a channel.
 /// </summary>
 /// <param name="message">Message to send</param>
 protected void SendMessage(ChannelOpenMessage message)
 {
     Session.SendMessage(message);
 }
 /// <summary>
 /// Send message to open a channel.
 /// </summary>
 /// <param name="message">Message to send</param>
 protected void SendMessage(ChannelOpenMessage message)
 {
     //  No need to check whether channel is open when trying to open a channel
     this._session.SendMessage(message);
 }
Пример #8
0
 public void ChannelOpenMessageConstructorTest()
 {
     ChannelOpenMessage target = new ChannelOpenMessage();
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
Пример #9
0
        public void Load_ShouldThrowNotSupportedExceptionWhenChannelTypeIsNotSupported()
        {
            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 channelName = "dunno_" + _random.Next().ToString(CultureInfo.InvariantCulture);
            var channelType = _ascii.GetBytes(channelName);

            var sshDataStream = new SshDataStream(1 + 4 + channelType.Length + 4 + 4 + 4);
            sshDataStream.WriteByte(ChannelOpenMessage.MessageNumber);
            sshDataStream.Write((uint) channelType.Length);
            sshDataStream.Write(channelType, 0, channelType.Length);
            sshDataStream.Write(localChannelNumber);
            sshDataStream.Write(initialWindowSize);
            sshDataStream.Write(maximumPacketSize);
            var bytes = sshDataStream.ToArray();
            var target = new ChannelOpenMessage();

            try
            {
                target.Load(bytes);
                Assert.Fail();
            }
            catch (NotSupportedException ex)
            {
                Assert.IsNull(ex.InnerException);
                Assert.AreEqual(string.Format("Channel type '{0}' is not supported.", channelName), ex.Message);
            }
        }
Пример #10
0
        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);

            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 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);
        }
Пример #11
0
        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);

            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 sessionChannelOpenInfo = target.Info as SessionChannelOpenInfo;
            Assert.IsNotNull(sessionChannelOpenInfo);
            Assert.AreEqual(info.ChannelType, sessionChannelOpenInfo.ChannelType);
        }
Пример #12
0
        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);
        }
Пример #13
0
        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);
        }
        private bool AssertExpectedMessage(ChannelOpenMessage channelOpenMessage)
        {
            if (channelOpenMessage == null)
                return false;
            if (channelOpenMessage.LocalChannelNumber != _localChannelNumber)
                return false;
            if (channelOpenMessage.InitialWindowSize != _localWindowSize)
                return false;
            if (channelOpenMessage.MaximumPacketSize != _localPacketSize)
                return false;

            var directTcpipChannelInfo = channelOpenMessage.Info as DirectTcpipChannelInfo;
            if (directTcpipChannelInfo == null)
                return false;
            if (directTcpipChannelInfo.HostToConnect != _remoteHost)
                return false;
            if (directTcpipChannelInfo.PortToConnect != _port)
                return false;

            var clientEndpoint = _client.LocalEndPoint as IPEndPoint;
            if (clientEndpoint == null)
                return false;
            if (directTcpipChannelInfo.OriginatorAddress != clientEndpoint.Address.ToString())
                return false;
            if (directTcpipChannelInfo.OriginatorPort != clientEndpoint.Port)
                return false;

            return true;
        }