Example #1
0
        public void Login_SocketKeepAliveFail_ReturnsFalse()
        {
            var socketMock = Substitute.For <ISymSocket>();

            socketMock.Connected.Returns(true);
            socketMock.When(x => x.WaitFor("Password:"******"[c")).Do(x => { throw new InvalidOperationException(); });

            var session = new SymSession(socketMock, 10);

            session.Login("bob", "dole", "bobdole").Should().BeFalse();
        }
Example #2
0
        public void Login_InvalidAixLoginUsername_ReturnsFalse()
        {
            var socketMock = Substitute.For <ISymSocket>();

            socketMock.Connected.Returns(true);
            socketMock.WaitFor("Password:"******"[c");
            socketMock.Read().Returns("invalid login");

            var session = new SymSession(socketMock, 10);

            session.Login("bob", "dole", "bobdole").Should().BeFalse();
        }
Example #3
0
        public void Login_SocketWriteFail_ReturnsFalse()
        {
            var socketMock = Substitute.For <ISymSocket>();

            socketMock.Connected.Returns(true);
            socketMock.WhenForAnyArgs(x => x.Write(new byte[] { }))
            .Do(x => { throw new NetworkInformationException(); });

            var session = new SymSession(socketMock, 10);

            session.Login("bob", "dole", "bobdole").Should().BeFalse();
        }
Example #4
0
        public void Login_SocketWriteFail_HasError()
        {
            var socketMock = Substitute.For <ISymSocket>();

            socketMock.Connected.Returns(true);
            socketMock.WhenForAnyArgs(x => x.Write(new byte[] { }))
            .Do(x => { throw new NetworkInformationException(); });

            var session = new SymSession(socketMock, 10);

            session.Login("bob", "dole", "bobdole");
            session.Error.Should().Contain("Telnet communication failed");
        }
Example #5
0
        public void Login_InvalidSymLogin_ReturnsFalse()
        {
            var socketMock = Substitute.For <ISymSocket>();

            socketMock.Connected.Returns(true);
            socketMock.WaitFor("Password:"******"[c").Returns(0);
            socketMock.WaitFor(":").Returns(0);
            socketMock.Read().Returns("Password:"******":");
            socketMock.ReadCommand().Returns(new SymCommand("SymLogonInvalidUser"));

            var session = new SymSession(socketMock, 10);

            session.Login("bob", "dole", "bobdole").Should().BeFalse();
        }
Example #6
0
        public void Login_InvalidAixLoginPassword_HasErrorMessage()
        {
            var socketMock = Substitute.For <ISymSocket>();

            socketMock.Connected.Returns(true);
            socketMock.WaitFor("Password:"******"[c").Returns(0);
            socketMock.WaitFor(":").Returns(0);
            socketMock.Read().Returns("Password:"******"invalid login");

            var session = new SymSession(socketMock, 10);

            session.Login("bob", "dole", "bobdole");
            session.Error.Should().Contain("Invalid AIX Login");
        }
Example #7
0
        private void Login()
        {
            while (!_session.LoggedIn)
            {
                _session.Disconnect();
                _session.Connect("symitar", 23);
                _session.Login("jdeering", "h3dd0#mon", "083ch#ckb00k");

                if (_session.LoggedIn)
                {
                    responseBox.Text += @"Logged in";
                    responseBox.Text += "\n\n";
                }
            }
        }
Example #8
0
        public void Login_CommandPromptNoWait_ReturnsTrue()
        {
            var socketMock = Substitute.For <ISymSocket>();

            socketMock.Connected.Returns(true);
            socketMock.WaitFor("Password:"******"[c").Returns(0);
            socketMock.WaitFor(":").Returns(0);
            socketMock.Read().Returns("Password:"******"[c");
            socketMock.ReadCommand().Returns(new SymCommand("Input", new Dictionary <string, string> {
                { "HelpCode", "10025" }
            }));

            var session = new SymSession(socketMock, 10);

            session.Login("bob", "dole", "bobdole").Should().BeTrue();
        }
Example #9
0
        public void Login_SocketKeepAliveException_ReturnsFalse()
        {
            var socketMock = Substitute.For <ISymSocket>();

            socketMock.Connected.Returns(true);
            socketMock.WaitFor("Password:"******"[c").Returns(0);
            socketMock.WaitFor(":").Returns(0);
            socketMock.Read().Returns("Password:"******":");
            socketMock.ReadCommand().Returns(new SymCommand("Input", new Dictionary <string, string> {
                { "HelpCode", "10025" }
            }));
            socketMock.When(x => x.KeepAliveStart()).Do(x => { throw new Exception(); });

            var session = new SymSession(socketMock, 10);

            session.Login("bob", "dole", "bobdole").Should().BeFalse();
        }
Example #10
0
        public void Login_Successful_StartsKeepAliveOnSocket()
        {
            var socketMock = Substitute.For <ISymSocket>();

            socketMock.Connected.Returns(true);
            socketMock.WaitFor("Password:"******"[c").Returns(0);
            socketMock.WaitFor(":").Returns(0);
            socketMock.Read().Returns("Password:"******":");
            socketMock.ReadCommand().Returns(new SymCommand("Input", new Dictionary <string, string> {
                { "HelpCode", "10025" }
            }));

            var session = new SymSession(socketMock, 10);

            session.Login("bob", "dole", "bobdole");
            socketMock.Received().KeepAliveStart();
        }
Example #11
0
        public void Login_LocksDuringLogin_ReturnsFalse()
        {
            var socketMock = Substitute.For <ISymSocket>();

            socketMock.Connected.Returns(true);
            socketMock.WaitFor("Password:"******"[c").Returns(0);
            socketMock.WaitFor(":").Returns(0);
            socketMock.Read().Returns("Password:"******":");
            socketMock.ReadCommand()
            .Returns(new SymCommand("SymLogonError",
                                    new Dictionary <string, string>
            {
                { "Text", "Too Many Invalid Password Attempts" }
            }));

            var session = new SymSession(socketMock, 10);

            session.Login("bob", "dole", "bobdole").Should().BeFalse();
        }
Example #12
0
        public void Login_InputHasHelpCode_CallsHostSyncWrite()
        {
            var socketMock = Substitute.For <ISymSocket>();

            socketMock.Connected.Returns(true);
            socketMock.WaitFor("Password:"******"[c").Returns(0);
            socketMock.WaitFor(":").Returns(0);
            socketMock.Read().Returns("Password:"******":");
            socketMock.ReadCommand()
            .Returns(
                new SymCommand("Request"),
                new SymCommand("Input", new Dictionary <string, string> {
                { "HelpCode", "10025" }
            })
                );

            var session = new SymSession(socketMock, 10);

            session.Login("bob", "dole", "bobdole");
            socketMock.Received().Write("$WinHostSync$\r");
        }
Example #13
0
        //========================================================================
        public bool Connect()
        {
            if (Connection != null)
            {
                if (Connection.isLoggedIn)
                {
                    return(true);
                }
            }

            Connection = new SymSession();
            if (!Connection.Connect(Parent.IP, Parent.Port))
            {
                return(false);
            }
            if (Connection.Login(Parent.AixUsr, Parent.AixPwd, SymDir, SymId) == false)
            {
                Connection.Disconnect();
                Connection = null;
                return(false);
            }
            return(true);
        }
Example #14
0
        //========================================================================
        //  sym Connections
        //========================================================================
        public static SymSession TrySymNewConnect(SymInst inst)
        {
            SymSession session = new SymSession();

            bool   prompt = false;
            string user   = inst.Parent.AixUsr;
            string pass   = inst.Parent.AixPwd;
            string id     = inst.SymId;

            if (user == "")
            {
                prompt = true;
            }
            if (pass == "")
            {
                prompt = true;
            }
            if (id == "")
            {
                prompt = true;
            }
            bool success = false;

            if (!prompt)
            {
                success = session.Connect(inst.Parent.IP, inst.Parent.Port);
                if (success)
                {
                    success = session.Login(user, pass, inst.SymDir, id);
                }
                while (!success)
                {
                    if (MessageBox.Show("Error Connecting to Sym\nRetry?", "PwrIDE", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.No)
                    {
                        break;
                    }
                    success = session.Connect(inst.Parent.IP, inst.Parent.Port);
                    if (success)
                    {
                        success = session.Login(user, pass, inst.SymDir, id);
                    }
                }
                if (!success)
                {
                    return(null);
                }
                return(session);
            }

            while (!success)
            {
                frmLogin login = new frmLogin(inst.Parent.IP, inst.SymDir, user, pass, id);
                if (login.ShowDialog(MainForm) == DialogResult.Cancel)
                {
                    break;
                }
                inst.Parent.AixUsr = user = login.User;
                inst.Parent.AixPwd = pass = login.Pass;
                inst.SymId         = id = login.ID;
                login.Dispose();
                success = inst.Connect();
                if (success)
                {
                    success = session.Login(user, pass, inst.SymDir, id);
                }
                if (!success)
                {
                    if (MessageBox.Show("Error Connecting to Sym\nRetry?", "PwrIDE", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.No)
                    {
                        break;
                    }
                }
            }
            if (!success)
            {
                return(null);
            }
            return(session);
        }
Example #15
0
        public void Login_CommandPromptNoWait_ReturnsTrue()
        {
            var socketMock = Substitute.For<ISymSocket>();
            socketMock.Connected.Returns(true);
            socketMock.WaitFor("Password:"******"[c").Returns(0);
            socketMock.WaitFor(":").Returns(0);
            socketMock.Read().Returns("Password:"******"[c");
            socketMock.ReadCommand().Returns(new SymCommand("Input", new Dictionary<string, string> { { "HelpCode", "10025" } }));

            var session = new SymSession(socketMock, 10);
            session.Login("bob", "dole", "bobdole").Should().BeTrue();
        }
Example #16
0
        public void Login_InputHasHelpCode_CallsHostSyncWrite()
        {
            var socketMock = Substitute.For<ISymSocket>();
            socketMock.Connected.Returns(true);
            socketMock.WaitFor("Password:"******"[c").Returns(0);
            socketMock.WaitFor(":").Returns(0);
            socketMock.Read().Returns("Password:"******":");
            socketMock.ReadCommand()
                .Returns(
                    new SymCommand("Request"),
                    new SymCommand("Input", new Dictionary<string, string> {{"HelpCode", "10025"}})
                );

            var session = new SymSession(socketMock, 10);
            session.Login("bob", "dole", "bobdole");
            socketMock.Received().Write("$WinHostSync$\r");
        }
Example #17
0
        public void Login_InvalidAixLoginPassword_HasErrorMessage()
        {
            var socketMock = Substitute.For<ISymSocket>();
            socketMock.Connected.Returns(true);
            socketMock.WaitFor("Password:"******"[c").Returns(0);
            socketMock.WaitFor(":").Returns(0);
            socketMock.Read().Returns("Password:"******"invalid login");

            var session = new SymSession(socketMock, 10);
            session.Login("bob", "dole", "bobdole");
            session.Error.Should().Contain("Invalid AIX Login");
        }
Example #18
0
        public void Login_SocketKeepAliveException_ReturnsFalse()
        {
            var socketMock = Substitute.For<ISymSocket>();
            socketMock.Connected.Returns(true);
            socketMock.WaitFor("Password:"******"[c").Returns(0);
            socketMock.WaitFor(":").Returns(0);
            socketMock.Read().Returns("Password:"******":");
            socketMock.ReadCommand().Returns(new SymCommand("Input", new Dictionary<string, string> { { "HelpCode", "10025" } }));
            socketMock.When(x => x.KeepAliveStart()).Do(x => { throw new Exception(); });

            var session = new SymSession(socketMock, 10);
            session.Login("bob", "dole", "bobdole").Should().BeFalse();
        }
Example #19
0
        public void Login_InvalidSymLogin_ReturnsFalse()
        {
            var socketMock = Substitute.For<ISymSocket>();
            socketMock.Connected.Returns(true);
            socketMock.WaitFor("Password:"******"[c").Returns(0);
            socketMock.WaitFor(":").Returns(0);
            socketMock.Read().Returns("Password:"******":");
            socketMock.ReadCommand().Returns(new SymCommand("SymLogonInvalidUser"));

            var session = new SymSession(socketMock, 10);
            session.Login("bob", "dole", "bobdole").Should().BeFalse();
        }
Example #20
0
 public void Login_1000SymDir_ThrowsArgumentOutOfRangeException()
 {
     AfterConnect();
     Assert.Throws <ArgumentOutOfRangeException>(
         () => _session.Login("bob", "dole", 1000, "bobdole"));
 }
Example #21
0
        public void Login_Successful_StartsKeepAliveOnSocket()
        {
            var socketMock = Substitute.For<ISymSocket>();
            socketMock.Connected.Returns(true);
            socketMock.WaitFor("Password:"******"[c").Returns(0);
            socketMock.WaitFor(":").Returns(0);
            socketMock.Read().Returns("Password:"******":");
            socketMock.ReadCommand().Returns(new SymCommand("Input", new Dictionary<string, string> {{"HelpCode", "10025"}}));

            var session = new SymSession(socketMock, 10);
            session.Login("bob", "dole", "bobdole");
            socketMock.Received().KeepAliveStart();
        }
Example #22
0
        //------------------------------------------------------------------------
        private void btnTest_Click(object sender, EventArgs e)
        {
            SymSession test = new SymSession();

            try
            {
                if (!test.Connect(Server.IP, Server.Port))
                {
                    MessageBox.Show(test.error, "PwrIDE", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                string aixPwd = Server.AixPwd;
                if (aixPwd.Trim().Length == 0)
                {
                    InputBox inp = new InputBox("Test Sym Connection", "Please Enter AIX Password for Server \"" + Server.Alias + "\".", "", true);
                    if (inp.ShowDialog(this) == DialogResult.Cancel)
                    {
                        return;
                    }
                    aixPwd = inp.Input;
                    inp.Dispose();
                }

                bool retry  = true;
                bool result = test.Login(Server.AixUsr, aixPwd, txtSym.Text, txtID.Text);
                while (retry && (!result))
                {
                    retry = false;
                    if (result == false)
                    {
                        if (test.error == "Invalid AIX Login")
                        {
                            InputBox inp = new InputBox("Test Sym Connection", "Invalid AIX Login.\nPlease Re-Enter or Cancel (ESC).", "", true);
                            if (inp.ShowDialog(this) == DialogResult.Cancel)
                            {
                                return;
                            }
                            aixPwd = inp.Input;
                            inp.Dispose();
                            result = test.Login(Server.AixUsr, aixPwd, txtSym.Text, txtID.Text, 1);
                            retry  = true;
                        }
                        else if (test.error == "Invalid Sym User")
                        {
                            InputBox inp = new InputBox("Test Sym Connection", "Invalid Sym User ID.\nPlease Re-Enter or Cancel (ESC).", "", true);
                            if (inp.ShowDialog(this) == DialogResult.Cancel)
                            {
                                return;
                            }
                            txtID.Text = inp.Input;
                            inp.Dispose();
                            result = test.Login(Server.AixUsr, aixPwd, txtSym.Text, txtID.Text, 2);
                            retry  = true;
                        }
                        else
                        {
                            retry = (MessageBox.Show("Error Connecting to Sym\nError: " + test.error + "\n\nRetry?", "Sym Connection Test", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes);
                        }
                        if ((!retry) && (!result))
                        {
                            test.Disconnect();
                            return;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error During Login Test\n" + ex.Message, "PwrIDE", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            test.Disconnect();
            MessageBox.Show("Sym Connected Okay!", "PwrIDE", MessageBoxButtons.OK, MessageBoxIcon.None);
        }
Example #23
0
        public void Login_SocketWriteFail_HasError()
        {
            var socketMock = Substitute.For<ISymSocket>();
            socketMock.Connected.Returns(true);
            socketMock.WhenForAnyArgs(x => x.Write(new byte[] { }))
                .Do(x => { throw new NetworkInformationException(); });

            var session = new SymSession(socketMock, 10);
            session.Login("bob", "dole", "bobdole");
            session.Error.Should().Contain("Telnet communication failed");
        }
Example #24
0
        public void Login_SocketKeepAliveFail_ReturnsFalse()
        {
            var socketMock = Substitute.For<ISymSocket>();
            socketMock.Connected.Returns(true);
            socketMock.When(x => x.WaitFor("Password:"******"[c")).Do(x => { throw new InvalidOperationException(); });

            var session = new SymSession(socketMock, 10);
            session.Login("bob", "dole", "bobdole").Should().BeFalse();
        }
Example #25
0
        public void Login_InvalidAixLoginUsername_ReturnsFalse()
        {
            var socketMock = Substitute.For<ISymSocket>();
            socketMock.Connected.Returns(true);
            socketMock.WaitFor("Password:"******"[c");
            socketMock.Read().Returns("invalid login");

            var session = new SymSession(socketMock, 10);
            session.Login("bob", "dole", "bobdole").Should().BeFalse();
        }
Example #26
0
        public void Login_SocketWriteFail_ReturnsFalse()
        {
            var socketMock = Substitute.For<ISymSocket>();
            socketMock.Connected.Returns(true);
            socketMock.WhenForAnyArgs(x => x.Write(new byte[] { }))
                .Do(x => { throw new NetworkInformationException(); });

            var session = new SymSession(socketMock, 10);
            session.Login("bob", "dole", "bobdole").Should().BeFalse();
        }
Example #27
0
        public void Login_LocksDuringLogin_ReturnsFalse()
        {
            var socketMock = Substitute.For<ISymSocket>();
            socketMock.Connected.Returns(true);
            socketMock.WaitFor("Password:"******"[c").Returns(0);
            socketMock.WaitFor(":").Returns(0);
            socketMock.Read().Returns("Password:"******":");
            socketMock.ReadCommand()
                      .Returns(new SymCommand("SymLogonError",
                                             new Dictionary<string, string>
                                                 {
                                                     {"Text", "Too Many Invalid Password Attempts"}
                                                 }));

            var session = new SymSession(socketMock, 10);
            session.Login("bob", "dole", "bobdole").Should().BeFalse();
        }