public void TestLongLineInIMAPConversation()
        {
            // hMailServer is kind and allows up to 1000000 octets.
             var sb = new StringBuilder();
             for (int i = 0; i < 100000; i++)
             {
            sb.Append("1234567890");
             }

             sb.Append(".com\r\n");

             string command = "A03 NOOP " + sb;

             var socket = new TcpSocket();
             Assert.IsTrue(socket.Connect(143));
             socket.Receive();
             socket.Send(command);

             try
             {
            string response = socket.Receive();
            Assert.IsTrue(response.StartsWith("* BYE"));
             }
             catch (SocketException ex)
             {
            Assert.IsTrue(ex.ErrorCode == 10054);
             }

             socket.Disconnect();
        }
Beispiel #2
0
        public void SetupSSLPort()
        {
            _application.Settings.Logging.Enabled = true;
             _application.Settings.Logging.LogTCPIP = true;
             _application.Settings.Logging.EnableLiveLogging(true);

             var cs = new TcpSocket();
             if (!cs.Connect(250))
            Assert.Fail("Could not connect to SSL server.");

             cs.Disconnect();

             for (int i = 0; i <= 40; i++)
             {
            Assert.IsTrue(i != 40);

            string liveLog = _application.Settings.Logging.LiveLog;
            if (liveLog.Contains("SSL handshake with client failed."))
               break;

            Thread.Sleep(250);
             }

             _application.Settings.Logging.EnableLiveLogging(false);
        }
Beispiel #3
0
        public void TestManyTCPIPConnections()
        {
            TestSetup.DeleteCurrentDefaultLog();

             const int count = 1000;

             List<TcpSocket> sockets = new List<TcpSocket>();
             for (int i = 0; i < count; i++)
             {
            TcpSocket socket = new TcpSocket();
            Assert.IsTrue(socket.Connect(25));

            sockets.Add(socket);
             }

             foreach (TcpSocket socket in sockets)
             {
            socket.Disconnect();
             }

             string log = TestSetup.ReadCurrentDefaultLog();
        }
        public void TestLongLineInPOP3Conversation()
        {
            var sb = new StringBuilder();
             for (int i = 0; i < 400; i++)
             {
            sb.Append("1234567890");
             }

             sb.Append(".com");

             string command = "NOOP " + sb;

             var socket = new TcpSocket();
             Assert.IsTrue(socket.Connect(110));
             socket.Receive();
             socket.Send(command + "\r\n");

             string response = socket.Receive();
             Assert.IsFalse(response.StartsWith("+OK"));

             socket.Disconnect();
        }
Beispiel #5
0
        public void TestLongSMTPCommand()
        {
            TcpSocket socket = new TcpSocket();
            socket.Connect(25);

            // Build a large string...
            StringBuilder sb = new StringBuilder();
            sb.Append("A01");
            for (int i = 0; i < 1000000; i++)
            {
                sb.Append("01234567890");
            }
            int length = sb.Length;

            sb.Append(Environment.NewLine);

            for (int i = 0; i < 100; i++)
            {
                try
                {
                    socket.Send(sb.ToString());
                }
                catch (Exception)
                {
                    return;
                }
            }

            socket.Send("\r\n");
            string result = socket.Receive();

            socket.Disconnect();
        }
Beispiel #6
0
        public void TestPOP3DownloadOfLargeMessage()
        {
            TestLongSMTPDataSessionIncludingNewline();

            POP3Simulator.AssertMessageCount("*****@*****.**", "test", 1);

            TcpSocket socket = new TcpSocket();
            socket.Connect(110);

            // Receive welcome message.
            socket.Receive();

            socket.Send("USER " + "*****@*****.**" + "\r\n");
            socket.ReadUntil("+OK");

            socket.Send("PASS " + "test" + "\r\n");
            socket.ReadUntil("+OK");

            socket.Send("RETR 1\r\n");

            var endOfResponseSB = new StringBuilder();

            string endOfResponse = "";
            while (endOfResponse.IndexOf("\r\n.\r\n") < 0)
            {
                if (endOfResponse.IndexOf("-ERR no such message") >= 0)
                {
                    socket.Disconnect();
                    Assert.Fail("Nope");
                }

                endOfResponseSB.Append(socket.Receive());

                if (endOfResponseSB.Length > 100)
                   endOfResponseSB.Remove(0, endOfResponseSB.Length - 100);

                endOfResponse = endOfResponseSB.ToString();
            }

            socket.Send("DELE 1\r\n");
            socket.ReadUntil("+OK");

            socket.Send("QUIT\r\n");
            socket.ReadUntil("+OK");

            socket.Disconnect();
        }
Beispiel #7
0
        public void TestLongSMTPDataSessionWithoutNewline()
        {
            long memoryUsage = Shared.GetCurrentMemoryUsage();

            TcpSocket socket = new TcpSocket();
            socket.Connect(25);
            socket.Receive();

            socket.Send("HELO test.com\r\n");
            socket.Receive();

            // Build a large string...
            StringBuilder sb = new StringBuilder();
            sb.Append("A01");
            for (int i = 0; i < 10000; i++)
            {
                sb.Append("01234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890");
            }
            int length = sb.Length;

            socket.Send("MAIL FROM: [email protected]\r\n");
            socket.Receive();
            socket.Send("RCPT TO: [email protected]\r\n");
            socket.Receive();
            socket.Send("DATA\r\n");
            socket.Receive();

            for (int i = 0; i < 1000; i++)
            {
                Shared.AssertLowMemoryUsage(memoryUsage+30);

                try
                {
                    socket.Send(sb.ToString());
                }
                catch (Exception)
                {
                    return;
                }
            }

            socket.Send("\r\n.\r\n");
            string result = socket.Receive();

            Assert.IsTrue(result.StartsWith("554 Too long line was received. Transmission aborted."));

            socket.Send("QUIT\r\n");
            result = socket.Receive();

            socket.Disconnect();
        }
Beispiel #8
0
        public void TestLongSMTPDataSessionIncludingNewline()
        {
            long memoryUsage = Shared.GetCurrentMemoryUsage();

               _application.Settings.MaxMessageSize = 0;

            TcpSocket socket = new TcpSocket();
            socket.Connect(25);
            socket.Receive();

            socket.Send("HELO test.com\r\n");
            socket.Receive();

            // Build a large string...
            StringBuilder sb = new StringBuilder();
            sb.Append("A01");
            for (int i = 0; i < 10000; i++)
            {
                sb.Append("01234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890\r\n");
            }
            int length = sb.Length;

            sb.Append(Environment.NewLine);

            socket.Send("MAIL FROM: [email protected]\r\n");
            socket.Receive();
            socket.Send("RCPT TO: [email protected]\r\n");
            socket.Receive();
            socket.Send("DATA\r\n");
            socket.Receive();

            for (int i = 0; i < 100; i++)
            {
                Shared.AssertLowMemoryUsage(memoryUsage+30);

                try
                {
                    socket.Send(sb.ToString());
                }
                catch (Exception)
                {
                    return;
                }
            }

            socket.Send("\r\n.\r\n");
            string result = socket.Receive();
            Assert.IsTrue(result.StartsWith("250"));

            socket.Send("QUIT\r\n");
            result = socket.Receive();
            socket.Disconnect();

            POP3Simulator.AssertMessageCount(_domain.Accounts[0].Address, "test", 1);
        }
Beispiel #9
0
        public void TestEHLOKeywords()
        {
            Application application = SingletonProvider<TestSetup>.Instance.GetApp();
             Settings settings = _settings;
             settings.HostName = "examplify.com";

             var socket = new TcpSocket();
             Assert.IsTrue(socket.Connect(25));
             string result = socket.Receive();
             socket.Send("EHLO example.com\r\n");
             result = socket.Receive();
             socket.Disconnect();
             Assert.IsTrue(result.Contains("250-" + settings.HostName));
        }