Esempio n. 1
0
        public void ConnectShouldSkipContentWhenHttpProxyReturnsHttpStatus200()
        {
            var proxyEndPoint  = new IPEndPoint(IPAddress.Loopback, 8123);
            var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);

            using (var proxyStub = new HttpProxyStub(proxyEndPoint))
            {
                proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
                proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Content-Length: 13\r\n"));
                proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
                proxyStub.Responses.Add(Encoding.ASCII.GetBytes("\r\n"));
                proxyStub.Responses.Add(Encoding.ASCII.GetBytes("DUMMY_CONTENT"));
                proxyStub.Responses.Add(Encoding.ASCII.GetBytes("SSH-666-SshStub"));
                proxyStub.Start();

                using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object))
                {
                    try
                    {
                        session.Connect();
                        Assert.Fail();
                    }
                    catch (SshConnectionException ex)
                    {
                        Assert.IsNull(ex.InnerException);
                        Assert.AreEqual("Server version '666' is not supported.", ex.Message);
                    }
                }
            }
        }
Esempio n. 2
0
        public void ConnectShouldThrowProxyExceptionWhenHttpProxyReturnsHttpStatusOtherThan200()
        {
            var proxyEndPoint  = new IPEndPoint(IPAddress.Loopback, 8123);
            var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);

            using (var proxyStub = new HttpProxyStub(proxyEndPoint))
            {
                proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n"));
                proxyStub.Start();

                using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object))
                {
                    try
                    {
                        session.Connect();
                        Assert.Fail();
                    }
                    catch (ProxyException ex)
                    {
                        Assert.IsNull(ex.InnerException);
                        Assert.AreEqual("HTTP: Status code 501, \"Custom\"", ex.Message);
                    }
                }
            }
        }
Esempio n. 3
0
        public void ConnectShouldNotWriteProxyAuthorizationToHttpProxyWhenProxyUserNameIsNull()
        {
            var proxyEndPoint  = new IPEndPoint(IPAddress.Loopback, 8123);
            var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);

            using (var proxyStub = new HttpProxyStub(proxyEndPoint))
            {
                proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n"));
                proxyStub.Start();

                var connectionInfo = CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, null);
                using (var session = new Session(connectionInfo, _serviceFactoryMock.Object))
                {
                    try
                    {
                        session.Connect();
                        Assert.Fail();
                    }
                    catch (ProxyException)
                    {
                    }
                }

                Assert.IsFalse(proxyStub.HttpRequest.Headers.Any(p => p.StartsWith("Proxy-Authorization:")));
            }
        }
Esempio n. 4
0
        public void ConnectShouldWriteProxyAuthorizationToHttpProxyWhenProxyUserNameIsNotNullAndNotEmpty()
        {
            var proxyEndPoint  = new IPEndPoint(IPAddress.Loopback, 8123);
            var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);

            using (var proxyStub = new HttpProxyStub(proxyEndPoint))
            {
                proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n"));
                proxyStub.Start();

                var connectionInfo = CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon");
                using (var session = new Session(connectionInfo, _serviceFactoryMock.Object))
                {
                    try
                    {
                        session.Connect();
                        Assert.Fail();
                    }
                    catch (ProxyException)
                    {
                    }
                }

                var expectedProxyAuthorizationHeader = CreateProxyAuthorizationHeader(connectionInfo);
                Assert.IsNotNull(proxyStub.HttpRequest.Headers.SingleOrDefault(p => p == expectedProxyAuthorizationHeader));
            }
        }
Esempio n. 5
0
        public void ConnectShouldThrowProxyExceptionWhenHttpProxyResponseDoesNotContainStatusLine()
        {
            var proxyEndPoint  = new IPEndPoint(IPAddress.Loopback, 8123);
            var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);

            using (var proxyStub = new HttpProxyStub(proxyEndPoint))
            {
                proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Whatever\r\n"));
                proxyStub.Start();

                using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object))
                {
                    try
                    {
                        session.Connect();
                        Assert.Fail();
                    }
                    catch (ProxyException ex)
                    {
                        Assert.IsNull(ex.InnerException);
                        Assert.AreEqual("HTTP response does not contain status line.", ex.Message);
                    }
                }
            }
        }
Esempio n. 6
0
        public void ConnectShouldWriteConnectMethodToHttpProxy()
        {
            var proxyEndPoint  = new IPEndPoint(IPAddress.Loopback, 8123);
            var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);

            using (var proxyStub = new HttpProxyStub(proxyEndPoint))
            {
                proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n"));
                proxyStub.Start();

                using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object))
                {
                    try
                    {
                        session.Connect();
                        Assert.Fail();
                    }
                    catch (ProxyException)
                    {
                    }
                }

                Assert.AreEqual(string.Format("CONNECT {0} HTTP/1.0", serverEndPoint), proxyStub.HttpRequest.RequestLine);
            }
        }