Beispiel #1
0
        public async Task ChangePassword_GivenDifferentNewAndConfirmPassword_ThrowsException()
        {
            var userRepository        = Substitute.For <IUserRepository>();
            var roleRepository        = Substitute.For <IRoleRepository>();
            var teamRepository        = Substitute.For <ITeamRepository>();
            var ldapRepository        = Substitute.For <ILdapAuthenticationModeRepository>();
            var ldapConnectionService = Substitute.For <ILdapConnectionService>();

            var userPasswordChangeSubmit = new UserPasswordChangeSubmit()
            {
                Uuid                 = Guid.NewGuid(),
                OldPassword          = "******",
                NewPassword          = "******",
                NewPasswordConfirmed = "newPassword2"
            };

            var userService = new UserService(userRepository, roleRepository, teamRepository, ldapRepository, mapper, ldapConnectionService);

            Exception caughtException = null;

            try
            {
                await userService.ChangePassword(userPasswordChangeSubmit);
            }
            catch (Exception ex)
            {
                caughtException = ex;
            }

            Assert.True(caughtException is ItemNotProcessableException, "Correctly changing password should NOT throw any exeption");
            Assert.True(caughtException.Message == "New password and confirm new password fields do not match.", "Differing new passwords should return 'New password and confirm new password fields do not match.'");
        }
Beispiel #2
0
        public async Task ChangePassword_GivenNoOldPassword_ThrowsException()
        {
            var userRepository        = Substitute.For <IUserRepository>();
            var roleRepository        = Substitute.For <IRoleRepository>();
            var teamRepository        = Substitute.For <ITeamRepository>();
            var ldapRepository        = Substitute.For <ILdapAuthenticationModeRepository>();
            var ldapConnectionService = Substitute.For <ILdapConnectionService>();

            var userPasswordChangeSubmit = new UserPasswordChangeSubmit()
            {
                Uuid                 = Guid.NewGuid(),
                NewPassword          = "******",
                NewPasswordConfirmed = "newPassword1"
            };

            var userService = new UserService(userRepository, roleRepository, teamRepository, ldapRepository, mapper, ldapConnectionService);

            Exception caughtException = null;

            try
            {
                await userService.ChangePassword(userPasswordChangeSubmit);
            }
            catch (Exception ex)
            {
                caughtException = ex;
            }

            Assert.True(caughtException is ItemNotProcessableException, "Correctly changing password should NOT throw any exeption");
            Assert.True(caughtException.Message == "Old password must be specified.", "Missing old password returned should return 'Old password must be specified.'");
        }
Beispiel #3
0
        public async Task ChangePassword_GivenUserChangeSubmit_CompletesSuccessfully()
        {
            var userRepository        = Substitute.For <IUserRepository>();
            var roleRepository        = Substitute.For <IRoleRepository>();
            var teamRepository        = Substitute.For <ITeamRepository>();
            var ldapRepository        = Substitute.For <ILdapAuthenticationModeRepository>();
            var ldapConnectionService = Substitute.For <ILdapConnectionService>();

            var userPasswordChangeSubmit = new UserPasswordChangeSubmit()
            {
                Uuid                 = Guid.NewGuid(),
                OldPassword          = "******",
                NewPassword          = "******",
                NewPasswordConfirmed = "newPassword1"
            };

            var userService = new UserService(userRepository, roleRepository, teamRepository, ldapRepository, mapper, ldapConnectionService);

            Exception caughtException = null;

            try
            {
                await userService.ChangePassword(userPasswordChangeSubmit);
            }
            catch (Exception ex)
            {
                caughtException = ex;
            }

            Assert.True(caughtException == null, "Correctly changing password should NOT throw any exeption");
        }
Beispiel #4
0
        public async Task ChangePassword_GivenUserChangeSubmit_ReturnsNoContent()
        {
            // Arrange
            var userService = Substitute.For <IUserService>();
            var controller  = new UserController(userService);

            var guid = Guid.NewGuid();
            var userPasswordChangeSubmit = new UserPasswordChangeSubmit()
            {
                Uuid                 = guid,
                OldPassword          = "******",
                NewPassword          = "******",
                NewPasswordConfirmed = "newPassword1"
            };

            // Act
            Exception     caughtException = null;
            IActionResult actionResult    = null;

            try
            {
                actionResult = await controller.ChangeUserPasswordAsync(guid, userPasswordChangeSubmit);
            }
            catch (Exception ex)
            {
                caughtException = ex;
            }

            // Assert
            var noContentResult = actionResult as NoContentResult;

            Assert.NotNull(noContentResult);
        }
Beispiel #5
0
        public async Task ChangePassword(UserPasswordChangeSubmit changeSubmit)
        {
            if (string.Compare(changeSubmit.NewPassword, changeSubmit.NewPasswordConfirmed, StringComparison.Ordinal) != 0)
            {
                throw new ItemNotProcessableException("New password and confirm new password fields do not match.");
            }

            if (string.IsNullOrEmpty(changeSubmit.OldPassword))
            {
                throw new ItemNotProcessableException("Old password must be specified.");
            }

            await userRepository.ChangePassword(changeSubmit.Uuid, changeSubmit.OldPassword, changeSubmit.NewPassword);
        }
Beispiel #6
0
 public abstract Task <IActionResult> ChangeUserPasswordAsync([FromRoute][Required] Guid userId, [FromBody] UserPasswordChangeSubmit userPasswordChangeSubmit);
Beispiel #7
0
        public async override Task <IActionResult> ChangeUserPasswordAsync([FromRoute, Required] Guid userId, [FromBody] UserPasswordChangeSubmit userPasswordChangeSubmit)
        {
            if (userId == Guid.Empty)
            {
                return(BadRequest());
            }

            await userService.ChangePassword(userPasswordChangeSubmit);

            return(NoContent());
        }