Ejemplo n.º 1
0
        public void TestTempErrorIfDiskFull()
        {
            Account senderAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

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

            Directories directories = SingletonProvider <TestSetup> .Instance.GetApp().Settings.Directories;

            string origDataDir = directories.DataDirectory;

            try
            {
                directories.DataDirectory = "C:\\FolderWhichDoesNotExist";

                string result = "";

                var sim = new SmtpClientSimulator();
                CustomAsserts.Throws <DeliveryFailedException>(() => sim.Send(senderAccount.Address, recipientAccount.Address, "MySubject", "Test", out result));

                Assert.IsTrue(result.StartsWith("4"), "Expected temporary error, but was: " + result);

                CustomAsserts.AssertReportedError("Failed to write to the file",
                                                  "Rejected message because no mail data has been saved in file");
            }
            finally
            {
                directories.DataDirectory = origDataDir;
            }
        }
Ejemplo n.º 2
0
        public void SetupSSLCertificateWithPassword()
        {
            string sslPath = Path.Combine(SslSetup.GetSslCertPath(), "WithPassword");

            SSLCertificate sslCertificate = _application.Settings.SSLCertificates.Add();

            sslCertificate.Name            = "Example";
            sslCertificate.CertificateFile = sslPath + "\\server.crt";
            sslCertificate.PrivateKeyFile  = sslPath + "\\server.key";
            sslCertificate.Save();

            TCPIPPort port = _application.Settings.TCPIPPorts.Add();

            port.Address          = "0.0.0.0";
            port.PortNumber       = 251;
            port.UseSSL           = true;
            port.SSLCertificateID = sslCertificate.ID;
            port.Protocol         = eSessionType.eSTSMTP;
            port.Save();

            _application.Stop();
            _application.Start();

            CustomAsserts.AssertReportedError("The private key file has a password. hMailServer does not support this.",
                                              "Failed to load private key file.");

            SingletonProvider <TestSetup> .Instance.PerformBasicSetup();
        }
Ejemplo n.º 3
0
        public void TestOnBackupFailedVBScript()
        {
            // First set up a script
            string script =
                @"Sub OnBackupFailed(reason)
                               EventLog.Write(""Failed: "" & reason)
                           End Sub";

            Scripting scripting = _settings.Scripting;
            string    file      = scripting.CurrentScriptFile;

            File.WriteAllText(file, script);
            scripting.Enabled = true;
            scripting.Reload();

            var back = new BackupRestore();

            back.InitializeBackupSettings();
            back.SetBackupDir(@"C:\some-non-existant-directory");
            Assert.IsFalse(back.Execute());

            CustomAsserts.AssertReportedError("BACKUP ERROR: The specified backup directory is not accessible:");
            string eventLogText = TestSetup.ReadExistingTextFile(LogHandler.GetEventLogFileName());

            Assert.IsTrue(eventLogText.Contains("The specified backup directory is not accessible"));
        }
Ejemplo n.º 4
0
        public void TestPortInUse()
        {
            Application application = SingletonProvider <TestSetup> .Instance.GetApp();

            application.Stop();

            var sock = new TcpConnection();

            using (var serverSocket = new TcpServer(1, 25, eConnectionSecurity.eCSNone))
            {
                serverSocket.StartListen();

                application.Start();

                // make sure it's possible to connect to the non blocked port.

                sock.IsPortOpen(110);
                sock.IsPortOpen(143);

                //let this our temp server die.
                sock.IsPortOpen(25);

                // make sure that hMailServer reported an error during start up because the ports were blocked.
                CustomAsserts.AssertReportedError("Failed to bind to local port.");
            }

            // restart hMailServer again. everything is now back to normal.
            application.Stop();

            application.Start();
            sock.IsPortOpen(25);
        }
Ejemplo n.º 5
0
        public void TestOnBackupFailedJScript()
        {
            Application application = SingletonProvider <TestSetup> .Instance.GetApp();

            Scripting scripting = _settings.Scripting;

            scripting.Language = "JScript";

            // First set up a script
            string script =
                @"function OnBackupFailed(reason)     
                           {
                               EventLog.Write('Failed: ' + reason)
                           }";


            string file = scripting.CurrentScriptFile;

            File.WriteAllText(file, script);
            scripting.Enabled = true;
            scripting.Reload();

            var back = new BackupRestore();

            back.InitializeBackupSettings();
            back.SetBackupDir(@"C:\some-non-existant-directory");
            Assert.IsFalse(back.Execute());

            CustomAsserts.AssertReportedError("BACKUP ERROR: The specified backup directory is not accessible:");
            string eventLogText = TestSetup.ReadExistingTextFile(LogHandler.GetEventLogFileName());

            Assert.IsTrue(eventLogText.Contains("The specified backup directory is not accessible"));
        }
Ejemplo n.º 6
0
        public void TestRetrievalOfMessageInDeletedFolderUsingIMAP()
        {
            Application application = SingletonProvider <TestSetup> .Instance.GetApp();

            string deletedMessageText = _settings.ServerMessages.get_ItemByName("MESSAGE_FILE_MISSING").Text;

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

            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody");

            IMAPFolder inbox = account.IMAPFolders.get_ItemByName("Inbox");


            CustomAsserts.AssertFolderMessageCount(inbox, 1);

            Message message = inbox.Messages[0];

            var           dir    = new DirectoryInfo(Path.GetFullPath(message.Filename));
            DirectoryInfo parent = dir.Parent.Parent.Parent;

            parent.Delete(true);

            var sim = new ImapClientSimulator();

            sim.ConnectAndLogon(account.Address, "test");
            sim.SelectFolder("INBOX");
            string result = sim.Fetch("1 BODY[1]");

            Assert.IsTrue(result.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename)));
            CustomAsserts.AssertReportedError("Message retrieval failed because message file");
        }
Ejemplo n.º 7
0
        public void TestRetrievalOfDeletedMessage()
        {
            Application application = SingletonProvider <TestSetup> .Instance.GetApp();

            string deletedMessageText = _settings.ServerMessages.get_ItemByName("MESSAGE_FILE_MISSING").Text;

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

            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody");

            IMAPFolder inbox = account.IMAPFolders.get_ItemByName("Inbox");


            CustomAsserts.AssertFolderMessageCount(inbox, 1);

            Message message = inbox.Messages[0];

            File.Delete(message.Filename);

            string text = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test");

            Assert.IsTrue(text.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename)));

            CustomAsserts.AssertReportedError("Message retrieval failed because message file");
        }
Ejemplo n.º 8
0
        public void TestSigningEnabledNoPrivateKey()
        {
            _domain.DKIMSignEnabled = true;
            _domain.Save();

            string result = SendMessage();

            Assert.IsFalse(result.ToLower().Contains("dkim-signature"), result);

            CustomAsserts.AssertReportedError("Either the selector or private key file was not specified.");
        }
Ejemplo n.º 9
0
        public void TestUnusedPort()
        {
            _antiVirus.ClamAVEnabled = true;
            _antiVirus.ClamAVPort    = 54391;

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

            SmtpClientSimulator.StaticSend(account1.Address, account1.Address, "Mail 1", "DummyBody");
            Pop3ClientSimulator.AssertMessageCount(account1.Address, "test", 1);
            CustomAsserts.AssertReportedError("Unable to connect to ClamAV server at localhost:54391.");
        }
Ejemplo n.º 10
0
        public void TestIncorrectPort()
        {
            _antiVirus.ClamAVEnabled = true;
            _antiVirus.ClamAVPort    = 110;

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

            SmtpClientSimulator.StaticSend(account1.Address, account1.Address, "Mail 1", "DummyBody");
            Pop3ClientSimulator.AssertMessageCount(account1.Address, "test", 1);
            CustomAsserts.AssertReportedError("Protocol error. Unexpected response: +OK");
        }
Ejemplo n.º 11
0
        public void TestSANotRunning()
        {
            StopSpamAssassin();

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

            smtpClientSimulator.Send(account.Address, account.Address, "SA test", "This is a test message.");
            string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test");

            Assert.IsFalse(sMessageContents.Contains("X-Spam-Status"));

            CustomAsserts.AssertReportedError("There was a communication error with SpamAssassin.",
                                              "The SpamAssassin tests did not complete. Please confirm that the configuration (host name and port) is valid and that SpamAssassin is running.");
        }
Ejemplo n.º 12
0
        public void TestIncorrectHost()
        {
            var smtpClientSimulator = new SmtpClientSimulator();

            _settings.AntiSpam.SpamAssassinEnabled = true;
            _settings.AntiSpam.SpamAssassinHost    = "localholst"; // <- mispelled
            smtpClientSimulator.Send(account.Address, account.Address, "SA test", "This is a test message.");
            string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test");

            if (sMessageContents.Contains("X-Spam-Status"))
            {
                _settings.AntiSpam.SpamAssassinEnabled = false;
                throw new Exception("Spam assassin not run");
            }

            CustomAsserts.AssertReportedError("The IP address for SpamAssassin could not be resolved.");
        }
Ejemplo n.º 13
0
        public void TestIncorrectPort()
        {
            var smtpClientSimulator = new SmtpClientSimulator();

            _settings.AntiSpam.SpamAssassinEnabled = true;
            _settings.AntiSpam.SpamAssassinHost    = "localhost"; // <- mispelled
            _settings.AntiSpam.SpamAssassinPort    = 12345;

            smtpClientSimulator.Send(account.Address, account.Address, "SA test", "This is a test message.");
            string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test");

            if (sMessageContents.Contains("X-Spam-Status"))
            {
                _settings.AntiSpam.SpamAssassinEnabled = false;
                throw new Exception("Spam assassin not run");
            }

            CustomAsserts.AssertReportedError("The SpamAssassin tests did not complete. Please confirm that the configuration (host name and port) is valid and that SpamAssassin is running.");
        }
Ejemplo n.º 14
0
        public void TestOnErrorJScript()
        {
            Application app = SingletonProvider <TestSetup> .Instance.GetApp();

            Scripting scripting = app.Settings.Scripting;

            scripting.Language = "JScript";
            string script = "function OnError(iSeverity, iError, sSource, sDescription) {" + Environment.NewLine +
                            " EventLog.Write('Severity: ' + iSeverity) " + Environment.NewLine +
                            " EventLog.Write('Error: ' + iError) " + Environment.NewLine +
                            " EventLog.Write('Source: ' + sSource) " + Environment.NewLine +
                            " EventLog.Write('Description: ' + sDescription) " + Environment.NewLine +
                            "}" + Environment.NewLine + Environment.NewLine;

            File.WriteAllText(scripting.CurrentScriptFile, script);

            scripting.Enabled = true;
            scripting.Reload();

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

            IMAPFolder inbox = account.IMAPFolders.get_ItemByName("Inbox");


            string deletedMessageText = app.Settings.ServerMessages.get_ItemByName("MESSAGE_FILE_MISSING").Text;

            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody");

            CustomAsserts.AssertFolderMessageCount(inbox, 1);
            hMailServer.Message message = inbox.Messages[0];
            File.Delete(message.Filename);
            string text = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test");

            Assert.IsTrue(text.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename)));
            CustomAsserts.AssertReportedError("Message retrieval failed because message file");

            string eventLogText = TestSetup.ReadExistingTextFile(app.Settings.Logging.CurrentEventLog);

            Assert.IsTrue(eventLogText.Contains("Description: Message retrieval failed"));
        }