Пример #1
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
        }
Пример #2
0
        public void RequestDifferTest()
        {
            TrafficViewerFile tvf = UnitTestUtils.GenerateTestTvf();

            RequestsDiffer reqDiffer = new RequestsDiffer();

            //compare two similar requests

            RequestsDifferResult res = reqDiffer.Diff(24, 29, tvf);

            Assert.AreEqual(16, res.DiffsForFirst.Count);
            Assert.AreEqual(14, res.DiffsForSecond.Count);

            Assert.AreEqual(0.9613687022159203, res.BodyAproximateSimilarity, 0.009);

            //first request is logged out
            Assert.IsTrue(res.DiffsForFirst[11].ToString().Contains
                              ("You do not appear to have authenticated yourself with the application."));

            //second request is logged in
            Assert.IsTrue(res.DiffsForSecond[6].ToString().Contains
                              ("out of the Online Banking application."));
        }
Пример #3
0
        public void TestTrafficLogProxy()
        {
            TrafficViewer.Instance.HttpClientFactory = new TrafficViewerHttpClientFactory();

            TrafficViewerFile tvf   = UnitTestUtils.GenerateTestTvf();
            TrafficStoreProxy proxy = new TrafficStoreProxy(tvf);

            proxy.Start();

            HttpClientRequest request = new HttpClientRequest();

            HttpRequestInfo reqInfo = new HttpRequestInfo(Properties.Resources.AltoroLoginPageRequest);

            //change the host and port to the proxy

            reqInfo.Host = proxy.Host;
            reqInfo.Port = proxy.Port;

            //test http
            request.SendRequest(reqInfo, false);

            request.RequestCompleteEvent.WaitOne();

            ValidateResponse(request);

            //test https
            proxy.Stop();
            proxy.Start();

            request.SendRequest(reqInfo, true);

            request.RequestCompleteEvent.WaitOne(2 * 1000);

            ValidateResponse(request);

            proxy.Stop();
        }