Пример #1
0
        public void When_AdditionalObsoleteAlgorithmIsGiven_Expect_NotUsed()
        {
            const string tmpAlgorithmId       = "TmpAlgorithm";
            const bool   tmpAlgorithmObsolete = true;

            var tmpAlgorithm = new Mock <IPasswordHashAlgorithm>();

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

            PasswordAlgorithmRepo.RegisterAlgorithm(tmpAlgorithm.Object);

            var passwordRequest = new PasswordHashRequest
            {
                AlgorithmId = currentAlgorithm.AlgorithmId,
                Password    = "******",
                Salt        = "Tmp"
            };

            var agileHash = new AgilePasswordHash();

            var response = agileHash.Hash(passwordRequest);

            Assert.AreEqual(response.AlgorithmId, currentAlgorithm.AlgorithmId);

            passwordRequest.AlgorithmId = null;

            response = agileHash.Hash(passwordRequest);

            Assert.AreEqual(response.AlgorithmId, newAlgorithm.AlgorithmId);

            PasswordAlgorithmRepo.DeregisterAlgorithm(tmpAlgorithmId);
        }
Пример #2
0
        public void When_CurrentIsObsolete_Expect_SecondRequestUseNewAlgorithm()
        {
            var request = new PasswordHashRequest
            {
                AlgorithmId = currentAlgorithm.AlgorithmId,
                Password    = "******",
                Salt        = "MySalt"
            };

            var agileHash = new AgilePasswordHash();

            var response = agileHash.Hash(request);

            Assert.AreEqual(response.AlgorithmId, currentAlgorithm.AlgorithmId);
            Assert.IsTrue(response.IsObsolete);

            request.AlgorithmId = null;

            response = agileHash.Hash(request);

            Assert.AreEqual(response.AlgorithmId, newAlgorithm.AlgorithmId);
            Assert.IsFalse(response.IsObsolete);
        }