public void TestFetchFromInvalidHostName() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); FetchAccount fa = account.FetchAccounts.Add(); fa.Enabled = true; fa.MinutesBetweenFetch = 10; fa.Name = "Test"; fa.Username = "******"; fa.Password = "******"; fa.UseSSL = false; fa.ServerAddress = "nonexistant.example.com"; fa.Port = 110; fa.ProcessMIMERecipients = false; fa.Save(); fa.DownloadNow(); RetryHelper.TryAction(TimeSpan.FromSeconds(10), () => { var log = LogHandler.ReadCurrentDefaultLog(); Assert.IsTrue( log.Contains("The IP address for external account Test could not be resolved. Aborting fetch.")); }); fa.Delete(); }
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); if (countWhileConnected != 1) { throw new ArgumentException($"Connection count not decreased. Expected: 1, Actual: {countWhileConnected}"); } }); } } RetryHelper.TryAction(TimeSpan.FromSeconds(10), () => { var countAfter = _application.Status.get_SessionCount(eSessionType.eSTSMTP); if (countBefore != countAfter) { throw new ArgumentException($"Connection count not decreased. Expected: countBefore, Actual: {countAfter}"); } }); }
public void ItShouldBePossibleToDisableSslV3() { SetSslVersions(true, true, true, true); var smtpClientSimulator = new SmtpClientSimulator(true, SslProtocols.Ssl3, 25001, IPAddress.Parse("127.0.0.1")); try { string errorMessage; smtpClientSimulator.Send(false, _account.Address, "test", _account.Address, _account.Address, "Test", "test", out errorMessage); Assert.Fail("Was able to establish SSLv3 connection"); } catch (System.Security.Authentication.AuthenticationException) { // on windows 10 } catch (System.IO.IOException) { // on windows xp } RetryHelper.TryAction(TimeSpan.FromSeconds(10), () => { var defaultLog = LogHandler.ReadCurrentDefaultLog(); Assert.IsTrue(defaultLog.Contains("Message: version too low")); }); }
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); }); }
private void WaitForFilesInFolder(string folder, int expectedCount) { // Check number of delivered messages. RetryHelper.TryAction(() => { int filesInFolder = GetNumberOfFilesInFolder(folder); Assert.AreEqual(expectedCount, filesInFolder); }, TimeSpan.FromSeconds(5), TimeSpan.FromMinutes(5)); }
private void WaitForMessageCount(TimeSpan timeout, int expectedMessageCount) { RetryHelper.TryAction(timeout, () => { var pop3ClientSimulator = new POP3ClientSimulator(); int count = pop3ClientSimulator.GetMessageCount("*****@*****.**", "test"); Assert.AreEqual(expectedMessageCount, count); }); }
public void TestServerNotSupportingUIDL() { var messages = new List <string>(); string message = "Received: from example.com (example.com [1.2.3.4]) by mail.host.edu\r\n" + "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!"; messages.Add(message); int port = TestSetup.GetNextFreePort(); using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.SupportsUIDL = false; pop3Server.StartListen(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); FetchAccount fa = account.FetchAccounts.Add(); fa.Enabled = true; fa.MinutesBetweenFetch = 10; fa.Name = "Test"; fa.Username = "******"; fa.Password = "******"; fa.UseSSL = false; fa.ServerAddress = "localhost"; fa.Port = port; fa.ProcessMIMERecipients = false; fa.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); RetryHelper.TryAction(TimeSpan.FromSeconds(10), () => { string error = LogHandler.ReadCurrentDefaultLog(); Assert.IsTrue(error.Contains("-ERR unhandled command")); Assert.IsTrue(error.Contains("Completed retrieval of messages from external account.")); }); } }
public void TestSendToManyRecipients() { // Add distribution list hMailServer.Accounts accounts = _domain.Accounts; var recipients = new List <string>(); for (int i = 0; i < 1000; i++) { hMailServer.Account account = SingletonProvider <TestSetup> .Instance.AddAccount(accounts, string.Format("recipient{0}@test.com", i), "test"); recipients.Add(account.Address); Marshal.ReleaseComObject(account); if (i % 10 == 0) { TestTracer.WriteTraceInfo("Creating accounts: {0}/{1}", i, 1000); } } Marshal.ReleaseComObject(accounts); var sw = new Stopwatch(); sw.Start(); SMTPClientSimulator.StaticSend("*****@*****.**", recipients, "Test", "Test message"); sw.Stop(); Console.WriteLine("Elapsed time: " + sw.Elapsed.TotalSeconds); string dataDir = Path.Combine(SingletonProvider <TestSetup> .Instance.GetApp().Settings.Directories.DataDirectory, "test.com"); // Check number of accounts. RetryHelper.TryAction(() => { if (IsFolderCountReached(dataDir, 1000)) { return; } throw new Exception("Not enough files in folder yet."); }, TimeSpan.FromSeconds(5), TimeSpan.FromMinutes(2)); }
public static void AssertReportedError(params string[] contents) { try { RetryHelper.TryAction(TimeSpan.FromSeconds(10), () => { string errorLog = ReadErrorLog(); foreach (var content in contents) { CustomAssert.IsTrue(errorLog.Contains(content), errorLog); } }); } finally { DeleteErrorLog(); } }
public void TestManyTCPIPConnections() { TestSetup.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 = TestSetup.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 SslV2ShouldBeDisabled() { SetSslVersions(true, true, true, true); var smtpClientSimulator = new SmtpClientSimulator(true, SslProtocols.Ssl2, 25001, IPAddress.Parse("127.0.0.1")); try { string errorMessage; smtpClientSimulator.Send(false, _account.Address, "test", _account.Address, _account.Address, "Test", "test", out errorMessage); } catch (System.IO.IOException) { // expected } RetryHelper.TryAction(TimeSpan.FromSeconds(10), () => { var defaultLog = LogHandler.ReadCurrentDefaultLog(); Assert.IsTrue(defaultLog.Contains("unknown protocol")); }); }
public void ItShouldBePossibleToDisableSslV3() { SetSslVersions(false, true, true, true); var smtpClientSimulator = new SmtpClientSimulator(true, SslProtocols.Ssl3, 25001, null); try { string errorMessage; smtpClientSimulator.Send(false, _account.Address, "test", _account.Address, _account.Address, "Test", "test", out errorMessage); Assert.Fail("Was able to establish SSLv3 connection"); } catch (System.IO.IOException) { // expected } RetryHelper.TryAction(TimeSpan.FromSeconds(10), () => { var defaultLog = LogHandler.ReadCurrentDefaultLog(); Assert.IsTrue(defaultLog.Contains("wrong version number")); }); }
public void TestSend200KMessages() { string dataDir = Path.Combine(SingletonProvider <TestSetup> .Instance.GetApp().Settings.Directories.DataDirectory, "test.com"); string accountDir = Path.Combine(dataDir, "test"); int memoryUsage = Shared.GetCurrentMemoryUsage(); int maxMemoryUsage = memoryUsage + 5; const int numberOfMessages = 200000; for (int i = 1; i <= numberOfMessages; i++) { Assert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Test", "Test message")); if (i % 100 == 0) { Shared.AssertLowMemoryUsage(maxMemoryUsage); TestTracer.WriteTraceInfo("{0}/{1}", i, numberOfMessages); } } // Check number of delivered messages. RetryHelper.TryAction(() => { Shared.AssertLowMemoryUsage(maxMemoryUsage); int actualNumberOfMessages = GetNumberOfFilesInFolder(accountDir); TestTracer.WriteTraceInfo("{0}/{1}", actualNumberOfMessages, numberOfMessages); Assert.AreEqual(numberOfMessages, actualNumberOfMessages); }, TimeSpan.FromSeconds(30), TimeSpan.FromHours(12)); _domain.Delete(); }