Exemplo n.º 1
0
        public string SendTest(string mutatedRequest, string host, int port, bool useSSL)
        {
            HttpRequestInfo reqInfo = new HttpRequestInfo(mutatedRequest, false);

            reqInfo.IsSecure = useSSL;
            reqInfo.Host     = host;
            reqInfo.Port     = port;
            IHttpClient client = _httpClientFactory.MakeClient();

            client.SetNetworkSettings(_netSettings);
            DateTime reqTime = DateTime.Now;


            HttpResponseInfo resp = null;


            TVRequestInfo tvReqInfo = null;

            if (_verbose)
            {
                tvReqInfo = SaveRequest("Custom Test", reqInfo, useSSL, String.Empty, reqTime, reqTime, "");
            }

            try
            {
                resp = client.SendRequest(reqInfo);
            }
            catch
            { }
            DateTime respTime = DateTime.Now;

            string response;

            if (resp != null)
            {
                PatternTracker.Instance.UpdatePatternValues(resp);
                response = resp.ToString();
                if (tvReqInfo != null)
                {
                    tvReqInfo.ResponseTime = DateTime.Now;
                    _trafficFile.UpdateRequestInfo(tvReqInfo);
                    _trafficFile.SaveResponse(tvReqInfo.Id, resp.ToArray());
                }
            }
            else
            {
                response = String.Empty;
            }

            return(response);
        }
Exemplo n.º 2
0
        public void EditARequest()
        {
            string originalRequest  = "GET / HTTP/1.1";
            string originalResponse = "HTTP/1.1 200 OK";

            TrafficViewerFile file = new TrafficViewerFile();
            int reqId = file.AddRequestResponse(originalRequest, originalResponse);

            Assert.AreEqual(1, file.RequestCount);
            TVRequestInfo reqInfo = file.GetRequestInfo(reqId);

            string newRequest  = "POST /login HTTP/1.1";
            string newResponse = "HTTP/1.1 302 Redirect";

            file.SaveRequest(reqId, Encoding.UTF8.GetBytes(newRequest));
            file.SaveResponse(reqId, Encoding.UTF8.GetBytes(newResponse));

            //check the response info was updated
            Assert.AreEqual(newRequest, reqInfo.RequestLine);
            Assert.AreEqual("302", reqInfo.ResponseStatus);
            Assert.AreEqual(newRequest.Length, reqInfo.RequestLength);
            Assert.AreEqual(newResponse.Length, reqInfo.ResponseLength);

            string loadedRequest = Encoding.UTF8.GetString(file.LoadRequestData(reqId));

            Assert.AreEqual(newRequest, loadedRequest);
            string loadedResponse = Encoding.UTF8.GetString(file.LoadResponseData(reqId));

            Assert.AreEqual(newResponse, loadedResponse);
            file.Close(false);
        }
Exemplo n.º 3
0
        public void EditTVF()
        {
            TrafficViewerFile tvf = UnitTestUtils.GenerateTestTvf();
            //check delete
            int initialCount = tvf.RequestCount;
            //get the first request id
            int           i      = -1;
            TVRequestInfo first  = tvf.GetNext(ref i);
            TVRequestInfo second = tvf.GetNext(ref i);

            HttpRequestInfo secondRequest = new HttpRequestInfo(tvf.LoadRequestData(second.Id));

            HttpResponseInfo secondResponse = new HttpResponseInfo();

            byte [] respBytes = tvf.LoadResponseData(second.Id);
            secondResponse.ProcessResponse(respBytes);
            int referenceResponseStatus = secondResponse.Status;

            int referenceHash = secondRequest.GetHashCode();

            Assert.IsTrue(tvf.RemoveRequest(first.Id));
            Assert.AreEqual(initialCount - 1, tvf.RequestCount);
            Assert.IsNull(tvf.GetPrevious(ref i));

            RequestDataCache.Instance.Clear();
            //check that

            //check add

            TVRequestInfo reqInfo = new TVRequestInfo();

            reqInfo.RequestLine = "GET /newrequest HTTP/1.1";
            string request  = "GET /newrequest HTTP/1.1\r\nHeader1:1\r\n\r\n";
            string response = "HTTP 200 OK\r\nHeader1:1\r\n\r\n<html><body>Added request</body></html>";

            RequestResponseBytes reqData = new RequestResponseBytes();

            reqData.AddToRequest(Constants.DefaultEncoding.GetBytes(request));
            reqData.AddToResponse(Constants.DefaultEncoding.GetBytes(response));

            tvf.AddRequestInfo(reqInfo);
            tvf.SaveRequest(reqInfo.Id, reqData);
            tvf.SaveResponse(reqInfo.Id, reqData);

            //Check that the request was added
            response = Constants.DefaultEncoding.GetString(tvf.LoadResponseData(reqInfo.Id));

            Assert.AreEqual(38, response.IndexOf("Added request"));
            Assert.AreEqual(65, response.Length);
            //modify the recently added request slightly
        }
Exemplo n.º 4
0
        private TVRequestInfo SaveRequest(string description, HttpRequestInfo reqInfo, bool isSecure, string testResponse, DateTime requestTime, DateTime responseTime, string validation)
        {
            TVRequestInfo newReqInfo = new TVRequestInfo();

            newReqInfo.Description    = description;
            newReqInfo.Validation     = validation;
            newReqInfo.Host           = reqInfo.Host;
            newReqInfo.ResponseStatus = HttpResponseInfo.GetResponseStatus(testResponse);
            newReqInfo.RequestTime    = requestTime;

            newReqInfo.IsHttps     = isSecure;
            newReqInfo.ThreadId    = Utils.GetCurrentWin32ThreadId().ToString();
            newReqInfo.RequestLine = reqInfo.RequestLine;
            int newId = _trafficFile.AddRequestInfo(newReqInfo);

            _trafficFile.SaveRequest(newId, Constants.DefaultEncoding.GetBytes(reqInfo.ToString(false)));
            if (!String.IsNullOrWhiteSpace(testResponse))
            {
                _trafficFile.SaveResponse(newId, Constants.DefaultEncoding.GetBytes(testResponse));
                newReqInfo.ResponseTime = responseTime;
            }
            return(newReqInfo);
        }