Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
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)));
        }