Пример #1
0
        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 SMTPClientSimulator();
             sim.Connect();
             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();
        }
Пример #2
0
        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 SMTPClientSimulator();
             oSMTP.Connect();
             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();
        }
Пример #3
0
        public void TestRcptToSyntax()
        {
            Account account1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var oSMTP = new SMTPClientSimulator();
             oSMTP.Connect();

             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();
        }
Пример #4
0
        public void TestMailFromSyntaxValidation()
        {
            Account account1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var oSMTP = new SMTPClientSimulator();
             oSMTP.Connect();

             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();
        }
Пример #5
0
        public void TestHelo()
        {
            var oSimulator = new SMTPClientSimulator();

             oSimulator.Connect();

             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();
        }
Пример #6
0
        public void TestSMTPLogonFailure()
        {
            _settings.AutoBanOnLogonFailure = true;
             _settings.MaxInvalidLogonAttempts = 2;
             _settings.MaxInvalidLogonAttemptsWithin = 5;
             _settings.AutoBanMinutes = 3;

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

             var sim = new SMTPClientSimulator();

             //[email protected] / test
             string errorMessage;
             CustomAssert.IsTrue(sim.ConnectAndLogon("dGVzdEB0ZXN0LmNvbQ==", "dGVzdA==", out errorMessage));
             sim.Disconnect();

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

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

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

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

             string logText = TestSetup.ReadCurrentDefaultLog();
             CustomAssert.IsTrue(logText.Contains("Blocked either by IP range or by connection limit."), logText);
        }