Example #1
0
        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();
             CustomAssert.IsTrue(sim.ConnectAndLogon(account.Address, "test"));
             sim.Disconnect();

             // confirm that we can retrieve welcome message.
             CustomAssert.IsTrue(sim.GetWelcomeMessage().StartsWith("+OK"));

             string errorMessage;
             // fail to log on 3 times.
             for (int i = 0; i < 5; i++)
             {
            CustomAssert.IsFalse(sim.ConnectAndLogon(account.Address, "testA", out errorMessage));
            sim.Disconnect();
             }

             CustomAssert.IsTrue(sim.GetWelcomeMessage().StartsWith("+OK"));

             string logText = TestSetup.ReadCurrentDefaultLog();
             CustomAssert.IsFalse(logText.Contains("Blocked either by IP range or by connection limit."), logText);
        }
Example #2
0
        public void TestImproperDisconnect()
        {
            TestSetup.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 oPOP3 = new POP3ClientSimulator();
             oPOP3.ConnectAndLogon(account.Address, "test");
             TestSetup.AssertSessionCount(eSessionType.eSTPOP3, iCount + 1);
             oPOP3.Disconnect(); // Disconnect without sending quit

             TestSetup.AssertSessionCount(eSessionType.eSTPOP3, iCount);
        }
Example #3
0
        public void TestEmptyPassword()
        {
            Account account1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "");

             string message;
             var sim = new POP3ClientSimulator();
             CustomAssert.IsFalse(sim.ConnectAndLogon(account1.Address, "", out message));

             var simIMAP = new IMAPClientSimulator();
             CustomAssert.IsFalse(simIMAP.ConnectAndLogon(account1.Address, "", out message));
             CustomAssert.AreEqual("A01 NO Invalid user name or password.\r\n", message);

             var simSMTP = new SMTPClientSimulator();
             CustomAssert.IsFalse(simSMTP.ConnectAndLogon("dGVzdEB0ZXN0LmNvbQ==", "", out message));
             CustomAssert.AreEqual("535 Authentication failed. Restarting authentication process.\r\n", message);
        }
Example #4
0
        public void TestAttachmentEncoding()
        {
            string[] testFiles = GetTestFiles();

             SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             foreach (string testFile in testFiles)
             {
            Trace.WriteLine(testFile);

            string fileHash = TestSetup.GetFileHash(testFile);

            var mail = new MailMessage();
            mail.From = new MailAddress("*****@*****.**");
            mail.To.Add("*****@*****.**");
            mail.Subject = "Test";
            mail.Attachments.Add(new Attachment(testFile));

            TestSetup.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 = TestSetup.GetFileHash(message.Filename);

               CustomAssert.AreEqual(fileHash, fileHashAfter);
            }
            finally
            {
               File.Delete(message.Filename);
            }
             }
        }
 public void TestPOP3Server()
 {
     var sim = new POP3ClientSimulator();
      sim.ConnectAndLogon(GetUsername(), GetPassword());
      EnsureNoPassword();
 }
Example #6
0
        public void TestReinitialize()
        {
            string @messageText =
            "From: [email protected]\r\n" +
            "\r\n" +
            "WhatTest\r\n";

             Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             CustomAssert.IsTrue(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);
             CustomAssert.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();

             CustomAssert.IsTrue(messageText.Contains("WhatTest"), messageText);
        }
Example #7
0
        public void TestIPRangeName()
        {
            _settings.AutoBanOnLogonFailure = true;
             _settings.MaxInvalidLogonAttempts = 3;
             _settings.MaxInvalidLogonAttemptsWithin = 5;
             _settings.AutoBanMinutes = 3;

             CustomAssert.AreEqual(2, _settings.SecurityRanges.Count);

             Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var sim = new POP3ClientSimulator();
             CustomAssert.IsTrue(sim.ConnectAndLogon(account.Address, "test"));
             sim.Disconnect();

             // confirm that we can retrieve welcome message.
             CustomAssert.IsTrue(sim.GetWelcomeMessage().StartsWith("+OK"));

             string errorMessage;
             // fail to log on 3 times.
             for (int i = 0; i < 3; i++)
             {
            CustomAssert.IsFalse(sim.ConnectAndLogon(account.Address, "testA", out errorMessage));
            sim.Disconnect();

            if (i == 2)
            {
               CustomAssert.IsTrue(errorMessage.Contains("Too many invalid logon attempts."));
            }
             }

             CustomAssert.IsTrue(sim.GetWelcomeMessage().Length == 0);

             CustomAssert.AreEqual(3, _settings.SecurityRanges.Count);
             CustomAssert.AreEqual("Auto-ban: [email protected]", _settings.SecurityRanges[2].Name);
        }
Example #8
0
        public void TestDELEInvalid()
        {
            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");
             CustomAssert.IsFalse(sim.DELE(0));
             CustomAssert.IsFalse(sim.DELE(-1));
             CustomAssert.IsFalse(sim.DELE(1000));
             CustomAssert.IsTrue(sim.DELE(5));
        }
Example #9
0
        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();

             CustomAssert.IsTrue(result.Contains("8 messages"));
             CustomAssert.IsTrue(result.Contains("\r\n1"));
             CustomAssert.IsTrue(result.Contains("\r\n3"));
             CustomAssert.IsTrue(result.Contains("\r\n5"));
             CustomAssert.IsTrue(result.Contains("\r\n."));
        }
Example #10
0
        public void TestUIDLSpecific()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody1");
             SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody2");
             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.UIDL(2);

             CustomAssert.IsTrue(result.Contains("OK 2"));

             result = sim.UIDL(3);
             CustomAssert.IsTrue(result.Contains("OK 3"));
        }
Example #11
0
        public void TestUIDLInvalid()
        {
            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.UIDL(0);
             CustomAssert.IsTrue(result.Contains("No such message"));
             result = sim.UIDL(-1);
             CustomAssert.IsTrue(result.Contains("No such message"));
             result = sim.UIDL(100);
             CustomAssert.IsTrue(result.Contains("No such message"));
        }
Example #12
0
        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);

             CustomAssert.IsTrue(result.Contains("Received"));
             CustomAssert.IsTrue(result.Contains("Line1"));
             CustomAssert.IsTrue(result.Contains("Line2"));
             CustomAssert.IsFalse(result.Contains("Line3"));
             CustomAssert.IsFalse(result.Contains("Line4"));
        }
Example #13
0
        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);

             CustomAssert.IsTrue(result.Contains("Received"));
             CustomAssert.IsTrue(result.Contains("Subject"));
        }
Example #14
0
        public void TestPOP3TransactionSafety()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             CustomAssert.IsTrue(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();
             CustomAssert.IsTrue(imapSimulator.ConnectAndLogon(account.Address, "test"));
             CustomAssert.IsTrue(imapSimulator.SelectFolder("INBOX"));
             CustomAssert.IsTrue(imapSimulator.SetDeletedFlag(1));
             CustomAssert.IsTrue(imapSimulator.Expunge());
             CustomAssert.AreEqual(0, imapSimulator.GetMessageCount("Inbox"));

             CustomAssert.IsTrue(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();

             CustomAssert.AreEqual(1, imapSimulator.GetMessageCount("Inbox"));
        }
Example #15
0
        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();

             CustomAssert.IsTrue(listResponse.Contains("\r\n1"));
             CustomAssert.IsTrue(listResponse.Contains("\r\n2"));
             CustomAssert.IsTrue(listResponse.Contains("\r\n3"));
             CustomAssert.IsTrue(listResponse.Contains("\r\n.\r\n"));
             CustomAssert.IsTrue(listResponse.Contains("3 messages"));

             CustomAssert.IsTrue(uidlResponse.Contains("\r\n1"));
             CustomAssert.IsTrue(uidlResponse.Contains("\r\n2"));
             CustomAssert.IsTrue(uidlResponse.Contains("\r\n3"));
             CustomAssert.IsTrue(uidlResponse.Contains("\r\n.\r\n"));
             CustomAssert.IsTrue(uidlResponse.Contains("3 messages"));
        }
Example #16
0
        public void TestNotificationOnPOP3Deletion()
        {
            _settings.IMAPIdleEnabled = true;

             Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             SMTPClientSimulator.StaticSend(account.Address, account.Address, "Message 1", "Body 1");
             SMTPClientSimulator.StaticSend(account.Address, account.Address, "Message 1", "Body 1");
             POP3ClientSimulator.AssertMessageCount(account.Address, "test", 2);

             var imapSimulator = new IMAPClientSimulator();
             string sWelcomeMessage = imapSimulator.Connect();
             CustomAssert.IsTrue(imapSimulator.Logon("*****@*****.**", "test"));
             CustomAssert.IsTrue(imapSimulator.SelectFolder("INBOX"));
             CustomAssert.IsTrue(imapSimulator.StartIdle());

             var sim = new POP3ClientSimulator();
             CustomAssert.IsTrue(sim.ConnectAndLogon(account.Address, "test"));
             CustomAssert.IsTrue(sim.DELE(1));
             sim.QUIT();

             // After a delete, the following should be sent tot he IMAP client:
             //  - EXPUNGE
             //  - EXISTS
             //  - RECENT
             CustomAssert.IsTrue(imapSimulator.AssertPendingDataExists(), "No pending data exist");

             var deadline = DateTime.Now.AddSeconds(10);
             var message = new StringBuilder();

             while (DateTime.Now < deadline)
             {
            if (imapSimulator.GetPendingDataExists())
               message.Append(imapSimulator.Receive());

            var str = message.ToString();

            if (str.Contains("* 1 EXPUNGE") &&
                str.Contains("EXISTS") &&
                str.Contains("RECENT"))
            {
               return;
            }
             }

             var receivedText = message.ToString();
             CustomAssert.IsTrue(receivedText.Contains("* 1 EXPUNGE"), receivedText);
             CustomAssert.IsTrue(receivedText.Contains("EXISTS"), receivedText);
             CustomAssert.IsTrue(receivedText.Contains("RECENT"), receivedText);
        }