예제 #1
0
        public void TestConnection()
        {
            for (int i = 0; i < 2500; i++)
            {
                TcpSocket socket = new TcpSocket();

                Assert.IsTrue(socket.CanConnect(25), i.ToString());
            }
        }
예제 #2
0
        public void TestConnections()
        {
            var 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");
        }
예제 #3
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 TcpSocket();
             Assert.IsTrue(socket.CanConnect(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.
        }
예제 #4
0
        public void TestPortInUse()
        {
            Application application = SingletonProvider<TestSetup>.Instance.GetApp();
             application.Stop();

             var sock = new TcpSocket();
             using (var serverSocket = new TcpServer(1, 25))
             {
            serverSocket.StartListen();

            application.Start();

            // 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.
            TestSetup.AssertReportedError();
             }

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

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