Beispiel #1
0
        public void NoSpacesTest()
        {
            var noSpacesMode = new NoSpaces("{{templKey:user}:'{templValue:user}',{templKey:pass}:'{templValue:pass}'}");

            for (int i = 1; i < 100000; i++)
            {
                var rndStringUsr  = Path.GetRandomFileName();
                var rndStringPass = Path.GetRandomFileName();
                var cleanRes      = noSpacesMode.CleanString("{user    :'******',   pass:'******'  }");
                Assert.AreEqual(cleanRes.CleanString,
                                "{user:'******',pass:'******'}");
                Assert.AreEqual(cleanRes.SecureData[0].Value, rndStringUsr);
                Assert.AreEqual(cleanRes.SecureData[1].Value, rndStringPass);
            }

            noSpacesMode = new NoSpaces("http://test.com/users/{templValue:user}/info");
            for (int i = 1; i < 100; i++)
            {
                var rndStringUsr = Path.GetRandomFileName();
                var cleanRes     = noSpacesMode.CleanString("http://test.com/users/" + rndStringUsr + "/info");
                Assert.AreEqual(cleanRes.CleanString,
                                "http://test.com/users/" + new String(noSpacesMode.Replacement, rndStringUsr.Length) + "/info");
                Assert.AreEqual(cleanRes.SecureData[0].Value, rndStringUsr);
            }
        }
Beispiel #2
0
        public void NoSpacesThreadingTest()
        {
            var  noSpacesMode       = new NoSpaces("{{templKey:user}:'{templValue:user}',{templKey:pass}:'{templValue:pass}'}");
            var  threaadList        = new List <Thread>();
            bool someThreadHasError = false;

            for (int j = 0; j < 50; j++)
            {
                var thread = new Thread(() =>
                {
                    for (int i = 1; i < 10000 && !someThreadHasError; i++)
                    {
                        var rndStringUsr   = Path.GetRandomFileName();
                        var rndStringPass  = Path.GetRandomFileName();
                        var cleanRes       = noSpacesMode.CleanString("{user:'******',pass:'******'}");
                        someThreadHasError = cleanRes.CleanString !=
                                             "{user:'******',pass:'******'}" && !someThreadHasError;
                        someThreadHasError = cleanRes.SecureData[0].Value != rndStringUsr && !someThreadHasError;
                        someThreadHasError = cleanRes.SecureData[1].Value != rndStringPass && !someThreadHasError;
                    }
                    lock (threaadList)
                    {
                        threaadList.Remove(Thread.CurrentThread);
                    }
                });
                lock (threaadList)
                {
                    threaadList.Add(thread);
                }
                thread.Start();
            }
            int threadCount = threaadList.Count;

            while (threadCount != 0)
            {
                Thread.Sleep(1000);
                lock (threaadList)
                {
                    threadCount = threaadList.Count;
                }
            }
            Assert.AreEqual(threadCount, 0);
            Assert.AreEqual(someThreadHasError, false);
        }