Beispiel #1
0
        private static ILoginResult TryLogin(SeededPrimitiveConnection seedConn, IAuthPromptResponse authPrompt)
        {
            var(seed, conn) = seedConn;

            var username        = authPrompt.Username;
            var password        = authPrompt.Password;
            var securedPassword = Md5Sum(string.Concat(seed, Md5Sum(password)));

            var loginCmd     = new SystemCommand(SystemOp.Login);
            var loginMessage = new MessageBuilder(loginCmd).Add(username).Add(securedPassword);

            loginMessage.Send(conn);

            var(matched, authResult, description) = conn.ReceiveSystemStringCommand(SystemOp.LoginResult);
            if (!matched)
            {
                return(new InvalidProtocolLoginResult("login result listen"));
            }

            var authenticated = CommandUnpacking.Value(authResult) == 0;

            if (!authenticated)
            {
                return(new UserLoginException(description ?? "(no description)"));
            }
            return(new SuccessLoginResult());
        }
Beispiel #2
0
        public void Attempt(SeededPrimitiveConnection?conn, IAuthPromptResponse response)
        {
            try
            {
                if (conn is null)
                {
                    throw new ArgumentNullException(nameof(conn));
                }
                if (response is null)
                {
                    throw new ArgumentNullException(nameof(response));
                }

                Result = TryLogin(conn, response);
                if (!Result.IsSuccess)
                {
                    return;
                }

                Connection = MakeMessageConnection(conn.Connection);
                // Stop the connection from being disposed by the 'finally' block if we successfully authenticated.
                conn = null;
            }
            finally
            {
                conn?.Dispose();
            }
        }
 public bool IsDifferentServer(IAuthPromptResponse other)
 {
     return(other.HasCredentials);
 }
 /// <summary>
 ///     Constructs a dummy login prompter with a particular stock
 ///     response.
 /// </summary>
 /// <param name="response">The response to give when asked.</param>
 public DummyAuthPrompter(IAuthPromptResponse response)
 {
     Response = response;
 }
        private ClientSideLoginPerformer <string, string> MakeLoginPerformer(string connection, IAuthPromptResponse response, ILoginResult result)
        {
            _authPrompterMock.SetupGet(t => t.Response).Returns(response);
            _authPerformerMock.SetupGet(t => t.Connection).Returns(connection);
            _authPerformerMock.SetupGet(t => t.Result).Returns(result);
            _loginErrorHandlerMock.Setup(t => t.Handle(It.IsAny <ILoginResult>())).Callback(new InvocationAction(RegisterLoginErrorHandlerCall));

            return(new ClientSideLoginPerformer <string, string>(_handshakePerformerMock.Object, _authPrompterMock.Object, _loginErrorHandlerMock.Object, _authPerformerMock.Object));
        }