public void SetupSSLCertificateWithPassword() { string originalPath = Environment.CurrentDirectory; Environment.CurrentDirectory = Environment.CurrentDirectory + "\\..\\..\\..\\SSL examples\\WithPassword"; string sslPath = Environment.CurrentDirectory; Environment.CurrentDirectory = originalPath; 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(); TestSetup.AssertReportedError(); SingletonProvider <TestSetup> .Instance.DoBasicSetup(); }
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(); sim.Send(senderAccount.Address, recipientAccount.Address, "MySubject", "Test", out result); CustomAssert.IsTrue(result.StartsWith("4"), "Expected temporary error, but was: " + result); TestSetup.AssertReportedError("Failed to write to the file", "Rejected message because no mail data has been saved in file"); } finally { directories.DataDirectory = origDataDir; } }
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"); TestSetup.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]"); CustomAssert.IsTrue(result.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename))); TestSetup.AssertReportedError("Message retrieval failed because message file"); }
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. TestSetup.AssertReportedError("Failed to bind to local port."); } // restart hMailServer again. everything is now back to normal. application.Stop(); application.Start(); sock.IsPortOpen(25); }
public void TestOnBackupFailedVBScript() { Application application = SingletonProvider <TestSetup> .Instance.GetApp(); // First set up a script string script = @"Sub OnBackupFailed(reason) EventLog.Write(""Failed: "" & reason) End Sub"; Scripting scripting = _settings.Scripting; string file = scripting.CurrentScriptFile; TestSetup.WriteFile(file, script); scripting.Enabled = true; scripting.Reload(); var back = new BackupRestore(); back.InitializeBackupSettings(); back.SetBackupDir(@"C:\some-non-existant-directory"); CustomAssert.IsFalse(back.Execute()); TestSetup.AssertReportedError(); string eventLogText = TestSetup.ReadExistingTextFile(TestSetup.GetEventLogFileName()); CustomAssert.IsTrue(eventLogText.Contains("The specified backup directory is not accessible")); }
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"); TestSetup.AssertFolderMessageCount(inbox, 1); Message message = inbox.Messages[0]; File.Delete(message.Filename); string text = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); CustomAssert.IsTrue(text.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename))); TestSetup.AssertReportedError("Message retrieval failed because message file"); }
public void ThrowLogicErrorShouldResultInErrorDump() { SetCrashSimulationMode(2); TriggerCrashSimulationError(); TestSetup.AssertReportedError("Message: Crash simulation test"); AssertMinidumpCount(1); }
public void AccessViolationShouldResultInErrorDump() { SetCrashSimulationMode(3); TriggerCrashSimulationError(); TestSetup.AssertReportedError("An error has been detected. A mini dump has been written"); AssertMinidumpCount(1); }
public void TestSigningEnabledNoPrivateKey() { _domain.DKIMSignEnabled = true; _domain.Save(); string result = SendMessage(); CustomAssert.IsFalse(result.ToLower().Contains("dkim-signature"), result); TestSetup.AssertReportedError("Either the selector or private key file was not specified."); }
public void TestUnusedPort() { _antiVirus.ClamAVEnabled = true; _antiVirus.ClamAVPort = 54391; Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); CustomAssert.IsTrue(SMTPClientSimulator.StaticSend(account1.Address, account1.Address, "Mail 1", "DummyBody")); POP3ClientSimulator.AssertMessageCount(account1.Address, "test", 1); TestSetup.AssertReportedError("Unable to connect to ClamAV server at localhost:54391."); }
public void TestIncorrectPort() { _antiVirus.ClamAVEnabled = true; _antiVirus.ClamAVPort = 110; Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); CustomAssert.IsTrue(SMTPClientSimulator.StaticSend(account1.Address, account1.Address, "Mail 1", "DummyBody")); POP3ClientSimulator.AssertMessageCount(account1.Address, "test", 1); TestSetup.AssertReportedError("Protocol error. Unexpected response: +OK"); }
public void TestSigningEnabledNoPrivateKey() { _domain.DKIMSignEnabled = true; _domain.Save(); string result = SendMessage(); CustomAssert.IsFalse(result.ToLower().Contains("dkim-signature"), result); TestSetup.AssertReportedError(); }
public void ThrowIntShouldResultInErrorDump() { SetCrashSimulationMode(1); TriggerCrashSimulationError(); TestSetup.AssertReportedError("Description: An error occured while parsing data.", "An error occured while executing 'IOCPQueueWorkerTask'", "An error has been detected. A mini dump has been written"); AssertMinidumpCount(1); }
public void TestSANotRunning() { TestSetup.StopSpamAssassin(); // Send a messages to this account. var oSMTP = new SMTPClientSimulator(); CustomAssert.IsTrue(oSMTP.Send(account.Address, account.Address, "SA test", "This is a test message.")); string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); CustomAssert.IsFalse(sMessageContents.Contains("X-Spam-Status")); TestSetup.AssertReportedError(); }
public void TestSANotRunning() { TestSetup.StopSpamAssassin(); // Send a messages to this account. var oSMTP = new SMTPClientSimulator(); CustomAssert.IsTrue(oSMTP.Send(account.Address, account.Address, "SA test", "This is a test message.")); string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); CustomAssert.IsFalse(sMessageContents.Contains("X-Spam-Status")); TestSetup.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."); }
public void TestIncorrectHost() { var oSMTP = new SMTPClientSimulator(); _settings.AntiSpam.SpamAssassinEnabled = true; _settings.AntiSpam.SpamAssassinHost = "localholst"; // <- mispelled oSMTP.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"); } TestSetup.AssertReportedError("The IP address for SpamAssassin could not be resolved."); }
public void TestIncorrectPort() { var oSMTP = new SMTPClientSimulator(); _settings.AntiSpam.SpamAssassinEnabled = true; _settings.AntiSpam.SpamAssassinHost = "localhost"; // <- mispelled _settings.AntiSpam.SpamAssassinPort = 12345; oSMTP.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"); } TestSetup.AssertReportedError("The SpamAssassin tests did not complete. Please confirm that the configuration (host name and port) is valid and that SpamAssassin is running."); }
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"); TestSetup.AssertFolderMessageCount(inbox, 1); hMailServer.Message message = inbox.Messages[0]; File.Delete(message.Filename); string text = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); CustomAssert.IsTrue(text.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename))); TestSetup.AssertReportedError(); string eventLogText = TestSetup.ReadExistingTextFile(app.Settings.Logging.CurrentEventLog); CustomAssert.IsTrue(eventLogText.Contains("Description: Message retrieval failed")); }
public void TestFetchFromInvalidHostName() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); FetchAccount fa = account.FetchAccounts.Add(); fa.Enabled = true; fa.MinutesBetweenFetch = 10; fa.Name = "Test"; fa.Username = "******"; fa.Password = "******"; fa.UseSSL = false; fa.ServerAddress = "nonexistant.example.com"; fa.Port = 110; fa.ProcessMIMERecipients = false; fa.Save(); fa.DownloadNow(); TestSetup.AssertReportedError("The IP address for external account Test could not be resolved. Aborting fetch."); fa.Delete(); }