Esempio n. 1
0
        public void TestConnections()
        {
            var oSocket = new TcpConnection();

             // Make sure an IP range exists.
             RemoveIPRanges();
             if (_ipRanges.Count == 0)
            AddIPRange();

             if (!oSocket.IsPortOpen(25))
            throw new Exception("ERROR: Cannot connect to port 25");
             if (!oSocket.IsPortOpen(110))
            throw new Exception("ERROR: Cannot connect to port 110");
             if (!oSocket.IsPortOpen(143))
            throw new Exception("ERROR: Cannot connect to port 143");

             RemoveIPRanges();

             // Now it shouldn't be possible to connect.

             if (oSocket.IsPortOpen(25))
            throw new Exception("ERROR: Cannot connect to port 25");
             if (oSocket.IsPortOpen(110))
            throw new Exception("ERROR: Cannot connect to port 110");
             if (oSocket.IsPortOpen(143))
            throw new Exception("ERROR: Cannot connect to port 143");

             AddIPRange();
             // Now it should be possible to connect again.
             if (!oSocket.IsPortOpen(25))
            throw new Exception("ERROR: Cannot connect to port 25");
             if (!oSocket.IsPortOpen(110))
            throw new Exception("ERROR: Cannot connect to port 110");
             if (!oSocket.IsPortOpen(143))
            throw new Exception("ERROR: Cannot connect to port 143");
        }
Esempio n. 2
0
        public void TestOnClientConnectVBScript()
        {
            Application app = SingletonProvider<TestSetup>.Instance.GetApp();
             Scripting scripting = app.Settings.Scripting;

             string script = "Sub OnClientConnect(oClient) " + Environment.NewLine +
                         " EventLog.Write(\"Port: \" & oClient.Port) " + Environment.NewLine +
                         " EventLog.Write(\"Address: \" & oClient.IPAddress) " + Environment.NewLine +
                         " EventLog.Write(\"Username: \" & oClient.Username) " + Environment.NewLine +
                         "End Sub" + Environment.NewLine + Environment.NewLine;

             File.WriteAllText(scripting.CurrentScriptFile, script);

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

             string eventLogFile = app.Settings.Logging.CurrentEventLog;
             if (File.Exists(eventLogFile))
            File.Delete(eventLogFile);

             var socket = new TcpConnection();
             Assert.IsTrue(socket.IsPortOpen(25));

             // Check that the message exists
             string message = TestSetup.ReadExistingTextFile(eventLogFile);

             Assert.IsNotEmpty(message);
             Assert.IsTrue(message.Contains("Port: 25"));
             Assert.IsTrue(message.Contains("Address: 127"));
             Assert.IsTrue(message.Contains("Username: \"")); // Should be empty, Username isn't available at this time.
        }
        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();
             }

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

             application.Start();
             sock.IsPortOpen(25);
        }