Пример #1
0
        public void TestLongLineInPOP3Conversation()
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < 400; i++)
            {
                sb.Append("1234567890");
            }

            sb.Append(".com");

            string command = "NOOP " + sb.ToString();

            TCPSocket 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();
        }
Пример #2
0
        public void SetupSSLPort()
        {
            _application.Settings.Logging.Enabled  = true;
            _application.Settings.Logging.LogTCPIP = true;
            _application.Settings.Logging.EnableLiveLogging(true);

            TCPSocket 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);
        }
Пример #3
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();
        }
Пример #4
0
        public void TestLongLineInIMAPConversation()
        {
            // hMailServer is kind and allows up to 1000000 octets.
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < 100000; i++)
            {
                sb.Append("1234567890");
            }

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

            string command = "A03 NOOP " + sb.ToString();

            TCPSocket socket = new TCPSocket();

            Assert.IsTrue(socket.Connect(143));
            socket.Receive();
            socket.Send(command);

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


            socket.Disconnect();
        }
Пример #5
0
        public void TestLongLineInIMAPConversation()
        {
            // hMailServer is kind and allows up to 1000000 octets.
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 100000; i++)
            {
                sb.Append("1234567890");
            }

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

            string command = "A03 NOOP " + sb.ToString();

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

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

            socket.Disconnect();
        }
Пример #6
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);
        }
Пример #7
0
        public void TestPOP3DownloadOfLargeMessage()
        {
            TestLongSMTPDataSessionIncludingNewline();

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

            TCPSocket socket = new TCPSocket();

            socket.Connect(110);

            // Receive welcome message.
            string sData = socket.Receive();

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

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

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

            string sRetVal = "";

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

                sRetVal = socket.Receive();
            }

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

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

            socket.Disconnect();
        }
Пример #8
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();
        }
Пример #9
0
        public void TestManyTCPIPConnections()
        {
            Utilities.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 = Utilities.ReadCurrentDefaultLog();
        }
Пример #10
0
        public void TestLongLineInPOP3Conversation()
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 400; i++)
            {
                sb.Append("1234567890");
            }

            sb.Append(".com");

            string command = "NOOP " + sb.ToString();

            TCPSocket 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();
        }
Пример #11
0
        public void TestEHLOKeywords()
        {
            hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp();
              hMailServer.Settings settings = _settings;
              settings.HostName = "examplify.com";

              TCPSocket 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));
        }