示例#1
0
        public void HandlersSpeedComparer_GetSecuredValue_UrlDataHandlers_ClearSecureData()
        {
            //ARRANGE
            string data            = "http://test.com?user=max&pass=123456&lang=rus&credit_card=660666&tel_number=89002223434";
            var    keyValueHandler = new UrlGetKeyValueDataHandler()
            {
                Properties = new Dictionary <string, string>
                {
                    { "user", "max" },
                    { "pass", "123456" },
                    { "lang", "rus" },
                    { "credit_card", "660666" },
                    { "tel_number", "89002223434" }
                }
            };

            var commonHandler = new UrlGetRequestDataHandler()
            {
                Properties = new [] { "user", "pass", "lang", "credit_card", "tel_number" }
            };

            //ACT
            var keyValueHandlerWorkTime = GetKeyValueHandlerExecutionTime(keyValueHandler, RepeatsNum, data);
            var commonHandlerWorkTime   = GetCommonHandlerExecutionTime(commonHandler, RepeatsNum, data);

            //ASSERT
            Assert.IsTrue(keyValueHandlerWorkTime < commonHandlerWorkTime);
        }
示例#2
0
        public void HandlersThreadSafety_GetSecuredValue_UrlDataHandlers_ClearSecureData()
        {
            //ARRANGE
            var handler = new UrlGetRequestDataHandler {
                Properties = new string[] { "user", "pass" }
            };
            const string data     = "http://test.com?user=max&pass=123456";
            const string expected = "http://test.com?user=XXX&pass=XXXXXX";

            //ACT
            List <Thread> threads = new List <Thread>();
            string        result1 = "", result2 = "", result3 = "", result4 = "";

            threads.AddRange(new List <Thread>
            {
                new Thread(() => { result1 = handler.GetSecuredData(data); }),
                new Thread(() => { result2 = handler.GetSecuredData(data); }),
                new Thread(() => { result3 = handler.GetSecuredData(data); }),
                new Thread(() => { result4 = handler.GetSecuredData(data); })
            });

            foreach (var thread in threads)
            {
                thread.Start();
                thread.Join();
            }

            //ASSERT
            Assert.AreEqual(expected, result1);
            Assert.AreEqual(expected, result2);
            Assert.AreEqual(expected, result3);
            Assert.AreEqual(expected, result4);
        }
示例#3
0
        public void UrlGetRequestDataHandler_GetSecuredData_EmptySecuredProps_NonChangedResult()
        {
            //ARRANGE
            AbstractDataHandler handler = new UrlGetRequestDataHandler();

            handler.Properties = new string[] { };

            //ACT
            var result = handler.GetSecuredData("http://test.com?user=max&pass=123456");

            //ASSERT
            Assert.AreEqual("http://test.com?user=max&pass=123456", result);
        }
示例#4
0
        public void UrlGetRequestDataHandler_GetSecuredData_SomePropsNotInRequest_ListedParametresSecured()
        {
            //ARRANGE
            AbstractDataHandler handler = new UrlGetRequestDataHandler();

            handler.Properties = new string[] { "user", "first_name" };

            //ACT
            var result = handler.GetSecuredData("http://test.com?user=max&pass=123456");

            //ASSERT
            Assert.AreEqual("http://test.com?user=XXX&pass=123456", result);
        }
示例#5
0
        public void UrlGetRequestDataHandler_GetSecuredData_NonEmptySecuredProps_ParametresSecured()
        {
            //ARRANGE
            AbstractDataHandler handler = new UrlGetRequestDataHandler();

            handler.Properties = new string[] { "user", "pass" };

            //ACT
            var result = handler.GetSecuredData("http://test.com?user=max&pass=123456");

            //ASSERT
            Assert.AreEqual("http://test.com?user=XXX&pass=XXXXXX", result);
        }
        public override string GetSecuredData(string data)
        {
            var splitedUrl = data.Split('/');

            foreach (var key in Properties)
            {
                for (var i = 0; i < splitedUrl.Length; i++)
                {
                    if ((splitedUrl[i] == key) && (i != splitedUrl.Length - 1))
                    {
                        splitedUrl[i + 1] = new string('X', splitedUrl[i + 1].Length);
                        i++;
                    }
                }
            }

            var urlDataHandler = new UrlGetRequestDataHandler
            {
                Properties = this.Properties
            };

            return(urlDataHandler.GetSecuredData(string.Join("/", splitedUrl)));
        }