Пример #1
0
        public void When_SearchPbkdf_Expect_AlgorithmFound()
        {
            var collection = PasswordAlgorithmRepo.Search("pbkdfv2-*");

            Assert.IsTrue(collection.Any());
            Assert.IsTrue(collection.All(a => a.AlgorithmId.StartsWith("PBKDFv2")));
        }
Пример #2
0
        public void When_SearchingForNonObsoleteAlgorithm_Expect_ExcludedObsoleteOnes()
        {
            PasswordAlgorithmRepo.RegisterAlgorithm(algorithm);

            var collection = PasswordAlgorithmRepo.Search("*", false);

            Assert.IsTrue(collection.Any());
            Assert.IsFalse(collection.Any(a => a.AlgorithmId == algorithm.AlgorithmId));
        }
Пример #3
0
        public void When_AddingAlgorithm_Expect_ShowsInSearch()
        {
            PasswordAlgorithmRepo.RegisterAlgorithm(algorithm);

            var collection = PasswordAlgorithmRepo.Search("*", true);

            var foundAlgorithm = collection.FirstOrDefault(a => a.AlgorithmId == algorithm.AlgorithmId);

            Assert.AreSame(algorithm, foundAlgorithm);
        }
Пример #4
0
        public void OneTimeCleanup()
        {
            foreach (var algorithm in PasswordAlgorithmRepo.Search("*", true))
            {
                PasswordAlgorithmRepo.DeregisterAlgorithm(algorithm.AlgorithmId);
            }

            foreach (var algorithm in originalAlgorithms)
            {
                PasswordAlgorithmRepo.RegisterAlgorithm(algorithm);
            }
        }
Пример #5
0
        public void When_DeregisteringAlgorithm_Expect_NoLongerSearchable()
        {
            PasswordAlgorithmRepo.RegisterAlgorithm(algorithm);

            var myAlgorithm = PasswordAlgorithmRepo.Get(algorithm.AlgorithmId);

            Assert.IsNotNull(myAlgorithm);
            Assert.AreSame(algorithm, myAlgorithm);

            PasswordAlgorithmRepo.DeregisterAlgorithm(algorithm.AlgorithmId);

            Assert.Throws <PasswordHashException>(() => PasswordAlgorithmRepo.Get(algorithm.AlgorithmId), $"The given algorithm ID '{algorithm.AlgorithmId}' was not found in the repo.");
            Assert.IsFalse(PasswordAlgorithmRepo.Search(algorithm.AlgorithmId, true).Any());
        }
Пример #6
0
        public void OneTimeSetup()
        {
            originalAlgorithms = PasswordAlgorithmRepo.Search("*", true);
            foreach (var algorithm in originalAlgorithms)
            {
                PasswordAlgorithmRepo.DeregisterAlgorithm(algorithm.AlgorithmId);
            }

            // current algorithm Values
            const string currentAlgorithmId = "MockCurrent";
            const bool   currentIsObsolete  = true;

            var currentMockAlgorithm = new Mock <IPasswordHashAlgorithm>();

            currentMockAlgorithm.SetupGet(m => m.AlgorithmId).Returns(currentAlgorithmId);
            currentMockAlgorithm.SetupGet(m => m.IsObsolete).Returns(currentIsObsolete);
            currentMockAlgorithm.Setup(m => m.Hash(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new PasswordHashResponse
            {
                AlgorithmId = currentAlgorithmId,
                IsObsolete  = currentIsObsolete,
                Value       = CurrentHashValue
            });

            currentAlgorithm = currentMockAlgorithm.Object;
            PasswordAlgorithmRepo.RegisterAlgorithm(currentAlgorithm);

            // new algorithm values
            const string newAlgorithmId       = "MockNew";
            const bool   newAlgorithmObsolete = false;

            var newMockAlgorithm = new Mock <IPasswordHashAlgorithm>();

            newMockAlgorithm.SetupGet(m => m.AlgorithmId).Returns(newAlgorithmId);
            newMockAlgorithm.SetupGet(m => m.IsObsolete).Returns(newAlgorithmObsolete);
            newMockAlgorithm.Setup(m => m.Hash(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new PasswordHashResponse
            {
                AlgorithmId = newAlgorithmId,
                IsObsolete  = newAlgorithmObsolete,
                Value       = NewHashValue
            });

            newAlgorithm = newMockAlgorithm.Object;
            PasswordAlgorithmRepo.RegisterAlgorithm(newAlgorithm);
        }
Пример #7
0
 public void When_EmptyRepo_Expect_AlgorithmsRegistered()
 {
     Assert.IsTrue(PasswordAlgorithmRepo.Search("*").Any());
 }
Пример #8
0
 public void When_SearchingEmptyValue_Expect_NoError()
 {
     Assert.IsTrue(PasswordAlgorithmRepo.Search("*").Any());
     Assert.IsFalse(PasswordAlgorithmRepo.Search(null).Any());
     Assert.IsFalse(PasswordAlgorithmRepo.Search(string.Empty).Any());
 }