Ejemplo n.º 1
0
        public void TestInsertionOfTooLongString()
        {
            var watch = new Stopwatch();

            Application application = SingletonProvider <TestSetup> .Instance.GetApp();

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

            var sb = new StringBuilder();

            for (int i = 0; i < 1000; i++)
            {
                sb.Append("abcdefgh");
            }

            account.PersonFirstName = sb.ToString();

            try
            {
                watch.Start();
                account.Save();
            }
            catch (Exception)
            {
            }

            watch.Stop();
            Assert.Greater(10000, watch.ElapsedMilliseconds);

            // an error log file may have been created. if we're using MySQL,
            // the value may have been silently truncated.
            CustomAsserts.AssertDeleteFile(LogHandler.GetErrorLogFileName());
        }
Ejemplo n.º 2
0
        public void TestSPFWithDebugLogging()
        {
            Application application = SingletonProvider <TestSetup> .Instance.GetApp();

            string debugLog = _settings.Logging.CurrentDefaultLog;

            CustomAsserts.AssertDeleteFile(debugLog);

            // Create a test account
            // Fetch the default domain

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

            // Disallow incorrect line endings.
            _antiSpam.SpamMarkThreshold   = 1;
            _antiSpam.SpamDeleteThreshold = 100;
            _antiSpam.AddHeaderReason     = true;
            _antiSpam.AddHeaderSpam       = true;
            _antiSpam.PrependSubject      = true;
            _antiSpam.PrependSubjectText  = "ThisIsSpam";

            // Enable SPF
            _antiSpam.UseSPF      = true;
            _antiSpam.UseSPFScore = 12;

            // Send a messages to this account.
            var smtpClientSimulator = new SmtpClientSimulator();

            smtpClientSimulator.Send("*****@*****.**", oAccount1.Address, "SPF test", "This is a test message.");

            string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");

            if (!sMessageContents.Contains("X-hMailServer-Spam"))
            {
                throw new Exception("Spam message not detected as spam");
            }

            // Check that it has been logged.
            string contents = TestSetup.ReadExistingTextFile(debugLog);

            Assert.IsTrue(contents.Contains("Total spam score: 12"));
            Assert.IsTrue(contents.Contains("Spam test: SpamTestSPF, Score: 12"));

            CustomAsserts.AssertDeleteFile(debugLog);
        }
Ejemplo n.º 3
0
        public void FailedDeliveriesDueToGlobalRulesShouldBeLogged()
        {
            SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            CreateDeleteAllMailRule();

            // Failed delivery from local to local.
            SmtpClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1");

            // Verify that the failed delivery is logged
            string contents = TestSetup.ReadExistingTextFile(_logging.CurrentAwstatsLog);

            CustomAsserts.AssertDeleteFile(_logging.CurrentAwstatsLog);
            string expectedString = string.Format("\[email protected]\[email protected]\t127.0.0.1\t127.0.0.1\tSMTP\t?\t550\t");

            StringAssert.Contains(expectedString, contents);

            // Verify there's just 1 logged line
            Assert.AreEqual(1, contents.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Length);
        }
Ejemplo n.º 4
0
        public void FailedDeliveriesDueToAuthErrorShouldBeLogged()
        {
            SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            IPAddress localAddress        = TestSetup.GetLocalIpAddress();
            var       smtpClientSimulator = new SmtpClientSimulator(false, 25, localAddress);

            // Failed delivery from local to local.
            CustomAsserts.Throws <DeliveryFailedException>(() =>
                                                           smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1"));

            // Verify that the failed delivery is logged
            string contents = TestSetup.ReadExistingTextFile(_logging.CurrentAwstatsLog);

            CustomAsserts.AssertDeleteFile(_logging.CurrentAwstatsLog);
            string expectedString = string.Format("\[email protected]\[email protected]\t{0}\t127.0.0.1\tSMTP\t?\t530\t", localAddress);

            StringAssert.Contains(expectedString, contents);

            // Verify there's just 1 logged line
            Assert.AreEqual(1, contents.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Length);
        }
Ejemplo n.º 5
0
        public void TestAwstatsLog()
        {
            Settings settings = SingletonProvider <TestSetup> .Instance.GetApp().Settings;

            Logging logging = settings.Logging;

            logging.AWStatsEnabled = true;
            logging.Enabled        = true;

            if (File.Exists(logging.CurrentAwstatsLog))
            {
                File.Delete(logging.CurrentAwstatsLog);
            }

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

            IPAddress localAddress        = TestSetup.GetLocalIpAddress();
            var       smtpClientSimulator = new SmtpClientSimulator(false, 25, localAddress);

            // Delivery from external to local.
            smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1");
            Pop3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 1);
            string contents = TestSetup.ReadExistingTextFile(logging.CurrentAwstatsLog);

            CustomAsserts.AssertDeleteFile(logging.CurrentAwstatsLog);
            string expectedString = string.Format("\[email protected]\[email protected]\t{0}\t127.0.0.1\tSMTP\t?\t250\t",
                                                  localAddress);

            Assert.IsTrue(contents.Contains(expectedString), contents);

            // Failed delivery from local to local.
            CustomAsserts.Throws <DeliveryFailedException>(() => smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1"));
            contents = TestSetup.ReadExistingTextFile(logging.CurrentAwstatsLog);
            CustomAsserts.AssertDeleteFile(logging.CurrentAwstatsLog);
            expectedString = string.Format("\[email protected]\[email protected]\t{0}\t127.0.0.1\tSMTP\t?\t530\t",
                                           localAddress);
            Assert.IsTrue(contents.Contains(expectedString), contents);
        }