Exemple #1
0
		/// <summary>
		/// Exports data from the specified source to the specifies strems
		/// </summary>
		/// <param name="source"></param>
		/// <param name="stream"></param>
		/// <param name="overwriteScheme">Wether to overrite existing http scheme</param>
		/// <param name="isSSL">Wether the request is secure or not. This will overrite the http scheme of the request if applicable</param>
		/// <param name="newHost">New host for the request</param>
		/// <param name="newPort">New port for the request</param>
		protected virtual void Export(ITrafficDataAccessor source, Stream stream, bool overwriteScheme, bool isSSL, string newHost, int newPort)
		{
			TVRequestInfo info;
			int i = -1;

			string overridenScheme = isSSL ? "https" : "http";
			//using an xml writer for memory concerns
			XmlWriter writer = new XmlTextWriter(stream, Encoding.UTF8);
			writer.WriteStartDocument();
			writer.WriteComment(String.Format("Automatically created by Traffic Viewer SDK at {0}", DateTime.Now));
			writer.WriteComment(String.Format("Number of requests in file {0}", source.RequestCount));
			writer.WriteStartElement("requests");

			while ((info = source.GetNext(ref i)) != null)
			{
				string scheme = info.IsHttps ? "https" : "http";
				scheme = overwriteScheme ? overridenScheme : scheme;

				//get the request information
				byte[] data = source.LoadRequestData(info.Id);
                if (data != null)
                {
					HttpRequestInfo reqInfo = new HttpRequestInfo(data);
					reqInfo.IsSecure = scheme == "https";
                    WriteRequest(writer, newHost, newPort, scheme, reqInfo);
                }
			}

			writer.WriteEndElement();
			writer.WriteEndDocument();
			writer.Flush();
		}
        /// <summary>
        /// Searches the entire data accessor for the specified criteria
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="criteriaSet"></param>
        /// <param name="result"></param>
        private void FullSearch(ITrafficDataAccessor dataSource, SearchCriteriaSet criteriaSet, ISearchResult result)
        {
            TVRequestInfo header;
            int           currReqId = -1;

            while ((header = dataSource.GetNext(ref currReqId)) != null && !_stopSearch)
            {
                RequestMatches(dataSource, header, criteriaSet, result);
            }
        }
        /// <summary>
        /// Sends all the requests in the attached file
        /// </summary>
        /// <param name="source"></param>
        public void Send(ITrafficDataAccessor source)
        {
            int           id   = -1;
            TVRequestInfo info = null;

            PatternTracker.Instance.PatternsToTrack = source.Profile.GetTrackingPatterns();

            while ((info = source.GetNext(ref id)) != null)
            {
                SendRequest(source, info);
            }
        }
        private void NextClick(object sender, EventArgs e)
        {
            TVRequestInfo header1 = _source.GetNext(ref _currFirstIndex);
            TVRequestInfo header2 = _source.GetNext(ref _currSecondIndex);

            _currFirstDiffIndex  = -1;
            _currSecondDiffIndex = -1;

            if (header1 != null && header2 != null)
            {
                if (!_buttonPrev.Enabled)
                {
                    _buttonPrev.Enabled = true;
                }

                DoDiff(_currFirstIndex, _currSecondIndex);
            }
            else
            {
                _buttonNext.Enabled = false;
            }
        }
Exemple #5
0
        /// <summary>
        /// Gets the next unsent request
        /// </summary>
        /// <returns>Http Request Info</returns>
        private HttpRequestInfo GetNextRequest()
        {
            TVRequestInfo   tvReqInfo   = null;
            HttpRequestInfo httpReqInfo = null;
            ICacheable      cacheEntry  = null;

            //get the next unvisited request
            bool isCached = true;
            int  hash     = 0;

            do
            {
                tvReqInfo = Source.GetNext(ref _currId);
                if (tvReqInfo != null)
                {
                    isCached = true;
                    //skip js files and images
                    if (!Utils.IsMatch(tvReqInfo.RequestLine, KNOWN_RESOURCE_EXTENSIONS))
                    {
                        byte[] requestBytes = Source.LoadRequestData(tvReqInfo.Id);
                        httpReqInfo = new HttpRequestInfo(requestBytes);
                        //skip invalid requests
                        if (httpReqInfo.Path.Contains("/"))
                        {
                            hash = httpReqInfo.GetHashCode();

                            //check the cache for the request to see if it was already visited
                            //allow the same request to be sent more than once
                            if (hash != _lastRequestHash)
                            {
                                cacheEntry = TrafficServerCache.Instance.GetEntry(hash);
                                isCached   = cacheEntry != null;
                            }
                        }
                    }
                }
                //keep doing this until the end of requests or until we found a request that is not cached
            }while (tvReqInfo != null && isCached);

            if (hash != _lastRequestHash)
            {
                _lastRequestHash = hash;
                //clear the cache so we don't skip any repeats of the previous request
                TrafficServerCache.Instance.Clear();
            }
            return(httpReqInfo);
        }
        void ValidateTrafficSourcesRequestsAreSame(ITrafficDataAccessor src1, ITrafficDataAccessor src2, bool includeResponses = true)
        {
            Assert.AreEqual(src1.RequestCount, src2.RequestCount);

            int i = -1, j = -1;


            while (true)
            {
                TVRequestInfo first  = src1.GetNext(ref i);
                TVRequestInfo second = src2.GetNext(ref j);

                if (first == null && second == null)
                {
                    break;
                }

                Assert.AreEqual(first.RequestLine, second.RequestLine);


                //proceed to compare http requests

                byte[] firstRequest  = src1.LoadRequestData(first.Id);
                byte[] secondRequest = src2.LoadRequestData(second.Id);

                HttpRequestInfo firstRequestInfo = new HttpRequestInfo(firstRequest);
                HttpRequestInfo seconRequestInfo = new HttpRequestInfo(secondRequest);

                Assert.AreEqual(firstRequestInfo.ToString(), seconRequestInfo.ToString());


                if (includeResponses)
                {
                    //proceed to compare responses
                    Assert.AreEqual(first.ResponseStatus, second.ResponseStatus);

                    byte[] firstResponse  = src1.LoadResponseData(first.Id);
                    byte[] secondResponse = src2.LoadResponseData(second.Id);

                    HttpResponseInfo firstResponseInfo  = new HttpResponseInfo(firstResponse);
                    HttpResponseInfo secondResponseInfo = new HttpResponseInfo(secondResponse);

                    Assert.AreEqual(firstResponseInfo.ToString(), secondResponseInfo.ToString());
                }
            }
        }
        /// <summary>
        /// Add the hosts in the traffic log to the host file
        /// </summary>
        private void AddHosts()
        {
            HttpServerConsole.Instance.WriteLine(LogMessageType.Warning,
                                                 "Using the host of the first request");
            int           i         = -1;
            TVRequestInfo tvReqInfo = _sourceStore.GetNext(ref i);

            if (tvReqInfo != null)
            {
                HttpRequestInfo httpReqInfo = new HttpRequestInfo(_sourceStore.LoadRequestData(tvReqInfo.Id));

                if (httpReqInfo.Host == String.Empty)
                {
                    HttpServerConsole.Instance.WriteLine(LogMessageType.Error,
                                                         "Could not find a host. You might need to add the host manually");
                }
            }
        }
Exemple #8
0
        public HttpResponseInfo SendRequest(HttpRequestInfo requestInfo)
        {
            int           idx = -1;
            TVRequestInfo currDataSourceInfo = null;

            byte[] response = null;

            while ((currDataSourceInfo = _mockSite.GetNext(ref idx)) != null)
            {
                if (String.Compare(currDataSourceInfo.RequestLine, requestInfo.RequestLine) == 0)
                {
                    response = _mockSite.LoadResponseData(currDataSourceInfo.Id);
                    break;
                }
            }
            HttpResponseInfo respInfo = null;

            if (response != null)
            {
                respInfo = new HttpResponseInfo(response);
            }
            return(respInfo);
        }
        protected override void Export(ITrafficDataAccessor source, System.IO.Stream stream, bool overwriteScheme, bool isSSL, string newHost, int newPort)
        {
            TVRequestInfo info;

            int i = -1;

            string overridenScheme = isSSL ? "https" : "http";
            //using an xml writer for memory concerns
            XmlWriter writer = new XmlTextWriter(stream, Encoding.UTF8);

            writer.WriteStartDocument();
            writer.WriteStartElement("StateInducer");
            writer.WriteAttributeString("Version", "1.1");


            writer.WriteStartElement("Sequences");
            writer.WriteStartElement("Sequence");

            writer.WriteAttributeString("Name", "Exported from X-Force Black Ops");
            writer.WriteAttributeString("Enabled", "True");
            writer.WriteAttributeString("ReplayOptimizationsEnabled", "False");
            writer.WriteAttributeString("TestInIsolation", "True");
            writer.WriteAttributeString("TestSingleThreadedly", "True");
            writer.WriteAttributeString("ManualExploreEnabled", "False");
            writer.WriteAttributeString("LoginRequired", "True");


            writer.WriteStartElement("requests");

            while ((info = source.GetNext(ref i)) != null)
            {
                string scheme = info.IsHttps ? "https" : "http";
                scheme = overwriteScheme ? overridenScheme : scheme;
                //get the request information
                byte[] reqData  = source.LoadRequestData(info.Id);
                byte[] respData = source.LoadResponseData(info.Id);

                if (reqData != null)
                {
                    HttpRequestInfo  reqInfo  = new HttpRequestInfo(reqData);
                    HttpResponseInfo respInfo = new HttpResponseInfo(respData);
                    //add to the list of variables
                    AddToVariableInfoCollection(reqInfo.Cookies.GetVariableInfoCollection());
                    AddToVariableInfoCollection(reqInfo.QueryVariables.GetVariableInfoCollection());
                    AddToVariableInfoCollection(reqInfo.BodyVariables.GetVariableInfoCollection());
                    AddToVariableInfoCollection(reqInfo.PathVariables.GetVariableInfoCollection());

                    WriteRequest(writer, newHost, newPort, scheme, reqInfo, respInfo);
                }
            }

            writer.WriteEndElement();

            //writer.WriteRaw(Resources.VariableDefinitions);

            writer.WriteEndElement();
            writer.WriteEndElement();

            writer.WriteEndElement();
            writer.WriteEndDocument();

            writer.Flush();
            writer.Close();
        }
        protected override void Export(ITrafficDataAccessor source, System.IO.Stream stream, bool overwriteScheme, bool isSSL, string newHost, int newPort)
        {
            TVRequestInfo info, inSessionRequestInfo = null;

            int i = -1, count = 0;

            string overridenScheme = isSSL ? "https" : "http";
            //using an xml writer for memory concerns
            XmlWriter writer       = new XmlTextWriter(stream, Encoding.UTF8);

            writer.WriteStartDocument();
            writer.WriteStartElement("SessionManagement");
            writer.WriteAttributeString("Version", "1.2");
            writer.WriteElementString("SessionManagementMode", "Manual");
            writer.WriteElementString("AllowConcurrentLogins", "True");
            writer.WriteElementString("EnableJSXInLoginReplay", "False");

            writer.WriteStartElement("RecordedSessionRequests");

            bool loginFound = false;


            while ((info = source.GetNext(ref i)) != null)
            {
                string scheme = info.IsHttps ? "https" : "http";
                scheme = overwriteScheme ? overridenScheme : scheme;
                //get the request information
                byte[] reqData  = source.LoadRequestData(info.Id);
                byte[] respData = source.LoadResponseData(info.Id);

                if (reqData != null)
                {
                    HttpRequestInfo reqInfo = new HttpRequestInfo(reqData);
                    reqInfo.IsSecure = scheme.Equals("https");
                    HttpResponseInfo respInfo = new HttpResponseInfo(respData);
                    //add to the list of variables
                    AddToVariableInfoCollection(reqInfo.Cookies.GetVariableInfoCollection());
                    AddToVariableInfoCollection(reqInfo.QueryVariables.GetVariableInfoCollection());
                    AddToVariableInfoCollection(reqInfo.BodyVariables.GetVariableInfoCollection());
                    AddToVariableInfoCollection(reqInfo.PathVariables.GetVariableInfoCollection());

                    if (info.Description.IndexOf(Resources.Login, StringComparison.OrdinalIgnoreCase) != -1)
                    {
                        WriteRequest(writer, newHost, newPort, scheme, reqInfo, respInfo, new KeyValuePair <string, string>("SessionRequestType", "Login"));
                        loginFound = true;
                        count++;
                    }
                    else if (info.Description.IndexOf(Resources.Session, StringComparison.OrdinalIgnoreCase) != -1)
                    {
                        WriteRequest(writer, newHost, newPort, scheme, reqInfo, respInfo, new KeyValuePair <string, string>("IsSessionVerifier", "True"));
                        inSessionRequestInfo = info;
                        break;
                    }
                    else if (loginFound)
                    {
                        break;
                    }
                }
            }


            writer.WriteEndElement();

            if (inSessionRequestInfo != null)
            {
                writer.WriteStartElement("SessionVerifier");
                writer.WriteElementString("Enable", "True");
                writer.WriteElementString("Pattern", @"(?i)((log|sign)\s?(out|off)|exit|quit)");
                writer.WriteElementString("PatternType", "RegularExpression");
                byte[] reqData  = source.LoadRequestData(inSessionRequestInfo.Id);
                byte[] respData = source.LoadResponseData(inSessionRequestInfo.Id);


                string scheme = inSessionRequestInfo.IsHttps ? "https" : "http";
                scheme = overwriteScheme ? overridenScheme : scheme;

                WriteRequest(writer, newHost, newPort, scheme, new HttpRequestInfo(reqData), new HttpResponseInfo(respData), new KeyValuePair <string, string>("SessionRequestType", "Regular"));
                writer.WriteEndElement();

                writer.WriteElementString("InSessionRequestIndex", count.ToString());
            }

            //WriteVariableDefinitions(writer);

            writer.WriteEndElement();
            writer.WriteEndDocument();

            writer.Close();

            if (!loginFound)
            {
                //warn the user
                throw new Exception(Resources.NoLoginRequestsFound);
            }
        }