Ejemplo n.º 1
0
            public void ActivateWithExpiredDateThrowException()
            {
                // Arrange
                var stubUserDao = MockRepository.GenerateStub<IUserExtensionDao>();

                stubUserDao.Stub(userExtDao => userExtDao.GetByKey(USER_TEST_ID)).Return(new UserExtension
                                                                                         {
                                                                                             UserId = USER_TEST_ID,
                                                                                             UserStatusCode =
                                                                                                 USER_STATUS_CREATEDCODE
                                                                                         });

                var membershipMock = MockRepository.GenerateMock<IMembership>();

                membershipMock.Stub(mbs => mbs.GetUser(USER_TEST_ID)).Return(dummyMembershipUser);


                accountManager.UserExtensionDao = stubUserDao;
                accountManager.Membership = membershipMock;

                ActivationToken token = new ActivationToken
                                        {
                                            UserId = USER_TEST_ID,
                                            ExpiryDate = DateTime.Now.AddHours(-1),
                                            TypeCode = ACTIVATION_TYPE_CODE,
                                            Version = CURRENT_VERSION
                                        };

                string encryptedToken = accountManager.CreateActivationToken(token);

                ActivationRequest validActivationRequest = new ActivationRequest
                                                           {
                                                               Answer = SECURITY_ANSWER,
                                                               SecurityQuestionId = SECURITY_QUESTION_ID,
                                                               Password = PASSWORD,
                                                               Token = encryptedToken
                                                           };

                try
                {
                    //Act
                    string userName = accountManager.Activate(validActivationRequest);

                    // Assert
                    Assert.Fail("An exception SRVEX30067 of type ValidationException should have been thrown");
                }
                catch (ValidationException ex)
                {
                    // Assert
                    Assert.AreEqual(Errors.SRVEX30067.ToString(), ex.Code,
                                    "The Validation exception is not returning the right error code");
                }
            }
Ejemplo n.º 2
0
            public void ActivateWithCorrectTokenReturnTrue()
            {
                // Arrange
                var mockUserDao = MockRepository.GenerateMock<IUserExtensionDao>();

                var membershipMock = MockRepository.GenerateMock<IMembership>();

                membershipMock.Stub(mbs => mbs.GetUser(USER_TEST_ID)).Return(dummyMembershipUser);

                mockUserDao.Expect(userExtDao => userExtDao.Modify(Arg<UserExtension>.Is.Anything)).Return(true);

                mockUserDao.Stub(userExtDao => userExtDao.GetByKey(USER_TEST_ID)).Return(new UserExtension
                                                                                         {
                                                                                             UserId = USER_TEST_ID,
                                                                                             UserStatusCode = USER_STATUS_CREATEDCODE
                                                                                         });

                accountManager.UserExtensionDao = mockUserDao;
                accountManager.Membership = membershipMock;

                ActivationToken token = new ActivationToken
                                        {
                                            UserId = USER_TEST_ID,
                                            ExpiryDate = DateTime.Now.AddDays(5),
                                            TypeCode = ACTIVATION_TYPE_CODE,
                                            Version = CURRENT_VERSION
                                        };

                string encryptedToken = accountManager.CreateDefaultActivationToken(USER_TEST_ID);

                ActivationRequest validActivationRequest = new ActivationRequest
                                                           {
                                                               Answer = SECURITY_ANSWER,
                                                               SecurityQuestionId = SECURITY_QUESTION_ID,
                                                               Password = PASSWORD,
                                                               Token = encryptedToken
                                                           };

                membershipMock.Expect(mbs => mbs.ChangePassword(dummyMembershipUser, validActivationRequest.Password)).
                    Return(true);
                membershipMock.Expect(
                    mbs =>
                    mbs.ChangeSecurityQuestionAndAnswer(dummyMembershipUser, validActivationRequest.Password,
                                                        validActivationRequest.SecurityQuestionId.ToString(),
                                                        validActivationRequest.Answer)).Return(true);

                //Act
                string userName = accountManager.Activate(validActivationRequest);

                //Assert
                Assert.IsNotNull(userName, "Check the Activate method return a valid response.");

                membershipMock.VerifyAllExpectations();
                mockUserDao.VerifyAllExpectations();
            }
Ejemplo n.º 3
0
            public void ActivateWithUnknownUserThrowException()
            {
                // Arrange
                var stubUserDao = MockRepository.GenerateStub<IUserExtensionDao>();

                stubUserDao.Stub(userExtDao => userExtDao.GetByKey(USER_TEST_ID)).Return(null);

                accountManager.UserExtensionDao = stubUserDao;

                ActivationToken token = new ActivationToken
                                        {
                                            UserId = USER_TEST_ID,
                                            ExpiryDate = DateTime.Now.AddHours(1),
                                            TypeCode = ACTIVATION_TYPE_CODE,
                                            Version = CURRENT_VERSION
                                        };

                string encryptedToken = accountManager.CreateDefaultActivationToken(USER_TEST_ID);

                ActivationRequest validActivationRequest = new ActivationRequest
                                                           {
                                                               Answer = SECURITY_ANSWER,
                                                               SecurityQuestionId = SECURITY_QUESTION_ID,
                                                               Password = PASSWORD,
                                                               Token = encryptedToken
                                                           };

                try
                {
                    //Act
                    string userName = accountManager.Activate(validActivationRequest);

                    // Assert
                    Assert.Fail("An exception SRVEX30064 of type ValidationException should have been thrown");
                }
                catch (ValidationException ex)
                {
                    // Assert
                    Assert.AreEqual(Errors.SRVEX30064.ToString(), ex.Code,
                                    "The Validation exception is not returning the right error code");
                }
            }
Ejemplo n.º 4
0
        /// <summary>
        ///  Create a reset password activation token
        /// </summary>
        /// <param name="userId">User Id</param>
        /// <returns>return the encrypted token</returns>
        public string CreateResetPasswordActivationToken(Guid userId)
        {
            ActivationToken token = new ActivationToken
            {
                UserId = userId,
                ExpiryDate = DateTime.Now.AddDays(TOKEN_NB_HOURS_BEFORE_EXPIRATION),
                TypeCode = RESETPASSWORD_TYPE_CODE,
                Version = TOKEN_VERSION
            };

            return CreateActivationToken(token);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///  Create a default activation token
        /// </summary>
        /// <param name="userId">User Id</param>
        /// <returns>return the encrypted token</returns>
        public string CreateDefaultActivationToken(Guid userId)
        {
            ActivationToken token = new ActivationToken
                                    {
                                        UserId = userId,
                                        ExpiryDate = DateTime.Now.AddDays(TOKEN_NB_HOURS_BEFORE_EXPIRATION),
                                        TypeCode = ACTIVATION_TYPE_CODE,
                                        Version = TOKEN_VERSION
                                    };

           return CreateActivationToken(token);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Create and encrypt an activation token (public for test only)
 /// </summary>
 /// <returns>return the encrypted token</returns>
 public string CreateActivationToken(ActivationToken token)
 {
     return EncryptToken(token);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Activation token
        /// </summary>
        /// <param name="token">Activation token</param>
        /// <returns>encrypted token</returns>
        private string EncryptToken(ActivationToken token)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            string tokenStr = serializer.Serialize(token);

            string encryptToken = DesCrypto.Encrypt(tokenStr);

            return encryptToken;
        }