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(); }
public void AuthShouldUpdateLastLogonTime() { Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); DateTime lastLogonTimeBefore = Convert.ToDateTime(account.LastLogonTime); Thread.Sleep(1000); var sock = new TcpSocket(); sock.Connect(25); Assert.IsTrue(sock.Receive().StartsWith("220")); sock.Send("EHLO test.com\r\n"); Assert.IsTrue(sock.Receive().StartsWith("250")); string base64EncodedUsername = EncodeBase64("*****@*****.**"); sock.Send("AUTH LOGIN " + base64EncodedUsername + "\r\n"); Assert.IsTrue(sock.Receive().StartsWith("334")); sock.Send(EncodeBase64("test") + "\r\n"); Assert.IsTrue(sock.Receive().StartsWith("235")); DateTime lastLogonTimeAfter = Convert.ToDateTime(SingletonProvider<TestSetup>.Instance.GetApp().Domains[0].Accounts[0].LastLogonTime); Assert.AreNotEqual(lastLogonTimeBefore, lastLogonTimeAfter); }
public void TestSendToTooManyRecipients() { hMailServer.Accounts accounts = _domain.Accounts; hMailServer.Account senderAccount = SingletonProvider<TestSetup>.Instance.AddAccount(accounts, string.Format("*****@*****.**"), "test"); List<string> recipients = new List<string>(); TcpSocket sock = new TcpSocket(); sock.Connect(25); string result = sock.ReadUntil("\r\n"); sock.Send("EHLO test.com\r\n"); result = sock.ReadUntil("\r\n"); Assert.IsTrue(result.StartsWith("250")); sock.Send("MAIL FROM: [email protected]\r\n"); result = sock.ReadUntil("\r\n"); Assert.IsTrue(result.StartsWith("250")); Stopwatch watch = new Stopwatch(); watch.Start(); for (int i = 0; i < 51000; i++) { string address = string.Format("test{0}@gmail.com", i); sock.Send(string.Format("RCPT TO: <{0}>\r\n", address)); result = sock.ReadUntil("\r\n"); if (i < 50000) { Assert.IsTrue(result.StartsWith("250")); } else { long perfor = watch.ElapsedMilliseconds; Assert.IsFalse(result.StartsWith("250")); } } }
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(); }
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(); }
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(); }
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(); }
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); }
public void TestSMTPServerAuthPlain() { _settings.AllowSMTPAuthPlain = true; var sock = new TcpSocket(); sock.Connect(25); Assert.IsTrue(sock.Receive().StartsWith("220")); sock.Send("EHLO test.com\r\n"); Assert.IsTrue(sock.Receive().StartsWith("250")); sock.Send("AUTH PLAIN\r\n"); Assert.IsTrue(sock.Receive().StartsWith("334")); string str = "\t" + GetUsername() + "\t" + GetPassword(); sock.Send(EncodeBase64(str) + "\r\n"); Assert.IsTrue(sock.Receive().StartsWith("535")); EnsureNoPassword(); }
public void TestSMTPServerAuthLoginUsernameAsThirdParameter() { _settings.AllowSMTPAuthPlain = true; var sock = new TcpSocket(); sock.Connect(25); Assert.IsTrue(sock.Receive().StartsWith("220")); sock.Send("EHLO test.com\r\n"); Assert.IsTrue(sock.Receive().StartsWith("250")); string base64EncodedUsername = EncodeBase64(GetUsername()); sock.Send("AUTH LOGIN " + base64EncodedUsername + "\r\n"); Assert.IsTrue(sock.Receive().StartsWith("334")); sock.Send(EncodeBase64(GetPassword()) + "\r\n"); Assert.IsTrue(sock.Receive().StartsWith("535")); EnsureNoPassword(); }
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)); }