public void TestDisabled() { _settings.AutoBanOnLogonFailure = false; _settings.MaxInvalidLogonAttempts = 3; _settings.MaxInvalidLogonAttemptsWithin = 5; _settings.AutoBanMinutes = 3; Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var sim = new Pop3ClientSimulator(); Assert.IsTrue(sim.ConnectAndLogon(account.Address, "test")); sim.Disconnect(); // confirm that we can retrieve welcome message. Assert.IsTrue(sim.GetWelcomeMessage().StartsWith("+OK")); string errorMessage; // fail to log on 3 times. for (int i = 0; i < 5; i++) { Assert.IsFalse(sim.ConnectAndLogon(account.Address, "testA", out errorMessage)); sim.Disconnect(); } Assert.IsTrue(sim.GetWelcomeMessage().StartsWith("+OK")); string logText = LogHandler.ReadCurrentDefaultLog(); Assert.IsFalse(logText.Contains("Blocked either by IP range or by connection limit."), logText); }
public void TestRETR() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody1"); Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody2"); Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 2); SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody3"); Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 3); var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); string result = sim.RETR(1); Assert.IsTrue(result.Contains("TestBody1"), result); result = sim.RETR(2); Assert.IsTrue(result.Contains("TestBody2"), result); result = sim.RETR(3); Assert.IsTrue(result.Contains("TestBody3"), result); Assert.IsFalse(result.Contains(".\r\n.")); }
public void TestPOP3TransactionSafety() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody"); Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); // Now delete the message using an IMAP client. var imapSimulator = new ImapClientSimulator(); Assert.IsTrue(imapSimulator.ConnectAndLogon(account.Address, "test")); Assert.IsTrue(imapSimulator.SelectFolder("INBOX")); Assert.IsTrue(imapSimulator.SetDeletedFlag(1)); Assert.IsTrue(imapSimulator.Expunge()); Assert.AreEqual(0, imapSimulator.GetMessageCount("Inbox")); SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody"); ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); // This deletion should not have any effect, since the POP3 connection is referencing an old message. sim.DELE(1); sim.QUIT(); Assert.AreEqual(1, imapSimulator.GetMessageCount("Inbox")); }
public void TestPOP3Server() { var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(GetUsername(), GetPassword()); EnsureNoPassword(); }
public void TestIPRangeName() { _settings.AutoBanOnLogonFailure = true; _settings.MaxInvalidLogonAttempts = 3; _settings.MaxInvalidLogonAttemptsWithin = 5; _settings.AutoBanMinutes = 3; Assert.AreEqual(2, _settings.SecurityRanges.Count); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var sim = new Pop3ClientSimulator(); Assert.IsTrue(sim.ConnectAndLogon(account.Address, "test")); sim.Disconnect(); // confirm that we can retrieve welcome message. Assert.IsTrue(sim.GetWelcomeMessage().StartsWith("+OK")); string errorMessage; // fail to log on 3 times. for (int i = 0; i < 3; i++) { Assert.IsFalse(sim.ConnectAndLogon(account.Address, "testA", out errorMessage)); sim.Disconnect(); if (i == 2) { Assert.IsTrue(errorMessage.Contains("Too many invalid logon attempts.")); } } Assert.IsTrue(sim.GetWelcomeMessage().Length == 0); Assert.AreEqual(3, _settings.SecurityRanges.Count); Assert.AreEqual("Auto-ban: [email protected]", _settings.SecurityRanges[2].Name); }
public void TestTopDotOnOtherwiseEmptyLineShouldBeEscaped() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "Line1\r\nLine2\r\n..\r\nLine4\r\n..A\r\n.B\r\nLine6\r\n"); Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); string result = sim.TOP(1, 100); Assert.IsTrue(result.Contains("Line1\r\nLine2\r\n..\r\nLine4\r\n..A\r\nB\r\nLine6\r\n"), result); }
public void TestAttachmentEncoding() { string[] testFiles = GetTestFiles(); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); foreach (string testFile in testFiles) { Trace.WriteLine(testFile); string fileHash = GetFileHash(testFile); var mail = new MailMessage(); mail.From = new MailAddress("*****@*****.**"); mail.To.Add("*****@*****.**"); mail.Subject = "Test"; mail.Attachments.Add(new Attachment(testFile)); SendMessage(mail); Pop3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 1); var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon("*****@*****.**", "test"); string fileContent = sim.RETR(1); sim.DELE(1); sim.QUIT(); var message = new Message(); try { File.WriteAllText(message.Filename, fileContent); message.RefreshContent(); message.Attachments[0].SaveAs(message.Filename); string fileHashAfter = GetFileHash(message.Filename); Assert.AreEqual(fileHash, fileHashAfter); } finally { File.Delete(message.Filename); } } }
public void TestEmptyPassword() { Account account1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", ""); string message; var sim = new Pop3ClientSimulator(); Assert.IsFalse(sim.ConnectAndLogon(account1.Address, "", out message)); var simIMAP = new ImapClientSimulator(); Assert.IsFalse(simIMAP.ConnectAndLogon(account1.Address, "", out message)); Assert.AreEqual("A01 NO Invalid user name or password.\r\n", message); var simSMTP = new SmtpClientSimulator(); CustomAsserts.Throws<AuthenticationException>(() => simSMTP.ConnectAndLogon("dGVzdEB0ZXN0LmNvbQ==", "", out message)); Assert.AreEqual("535 Authentication failed. Restarting authentication process.\r\n", message); }
public void TestTOPInvalid() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); for (int i = 1; i <= 10; i++) { SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString()); } Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 10); var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); Assert.IsTrue(sim.TOP(-1, 0).Contains("No such message")); Assert.IsTrue(sim.TOP(0, 0).Contains("No such message")); Assert.IsTrue(sim.TOP(100, 0).Contains("No such message")); }
public void TestImproperDisconnect() { CustomAsserts.AssertSessionCount(eSessionType.eSTPOP3, 0); var application = SingletonProvider <TestSetup> .Instance.GetApp(); var account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); int iCount = application.Status.get_SessionCount(eSessionType.eSTPOP3); var pop3ClientSimulator = new Pop3ClientSimulator(); pop3ClientSimulator.ConnectAndLogon(account.Address, "test"); CustomAsserts.AssertSessionCount(eSessionType.eSTPOP3, iCount + 1); pop3ClientSimulator.Disconnect(); // Disconnect without sending quit CustomAsserts.AssertSessionCount(eSessionType.eSTPOP3, iCount); }
public void TestTOPSpecificEntire() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); for (int i = 1; i <= 10; i++) { SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString()); } Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 10); var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); string result = sim.TOP(1, 0); Assert.IsTrue(result.Contains("Received")); Assert.IsTrue(result.Contains("Subject")); }
public void TestLogonMailboxWithDeletedMessage() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); for (int i = 1; i <= 3; i++) { SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "Line1\r\nLine2\r\nLine3\r\nLine4\r\nLine\r\n"); } // Mark the second message as deleted using IMAP. Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 3); var sim = new ImapClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); sim.SelectFolder("INBOX"); sim.SetDeletedFlag(2); sim.Disconnect(); // Now list messages and confirm that all are listed. var pop3Client = new Pop3ClientSimulator(); pop3Client.ConnectAndLogon(account.Address, "test"); string listResponse = pop3Client.LIST(); string uidlResponse = pop3Client.UIDL(); Assert.IsTrue(listResponse.Contains("\r\n1")); Assert.IsTrue(listResponse.Contains("\r\n2")); Assert.IsTrue(listResponse.Contains("\r\n3")); Assert.IsTrue(listResponse.Contains("\r\n.\r\n")); Assert.IsTrue(listResponse.Contains("3 messages")); Assert.IsTrue(uidlResponse.Contains("\r\n1")); Assert.IsTrue(uidlResponse.Contains("\r\n2")); Assert.IsTrue(uidlResponse.Contains("\r\n3")); Assert.IsTrue(uidlResponse.Contains("\r\n.\r\n")); Assert.IsTrue(uidlResponse.Contains("3 messages")); }
public void TestReinitialize() { string @messageText = "From: [email protected]\r\n" + "\r\n" + "WhatTest\r\n"; Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SmtpClientSimulator.StaticSend(account.Address, account.Address, "First message", "Test message"); Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); // Create another message on disk and import it. string domainPath = Path.Combine(_application.Settings.Directories.DataDirectory, "test.com"); string accountPath = Path.Combine(domainPath, "test"); Directory.CreateDirectory(accountPath); string fileName = Path.Combine(accountPath, "something.eml"); File.WriteAllText(fileName, messageText); Assert.IsTrue(_application.Utilities.ImportMessageFromFile(fileName, account.ID)); // Since the cache isn't refreshed, the message has not yet appeared. Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); // Reinitialize the server. Should, among other things, clear the cache. _application.Reinitialize(); // Now the message should have appeared. Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 2); var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); messageText = sim.RETR(2); sim.QUIT(); Assert.IsTrue(messageText.Contains("WhatTest"), messageText); }
public void TestTOPSpecificPartial() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); for (int i = 1; i <= 10; i++) { SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "Line1\r\nLine2\r\nLine3\r\nLine4\r\nLine\r\n"); } Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 10); var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); string result = sim.TOP(4, 2); Assert.IsTrue(result.Contains("Received")); Assert.IsTrue(result.Contains("Line1")); Assert.IsTrue(result.Contains("Line2")); Assert.IsFalse(result.Contains("Line3")); Assert.IsFalse(result.Contains("Line4")); }
public void TestUIDLWithDeleted() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); for (int i = 1; i <= 10; i++) { SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString()); } Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 10); var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); sim.DELE(2); sim.DELE(4); string result = sim.UIDL(); Assert.IsTrue(result.Contains("8 messages")); Assert.IsTrue(result.Contains("\r\n1")); Assert.IsTrue(result.Contains("\r\n3")); Assert.IsTrue(result.Contains("\r\n5")); Assert.IsTrue(result.Contains("\r\n.")); }