コード例 #1
0
        //TODO: IMPORTANT This needs to be ported correctly, not using VoatUserManager param any longer
        public static async Task <bool> CanUserNameBeRegistered(VoatUserManager userManager, string userName, IDictionary <string, string> charSwaps = null)
        {
            //List<string> spoofsToCheck = new List<string>();
            //spoofsToCheck.Add(userName); //add original username

            ////process deviations
            //if (spoofSubstitutionFuncList != null && spoofSubstitutionFuncList.Any())
            //{
            //    foreach (var spoofFunc in spoofSubstitutionFuncList)
            //    {
            //        var l = spoofFunc(userName);
            //        if (l != null && l.Any())
            //        {
            //            spoofsToCheck.AddRange(l.Where(x => !String.IsNullOrEmpty(x) && !userName.IsEqual(x)).ToList()); //only add valid items
            //        }
            //    }
            //}

            //TODO: Need to migrate to dapper and repo
            //var accountExists = spoofsToCheck.Any(x => userManager.FindByNameAsync(x).Result != null);
            var spoofsToCheck = SpooferProofer.CharacterSwapList(userName, charSwaps, true, Normalization.Lower);
            var accountExists = await VoatUserManager.UserNameExistsAsync(spoofsToCheck);

            return(!accountExists);
        }
コード例 #2
0
ファイル: MiscUtilsTests.cs プロジェクト: vrijdagweekend/voat
        public void SpooferProofer_Tests()
        {
            var charSwaps = new Dictionary <string, string>()
            {
                { "i", "l" },
                { "o", "0" }
            };
            var identifier      = "LeeroyJenkins";
            var expectingToFind = "";

            var testSpoofList = new Action <Normalization>(normalization => {
                var spoofList = SpooferProofer.CharacterSwapList(identifier, charSwaps, true, normalization);

                if (normalization == Normalization.None)
                {
                    Assert.AreEqual(4, spoofList.Count());
                }
                else
                {
                    Assert.AreEqual(8, spoofList.Count());
                }

                expectingToFind = identifier.ToNormalized(normalization);
                Assert.AreEqual(expectingToFind, spoofList.FirstOrDefault(x => x == expectingToFind));

                expectingToFind = "Leer0yJenklns".ToNormalized(normalization);
                Assert.AreEqual(expectingToFind, spoofList.FirstOrDefault(x => x == expectingToFind));

                expectingToFind = "LeeroyJenklns".ToNormalized(normalization);
                Assert.AreEqual(expectingToFind, spoofList.FirstOrDefault(x => x == expectingToFind));

                expectingToFind = "Leer0yJenkins".ToNormalized(normalization);
                Assert.AreEqual(expectingToFind, spoofList.FirstOrDefault(x => x == expectingToFind));
            });

            testSpoofList(Normalization.None);
            testSpoofList(Normalization.Lower);
            testSpoofList(Normalization.Upper);

            ////Lowered tests same inputs but all outputs should be lower cased
            //spoofs = SpooferProofer.CharacterSwapList(identifier, charSwaps, true, Normalization.Lower);

            //expectingToFind = identifier.ToLower();
            //Assert.AreEqual(expectingToFind, spoofs.FirstOrDefault(x => x == expectingToFind));

            //expectingToFind = "Leer0yJenklns".ToLower();
            //Assert.AreEqual(expectingToFind, spoofs.FirstOrDefault(x => x == expectingToFind));

            //expectingToFind = "LeeroyJenklns".ToLower();
            //Assert.AreEqual(expectingToFind, spoofs.FirstOrDefault(x => x == expectingToFind));

            //expectingToFind = "Leer0yJenkins".ToLower();
            //Assert.AreEqual(expectingToFind, spoofs.FirstOrDefault(x => x == expectingToFind));

            //Test not reversed swaps
            identifier = "Leer0yJenklns";
            var spoofs = SpooferProofer.CharacterSwapList(identifier, charSwaps, false);

            Assert.AreEqual(1, spoofs.Count());

            expectingToFind = identifier;
            Assert.AreEqual(expectingToFind, spoofs.FirstOrDefault(x => x == expectingToFind));
        }