Ejemplo n.º 1
0
        public void TestPortInUse()
        {
            hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp();

            application.Stop();

            var serverSocket = new ServerSocket(1, 25);

            serverSocket.StartListen();

            application.Start();
            TCPSocket sock = new TCPSocket();

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

            sock.CanConnect(110);
            sock.CanConnect(143);

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

            // make sure that hMailServer reported an error during start up because the ports were blocked.
            Utilities.AssertReportedError();

            // restart hMailServer again. everything is now back to normal.
            application.Stop();
            application.Start();
            sock.CanConnect(25);
        }
Ejemplo n.º 2
0
        public void TestConnections()
        {
            TCPSocket oSocket = new TCPSocket();

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

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

            RemoveIPRanges();

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

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

            AddIPRange();
            // Now it should be possible to connect again.
            if (!oSocket.CanConnect(25))
            {
                throw new Exception("ERROR: Cannot connect to port 25");
            }
            if (!oSocket.CanConnect(110))
            {
                throw new Exception("ERROR: Cannot connect to port 110");
            }
            if (!oSocket.CanConnect(143))
            {
                throw new Exception("ERROR: Cannot connect to port 143");
            }
        }
Ejemplo n.º 3
0
        public void TestConnection()
        {
            for (int i = 0; i < 2500; i++)
            {
                TCPSocket socket = new TCPSocket();

                Assert.IsTrue(socket.CanConnect(25));
            }
        }
Ejemplo n.º 4
0
        public void TestConnections()
        {
            TCPSocket oSocket = new TCPSocket();

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

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

             RemoveIPRanges();

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

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

             AddIPRange();
             // Now it should be possible to connect again.
             if (!oSocket.CanConnect(25))
            throw new Exception("ERROR: Cannot connect to port 25");
             if (!oSocket.CanConnect(110))
            throw new Exception("ERROR: Cannot connect to port 110");
             if (!oSocket.CanConnect(143))
            throw new Exception("ERROR: Cannot connect to port 143");
        }
Ejemplo n.º 5
0
        public void TestOnClientConnectJScript()
        {
            hMailServer.Application app = SingletonProvider <Utilities> .Instance.GetApp();

            hMailServer.Scripting scripting = app.Settings.Scripting;

            scripting.Language = "JScript";

            string script = "function OnClientConnect(oClient) " + Environment.NewLine +
                            "{" + Environment.NewLine +
                            " EventLog.Write('Port: ' + oClient.Port); " + Environment.NewLine +
                            " EventLog.Write('Address: ' + oClient.IPAddress); " + Environment.NewLine +
                            " EventLog.Write('Username: '******'t available at this time.
        }
Ejemplo n.º 6
0
        public void TestOnClientConnectVBScript()
        {
            hMailServer.Application app = SingletonProvider<Utilities>.Instance.GetApp();
             hMailServer.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);

             TCPSocket socket = new TCPSocket();
             Assert.IsTrue(socket.CanConnect(25));

             // Check that the message exists
             string message = Utilities.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.
        }
Ejemplo n.º 7
0
        public void TestPortInUse()
        {
            hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp();
              application.Stop();

              var serverSocket = new ServerSocket(1, 25);
              serverSocket.StartListen();

              application.Start();
              TCPSocket sock = new TCPSocket();
              // make sure it's possible to connect to the non blocked port.

              sock.CanConnect(110);
              sock.CanConnect(143);

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

              // make sure that hMailServer reported an error during start up because the ports were blocked.
              Utilities.AssertReportedError();

              // restart hMailServer again. everything is now back to normal.
              application.Stop();
              application.Start();
              sock.CanConnect(25);
        }