Exemplo n.º 1
0
        public bool DoLogin()
        {
            bool DoLoginResult = false;

            try
            {
                if (ExecutingThreadId == 0 || Thread.CurrentThread.ManagedThreadId == ExecutingThreadId)
                {
                    ExecutingThreadId = Thread.CurrentThread.ManagedThreadId;
                    Analysis.LogReplayer Replayer = new Analysis.LogReplayer(LoginAssociations);
                    LoginReplayAssociations = Replayer.Play();
                    this.Cookies            = LoginReplayAssociations.Cookies;
                    DoLoginResult           = IsLoggedIn();
                    GetCsrfToken();
                    ExecutingThreadId = 0;
                    ReleaseAllQueues(true);
                }
                else
                {
                    ManualResetEvent MSR = new ManualResetEvent(false);
                    lock (DoLoginQueue)
                    {
                        DoLoginQueue.Enqueue(MSR);
                    }
                    MSR.WaitOne();
                    if (!MostRecentIsLoggedInResult)
                    {
                        return(DoLogin());
                    }
                    return(DoLoginResult);
                }
            }
            catch (Exception Exp)
            {
                ReleaseAllQueues(true);
                throw Exp;
            }
            return(DoLoginResult);
        }
Exemplo n.º 2
0
        void FindLoggedInAndLoggedOutSampleResponses()
        {
            Analysis.LogAssociation LoginAsso = LoginAssociations.GetLastAssociationWithParameterValues(new List <string>()
            {
                Username, Password
            });
            if (LoginAsso == null)
            {
                throw new Exception("Unable to find login request in the login recording");
            }
            this.LoginRequestAsso = LoginAsso;

            Analysis.LogReplayer           ValidCredsReplayer     = new Analysis.LogReplayer(LoginAssociations);
            Analysis.LogReplayAssociations ValidCredsAssociations = ValidCredsReplayer.Play();

            Analysis.LogReplayer           InvalidCredsReplayer     = new Analysis.LogReplayer(LoginAssociations, UpdateLastLoginRequestWithInvalidCreds);
            Analysis.LogReplayAssociations InValidCredsAssociations = InvalidCredsReplayer.Play();

            //now compare ValidCredsAssociations and InvalidCredsAssociations and decide which one will be the LoginCheckRequest and also update the LoginCheckResponseWhenLoggedIn and LoginCheckResponseWhenLoggedOut values
            List <Analysis.LogAssociation> LoggedInCheckResponeCandidates  = new List <Analysis.LogAssociation>();
            List <Analysis.LogAssociation> LoggedOutCheckResponeCandidates = new List <Analysis.LogAssociation>();

            foreach (int i in ValidCredsAssociations.OriginalLogIds)// . FirstOriginalLogId; i <= ValidCredsAssociations.LastOriginalLogId; i++)
            {
                if (i <= LoginAsso.DestinationLog.LogId)
                {
                    continue;                                     //We don't want to include the
                }
                if (InValidCredsAssociations.HasOriginalLog(i))
                {
                    if (CanBeLoggedInLoggedOutResCandidate(ValidCredsAssociations.GetAssociationByOriginalId(i).ReplayAssociation, InValidCredsAssociations.GetAssociationByOriginalId(i).ReplayAssociation))
                    {
                        LoggedInCheckResponeCandidates.Add(ValidCredsAssociations.GetAssociationByOriginalId(i).ReplayAssociation);
                        LoggedOutCheckResponeCandidates.Add(InValidCredsAssociations.GetAssociationByOriginalId(i).ReplayAssociation);
                    }
                }
            }
            for (int i = 0; i < LoggedInCheckResponeCandidates.Count; i++)
            {
                Analysis.LogAssociation InResCand  = LoggedInCheckResponeCandidates[i];
                Analysis.LogAssociation OutResCand = LoggedOutCheckResponeCandidates[i];
                if (InResCand.DestinationLog.Request.Host.Equals(LoginAsso.DestinationLog.Request.Host))
                {
                    LoginCheckRequest = InResCand.DestinationLog.Request.GetClone();
                    LoginCheckResponseWhenLoggedIn  = InResCand.DestinationLog.Response.GetClone();
                    LoginCheckResponseWhenLoggedOut = OutResCand.DestinationLog.Response.GetClone();
                    break;
                }
                else if (!Tools.IsValidIpv4(InResCand.DestinationLog.Request.Host) && !Tools.IsValidIpv6(LoginAsso.DestinationLog.Request.Host))
                {
                    string[] InReqParts    = InResCand.DestinationLog.Request.Host.Split('.');
                    string[] LoginReqParts = LoginAsso.DestinationLog.Request.Host.Split('.');
                    if (InReqParts.Length > 1 && LoginReqParts.Length > 1)
                    {
                        if (LoginReqParts[LoginReqParts.Length - 1].Equals(InReqParts[InReqParts.Length - 1]) && LoginReqParts[LoginReqParts.Length - 2].Equals(InReqParts[InReqParts.Length - 2]))
                        {
                            LoginCheckRequest = InResCand.DestinationLog.Request.GetClone();
                            LoginCheckResponseWhenLoggedIn  = InResCand.DestinationLog.Response.GetClone();
                            LoginCheckResponseWhenLoggedOut = OutResCand.DestinationLog.Response.GetClone();
                            break;
                        }
                    }
                }
            }
            if (LoginCheckRequest == null || LoginCheckResponseWhenLoggedIn == null || LoginCheckResponseWhenLoggedOut == null)
            {
                if (LoggedInCheckResponeCandidates.Count > 0 && LoggedOutCheckResponeCandidates.Count > 0)
                {
                    LoginCheckRequest = LoggedInCheckResponeCandidates[LoggedInCheckResponeCandidates.Count - 1].DestinationLog.Request.GetClone();
                    LoginCheckResponseWhenLoggedIn  = LoggedInCheckResponeCandidates[LoggedInCheckResponeCandidates.Count - 1].DestinationLog.Response.GetClone();
                    LoginCheckResponseWhenLoggedOut = LoggedOutCheckResponeCandidates[LoggedOutCheckResponeCandidates.Count - 1].DestinationLog.Response.GetClone();
                }
            }
            if (LoginCheckRequest == null || LoginCheckResponseWhenLoggedIn == null || LoginCheckResponseWhenLoggedOut == null)
            {
                Request TestLoginCheckReq = LoginAsso.DestinationLog.Request.GetClone();
                TestLoginCheckReq.BodyString   = "";
                TestLoginCheckReq.Method       = "GET";
                TestLoginCheckReq.CookieString = "";
                if (TestLoginCheckReq.Url.Contains(Tools.UrlEncode(Username)) && TestLoginCheckReq.Url.Contains(Tools.UrlEncode(Password)))
                {
                    TestLoginCheckReq.Query.RemoveAll();
                }
                List <Response> LoggedInReses = new List <Response>();
                TestLoginCheckReq.SetSource("LoginCheck");
                TestLoginCheckReq.SetCookie(ValidCredsAssociations.Cookies);
                Response LoggedInResCandidate = TestLoginCheckReq.Send();

                TestLoginCheckReq.CookieString = "";
                TestLoginCheckReq.SetCookie(InValidCredsAssociations.Cookies);
                Response LoggedOutResCandidate = TestLoginCheckReq.Send();

                if (CanBeLoggedInLoggedOutResCandidate(LoggedInResCandidate, LoggedOutResCandidate))
                {
                    LoginCheckRequest = TestLoginCheckReq.GetClone();
                    LoginCheckResponseWhenLoggedIn  = LoggedInResCandidate.GetClone();
                    LoginCheckResponseWhenLoggedOut = LoggedOutResCandidate.GetClone();
                }
            }
            if (LoginCheckRequest == null || LoginCheckResponseWhenLoggedIn == null || LoginCheckResponseWhenLoggedOut == null)
            {
                throw new Exception("Unable to find a suitable logged in status check response");
            }
        }