public void Send100MBMessage() { long memoryUsage = Shared.GetCurrentMemoryUsage(); _application.Settings.MaxMessageSize = 0; TcpConnection socket = new TcpConnection(); 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 = 1; i <= 100; i++) { Shared.AssertLowMemoryUsage(memoryUsage + 30); try { socket.Send(sb.ToString()); } catch (Exception) { return; } if ((i % 10) == 0) { TestTracer.WriteTraceInfo("{0}/{1}", i, 1000); } } 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(); Pop3ClientSimulator.AssertMessageCount(_domain.Accounts[0].Address, "test", 1); }
public void ConnectionCountShouldDecreaseWhenClientDisconnects() { var countBefore = _application.Status.get_SessionCount(eSessionType.eSTSMTP); using (var tcpConn = new TcpConnection(false)) { tcpConn.Connect(25001); // Since there may be other connections lingering, we just check the increased count if // it was zero previous to this test. Otherwise we might end up with false positives. if (countBefore == 0) { RetryHelper.TryAction(TimeSpan.FromSeconds(10), () => { var countWhileConnected = _application.Status.get_SessionCount(eSessionType.eSTSMTP); Assert.AreEqual(1, countWhileConnected); }); } } RetryHelper.TryAction(TimeSpan.FromSeconds(10), () => { var countAfter = _application.Status.get_SessionCount(eSessionType.eSTSMTP); Assert.GreaterOrEqual(countBefore, countAfter); }); }
public IMAPSimulator(string username, string password, string mailbox) { _tcpConnection = new TcpConnection(); CustomAssert.IsTrue(ConnectAndLogon(username, password)); CustomAssert.IsTrue(SelectFolder(mailbox)); }
public void SetupSSLPort() { _application.Settings.Logging.Enabled = true; _application.Settings.Logging.LogTCPIP = true; _application.Settings.Logging.EnableLiveLogging(true); var cs = new TcpConnection(); if (!cs.Connect(250)) CustomAssert.Fail("Could not connect to SSL server."); cs.Disconnect(); for (int i = 0; i <= 40; i++) { CustomAssert.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); }
public void TestExcessiveDataInPOP3Conversation() { var sb = new StringBuilder(); for (int i = 0; i < 100000; i++) { sb.Append("1234567890"); } string command = "HELP " + sb; var socket = new TcpConnection(); CustomAssert.IsTrue(socket.Connect(110)); socket.Receive(); socket.Send(command + "\r\n"); try { string response = socket.Receive(); CustomAssert.IsTrue(response.StartsWith("-ERR")); socket.Disconnect(); } catch (IOException ex) { AssertIsConnectionTerminatedException(ex); } }
public void TestExcessiveDataInIMAPConversation() { 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 TcpConnection(); CustomAssert.IsTrue(socket.Connect(143)); socket.Receive(); socket.Send(command); try { string response = socket.Receive(); CustomAssert.IsTrue(response.StartsWith("* BYE")); } catch (System.IO.IOException ex) { AssertIsConnectionTerminatedException(ex); } socket.Disconnect(); }
public void IfStartTlsNotEnabledStartTlsShouldNotBeShownInEhloResponse() { var smtpClientSimulator = new TcpConnection(); smtpClientSimulator.Connect(25); var data1 = smtpClientSimulator.Receive(); var data = smtpClientSimulator.SendAndReceive("EHLO example.com\r\n"); Assert.IsFalse(data.Contains("STARTTLS")); }
public void IfStlsRequiredLogonShouldFailIfNoStls() { var smtpClientSimulator = new TcpConnection(); smtpClientSimulator.Connect(25003); var banner = smtpClientSimulator.Receive(); var capabilities1 = smtpClientSimulator.SendAndReceive("EHLO example.com\r\n"); Assert.IsTrue(capabilities1.Contains("STARTTLS")); var loginResult = smtpClientSimulator.SendAndReceive("AUTH LOGIN\r\n"); Assert.IsTrue(loginResult.StartsWith("530 Must issue STARTTLS first.")); }
public void TestConnectingToPop3ServerIncreasesPop3SessionCount() { var app = SingletonProvider<TestSetup>.Instance.GetApp(); var status = app.Status; int countBefore = status.get_SessionCount(eSessionType.eSTPOP3); using (var conn1 = new TcpConnection()) { CustomAssert.IsTrue(conn1.Connect(110)); TestSetup.AssertSessionCount(eSessionType.eSTPOP3, countBefore + 1); } }
public void TestConnectingToImapServerIncreasesImapSessionCount() { var app = SingletonProvider<TestSetup>.Instance.GetApp(); var status = app.Status; int countBefore = status.get_SessionCount(eSessionType.eSTIMAP); using (var conn1 = new TcpConnection()) { Assert.IsTrue(conn1.Connect(143)); CustomAsserts.AssertSessionCount(eSessionType.eSTIMAP, countBefore + 1); } }
public void IfStlsOptionalButSslRequiredByIpRangeForAuthThenAuthShouldFail() { var range = SingletonProvider<TestSetup>.Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer"); range.RequireSSLTLSForAuth = true; range.Save(); var smtpClientSimulator = new TcpConnection(); smtpClientSimulator.Connect(25002); var banner = smtpClientSimulator.Receive(); var capabilities1 = smtpClientSimulator.SendAndReceive("EHLO example.com\r\n"); Assert.IsTrue(capabilities1.Contains("STARTTLS")); var loginResult = smtpClientSimulator.SendAndReceive("AUTH LOGIN\r\n"); Assert.IsTrue(loginResult.StartsWith("530 A SSL/TLS-connection is required for authentication.")); // must run starttls first. }
public void HandshakeCompletionShouldBeLoggedWithCipherDetails() { var smtpClientSimulator = new TcpConnection(); smtpClientSimulator.Connect(25002); var banner = smtpClientSimulator.Receive(); var capabilities1 = smtpClientSimulator.SendAndReceive("EHLO example.com\r\n"); Assert.IsTrue(capabilities1.Contains("STARTTLS")); smtpClientSimulator.SendAndReceive("STARTTLS\r\n"); smtpClientSimulator.HandshakeAsClient(); var capabilities2 = smtpClientSimulator.SendAndReceive("EHLO example.com\r\n"); var default_log = LogHandler.ReadCurrentDefaultLog(); Assert.IsTrue(default_log.Contains("Version: TLS")); Assert.IsTrue(default_log.Contains("Cipher: ")); Assert.IsTrue(default_log.Contains("Bits: ")); }
public static void AssertClamDRunning() { Process[] processlist = Process.GetProcesses(); foreach (Process theprocess in processlist) { if (theprocess.ProcessName == "clamd") { return; } } // Check if we can launch it... var startInfo = new ProcessStartInfo(); startInfo.FileName = @"C:\clamav\clamd.exe"; startInfo.WorkingDirectory = @"C:\Clamav"; startInfo.Arguments = "--daemon"; try { Process.Start(startInfo); // Wait for clamav to start up. for (int i = 0; i < 10; i++) { var sock = new TcpConnection(); if (sock.Connect(3310)) { return; } Thread.Sleep(1000); } CustomAssert.Fail("ClamD process not starting up."); } catch (Exception) { CustomAssert.Inconclusive("Unable to start ClamD process. Is ClamAV installed?"); } }
public void TestManyTCPIPConnections() { LogHandler.DeleteCurrentDefaultLog(); const int count = 1000; List<TcpConnection> sockets = new List<TcpConnection>(); for (int i = 1; i <= count; i++) { TcpConnection socket = new TcpConnection(); Assert.IsTrue(socket.Connect(25)); if ((i % 10) == 0) { TestTracer.WriteTraceInfo("{0}/{1}", i, 1000); } sockets.Add(socket); } foreach (TcpConnection socket in sockets) { socket.Disconnect(); } RetryHelper.TryAction(() => { string log = LogHandler.ReadCurrentDefaultLog(); string connectionCreated = "TCP - 127.0.0.1 connected to 127.0.0.1:25."; string connectionEnded = "Ending session "; var created = Regex.Matches(log, connectionCreated); var ended = Regex.Matches(log, connectionEnded); Assert.AreEqual(count, created.Count); Assert.AreEqual(count, ended.Count); }, TimeSpan.FromSeconds(1),TimeSpan.FromSeconds(30)); }
public void AuthShouldUpdateLastLogonTime() { Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); DateTime lastLogonTimeBefore = Convert.ToDateTime(account.LastLogonTime); Thread.Sleep(1000); var sock = new TcpConnection(); sock.Connect(25); CustomAssert.IsTrue(sock.Receive().StartsWith("220")); sock.Send("EHLO test.com\r\n"); CustomAssert.IsTrue(sock.Receive().StartsWith("250")); string base64EncodedUsername = EncodeBase64("*****@*****.**"); sock.Send("AUTH LOGIN " + base64EncodedUsername + "\r\n"); CustomAssert.IsTrue(sock.Receive().StartsWith("334")); sock.Send(EncodeBase64("test") + "\r\n"); CustomAssert.IsTrue(sock.Receive().StartsWith("235")); DateTime lastLogonTimeAfter = Convert.ToDateTime(SingletonProvider<TestSetup>.Instance.GetApp().Domains[0].Accounts[0].LastLogonTime); CustomAssert.AreNotEqual(lastLogonTimeBefore, lastLogonTimeAfter); }
public void TestLongSMTPCommand() { var socket = new TcpConnection(); socket.Connect(25); // Build a large string... var sb = new StringBuilder(); sb.Append("A01"); for (int i = 0; i < 1000000; i++) { sb.Append("01234567890"); } sb.Append(Environment.NewLine); for (int i = 0; i < 100; i++) { try { socket.Send(sb.ToString()); } catch (Exception) { return; } if ((i % 10) == 0) { TestTracer.WriteTraceInfo("{0}/{1}", i, 100); } } socket.Send("\r\n"); socket.Receive(); socket.Disconnect(); }
public static void AssertClamDRunning() { Process[] processlist = Process.GetProcesses(); foreach (Process theprocess in processlist) { if (theprocess.ProcessName == "clamd") return; } // Check if we can launch it... var startInfo = new ProcessStartInfo(); startInfo.FileName = @"C:\clamav\clamd.exe"; startInfo.WorkingDirectory = @"C:\Clamav"; startInfo.Arguments = "--daemon"; try { Process.Start(startInfo); // Wait for clamav to start up. for (int i = 0; i < 10; i++) { var sock = new TcpConnection(); if (sock.Connect(3310)) return; Thread.Sleep(1000); } CustomAssert.Fail("ClamD process not starting up."); } catch (Exception) { CustomAssert.Inconclusive("Unable to start ClamD process. Is ClamAV installed?"); } }
public void TestConnections() { var oSocket = new TcpConnection(); // Make sure an IP range exists. RemoveIPRanges(); if (_ipRanges.Count == 0) AddIPRange(); if (!oSocket.IsPortOpen(25)) throw new Exception("ERROR: Cannot connect to port 25"); if (!oSocket.IsPortOpen(110)) throw new Exception("ERROR: Cannot connect to port 110"); if (!oSocket.IsPortOpen(143)) throw new Exception("ERROR: Cannot connect to port 143"); RemoveIPRanges(); // Now it shouldn't be possible to connect. if (oSocket.IsPortOpen(25)) throw new Exception("ERROR: Cannot connect to port 25"); if (oSocket.IsPortOpen(110)) throw new Exception("ERROR: Cannot connect to port 110"); if (oSocket.IsPortOpen(143)) throw new Exception("ERROR: Cannot connect to port 143"); AddIPRange(); // Now it should be possible to connect again. if (!oSocket.IsPortOpen(25)) throw new Exception("ERROR: Cannot connect to port 25"); if (!oSocket.IsPortOpen(110)) throw new Exception("ERROR: Cannot connect to port 110"); if (!oSocket.IsPortOpen(143)) throw new Exception("ERROR: Cannot connect to port 143"); }
public void TestSameRecipientMultipleTimes() { Logging logging = SingletonProvider<TestSetup>.Instance.GetApp().Settings.Logging; logging.AWStatsEnabled = true; logging.Enabled = true; if (File.Exists(logging.CurrentAwstatsLog)) File.Delete(logging.CurrentAwstatsLog); Account account1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); var oSMTP = new TcpConnection(); oSMTP.Connect(25); CustomAssert.IsTrue(oSMTP.Receive().StartsWith("220")); oSMTP.Send("HELO test\r\n"); CustomAssert.IsTrue(oSMTP.Receive().StartsWith("250")); oSMTP.Send("MAIL FROM: [email protected]\r\n"); CustomAssert.IsTrue(oSMTP.Receive().StartsWith("250")); oSMTP.Send("RCPT TO: [email protected]\r\n"); CustomAssert.IsTrue(oSMTP.Receive().StartsWith("250")); oSMTP.Send("RCPT TO: [email protected]\r\n"); CustomAssert.IsTrue(oSMTP.Receive().StartsWith("250")); oSMTP.Disconnect(); }
public void TestTooManyInvalidCommandsAUTH() { Application application = SingletonProvider<TestSetup>.Instance.GetApp(); Settings settings = _settings; settings.DisconnectInvalidClients = true; settings.MaxNumberOfInvalidCommands = 3; var sim = new TcpConnection(); sim.Connect(25); sim.Send("EHLO test.com\r\n"); for (int i = 1; i <= 6; i++) { try { sim.Send("AUTH LOGIN\r\n"); string result = sim.Receive(); if (result.Contains("Too many invalid commands")) return; if (i > 5) break; sim.Send("YWNhZGVtaWE=\r\n"); sim.Receive(); sim.Send("abc\r\n"); sim.Receive(); } catch (Exception) { if (i < 5) { CustomAssert.Fail("Was disconnected prematurely."); } return; } } CustomAssert.Fail("Wasn't disconnected"); }
public void TestMailFromSyntaxValidation() { Account account1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); var oSMTP = new TcpConnection(); oSMTP.Connect(25); CustomAssert.IsTrue(oSMTP.Receive().StartsWith("220")); oSMTP.Send("HELO test\r\n"); CustomAssert.IsTrue(oSMTP.Receive().StartsWith("250")); // A few tests of invalid syntax. CustomAssert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: <[email protected]\r\n").StartsWith("250")); CustomAssert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: [email protected]>\r\n").StartsWith("250")); CustomAssert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: < [email protected] \r\n").StartsWith("250")); CustomAssert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: < \r\n").StartsWith("250")); CustomAssert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: > \r\n").StartsWith("250")); CustomAssert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: <[email protected]\r\n").StartsWith("250")); CustomAssert.IsFalse(oSMTP.SendAndReceive("MAIL FROM <*****@*****.**>\r\n").StartsWith("250")); CustomAssert.IsFalse(oSMTP.SendAndReceive("MAIL FROM [email protected]\r\n").StartsWith("250")); // Valid syntax, < and > CustomAssert.IsTrue(oSMTP.SendAndReceive("MAIL FROM: <*****@*****.**>\r\n").StartsWith("250")); CustomAssert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250")); CustomAssert.IsTrue(oSMTP.SendAndReceive("MAIL FROM: [email protected]\r\n").StartsWith("250")); CustomAssert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250")); CustomAssert.IsTrue(oSMTP.SendAndReceive("MAIL FROM: [email protected] \r\n").StartsWith("250")); CustomAssert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250")); CustomAssert.IsTrue(oSMTP.SendAndReceive("MAIL FROM:[email protected]\r\n").StartsWith("250")); CustomAssert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250")); CustomAssert.IsTrue(oSMTP.SendAndReceive("MAIL FROM:<*****@*****.**>\r\n").StartsWith("250")); CustomAssert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250")); oSMTP.Disconnect(); }
public void TestRcptToSyntax() { Account account1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); var oSMTP = new TcpConnection(); oSMTP.Connect(25); CustomAssert.IsTrue(oSMTP.Receive().StartsWith("220")); oSMTP.Send("HELO test\r\n"); CustomAssert.IsTrue(oSMTP.Receive().StartsWith("250")); // A few tests of invalid syntax. CustomAssert.IsTrue(oSMTP.SendAndReceive("MAIL FROM: <*****@*****.**>\r\n").StartsWith("250")); CustomAssert.IsFalse(oSMTP.SendAndReceive("RCPT TO: [email protected]>\r\n").StartsWith("250")); CustomAssert.IsFalse(oSMTP.SendAndReceive("RCPT TO: <[email protected]\r\n").StartsWith("250")); CustomAssert.IsFalse(oSMTP.SendAndReceive("RCPT TO <[email protected]\r\n").StartsWith("250")); CustomAssert.IsFalse(oSMTP.SendAndReceive("RCPT TO<[email protected]\r\n").StartsWith("250")); CustomAssert.IsTrue(oSMTP.SendAndReceive("RCPT TO: <*****@*****.**>\r\n").StartsWith("250")); CustomAssert.IsTrue(oSMTP.SendAndReceive("RCPT TO: [email protected]\r\n").StartsWith("250")); oSMTP.Disconnect(); }
public void TestEHLOKeywords() { Application application = SingletonProvider<TestSetup>.Instance.GetApp(); Settings settings = _settings; settings.HostName = "examplify.com"; var socket = new TcpConnection(); CustomAssert.IsTrue(socket.Connect(25)); string result = socket.Receive(); socket.Send("EHLO example.com\r\n"); result = socket.Receive(); socket.Disconnect(); CustomAssert.IsTrue(result.Contains("250-" + settings.HostName)); }
public void TestHelo() { var oSimulator = new TcpConnection(); oSimulator.Connect(25); string sWelcome = oSimulator.Receive(); oSimulator.Send("HELO\r\n"); string sResponse = oSimulator.Receive(); if (!sResponse.StartsWith("501")) throw new Exception("Invalid response to HELO"); oSimulator.Send("HELO \r\n"); sResponse = oSimulator.Receive(); if (!sResponse.StartsWith("501")) throw new Exception("Invalid response to HELO"); oSimulator.Send("HELO TEST.COM\r\n"); sResponse = oSimulator.Receive(); if (!sResponse.StartsWith("250")) throw new Exception("Invalid response to HELO"); oSimulator.Send("HELO TEST.COM\r\n"); sResponse = oSimulator.Receive(); if (!sResponse.StartsWith("250")) throw new Exception("Invalid response to HELO"); oSimulator.Send("EHLO TEST.COM\r\n"); sResponse = oSimulator.Receive(); if (!sResponse.StartsWith("250")) throw new Exception("Invalid response to HELO"); oSimulator.Send("EHLO TEST.COM\r\n"); sResponse = oSimulator.Receive(); if (!sResponse.StartsWith("250")) throw new Exception("Invalid response to HELO"); oSimulator.Disconnect(); }
public ImapClientSimulator() { _tcpConnection = new TcpConnection(); }
private void AssertValidMailRcptToCommand(string comamnd) { var smtpClientSimulator = new TcpConnection(); smtpClientSimulator.Connect(25); Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("220")); smtpClientSimulator.Send("HELO test\r\n"); Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("250")); smtpClientSimulator.Send("MAIL FROM: <*****@*****.**>\r\n"); Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("250")); string result = smtpClientSimulator.SendAndReceive(comamnd + "\r\n"); smtpClientSimulator.Disconnect(); Assert.AreEqual("250 OK\r\n", result); }
public ImapClientSimulator(bool useSSL, int port) { _tcpConnection = new TcpConnection(useSSL); _port = port; }
public Pop3ClientSimulator(IPAddress ipaddress, bool useSSL, int port) { _tcpConnection = new TcpConnection(useSSL); _port = port; _ipaddress = ipaddress; }
public void TestOnClientConnectVBScript() { Application app = SingletonProvider<TestSetup>.Instance.GetApp(); Scripting scripting = app.Settings.Scripting; string script = "Sub OnClientConnect(oClient) " + Environment.NewLine + " EventLog.Write(\"Port: \" & oClient.Port) " + Environment.NewLine + " EventLog.Write(\"Address: \" & oClient.IPAddress) " + Environment.NewLine + " EventLog.Write(\"Username: \" & oClient.Username) " + Environment.NewLine + "End Sub" + Environment.NewLine + Environment.NewLine; File.WriteAllText(scripting.CurrentScriptFile, script); scripting.Enabled = true; scripting.Reload(); string eventLogFile = app.Settings.Logging.CurrentEventLog; if (File.Exists(eventLogFile)) File.Delete(eventLogFile); var socket = new TcpConnection(); Assert.IsTrue(socket.IsPortOpen(25)); // Check that the message exists string message = TestSetup.ReadExistingTextFile(eventLogFile); Assert.IsNotEmpty(message); Assert.IsTrue(message.Contains("Port: 25")); Assert.IsTrue(message.Contains("Address: 127")); Assert.IsTrue(message.Contains("Username: \"")); // Should be empty, Username isn't available at this time. }
public void TestSMTPServerAuthPlain() { _settings.AllowSMTPAuthPlain = true; var sock = new TcpConnection(); sock.Connect(25); CustomAssert.IsTrue(sock.Receive().StartsWith("220")); sock.Send("EHLO test.com\r\n"); CustomAssert.IsTrue(sock.Receive().StartsWith("250")); sock.Send("AUTH PLAIN\r\n"); CustomAssert.IsTrue(sock.Receive().StartsWith("334")); string str = "\t" + GetUsername() + "\t" + GetPassword(); sock.Send(EncodeBase64(str) + "\r\n"); CustomAssert.IsTrue(sock.Receive().StartsWith("535")); EnsureNoPassword(); }
public void TestSMTPServerAuthLoginUsernameAsThirdParameter() { _settings.AllowSMTPAuthPlain = true; var sock = new TcpConnection(); sock.Connect(25); CustomAssert.IsTrue(sock.Receive().StartsWith("220")); sock.Send("EHLO test.com\r\n"); CustomAssert.IsTrue(sock.Receive().StartsWith("250")); string base64EncodedUsername = EncodeBase64(GetUsername()); sock.Send("AUTH LOGIN " + base64EncodedUsername + "\r\n"); CustomAssert.IsTrue(sock.Receive().StartsWith("334")); sock.Send(EncodeBase64(GetPassword()) + "\r\n"); CustomAssert.IsTrue(sock.Receive().StartsWith("535")); EnsureNoPassword(); }
public void TestTooManyInvalidCommandsHELO() { Settings settings = _settings; settings.DisconnectInvalidClients = true; settings.MaxNumberOfInvalidCommands = 3; var sim = new TcpConnection(); sim.Connect(25); sim.Receive(); // banner sim.SendAndReceive("HELO\r\n"); sim.SendAndReceive("HELO\r\n"); sim.SendAndReceive("HELO\r\n"); sim.SendAndReceive("HELO\r\n"); var result = sim.SendAndReceive("HELO\r\n"); CustomAssert.IsTrue(result.Contains("Too many invalid commands"), result); }
public Pop3ClientSimulator() { _tcpConnection = new TcpConnection(); }
public void TestTooManyInvalidCommandsTempError() { Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); for (int i = 0; i < 10; i++) SingletonProvider<TestSetup>.Instance.AddAccount(_domain, string.Format("test{0}@test.com", i), "test"); Application application = SingletonProvider<TestSetup>.Instance.GetApp(); Settings settings = _settings; settings.DisconnectInvalidClients = true; settings.MaxNumberOfInvalidCommands = 5; settings.AntiSpam.GreyListingEnabled = true; var sim = new TcpConnection(); sim.Connect(25); string res = sim.Receive(); sim.Send("EHLO test.com\r\n"); res = sim.Receive(); sim.Send("MAIL FROM: <*****@*****.**>\r\n"); res = sim.Receive(); for (int i = 1; i < 10; i++) { string address = string.Format("test{0}@test.com", i); sim.Send("RCPT TO: " + address + "\r\n"); res = sim.Receive(); CustomAssert.AreEqual("451 Please try again later.\r\n", res); } sim.Disconnect(); }
public SmtpClientSimulator(bool useSSL, SslProtocols sslProtocols, int port, IPAddress ipaddress) { _tcpConnection = new TcpConnection(useSSL, sslProtocols); _port = port; _ipaddress = ipaddress; }
public SMTPClientSimulator(bool useSSL, int port, IPAddress ipaddress) { _tcpConnection = new TcpConnection(useSSL); _port = port; _ipaddress = ipaddress; }