public async Task WhenInvalidOldPassword_Throws()
        {
            var uniqueData = UNIQUE_PREFIX + "InvOldPw_T";

            using var app = _appFactory.Create();
            var contentRepository = app.Services.GetContentRepository();

            var userId = await app.TestData.Users().AddAsync(uniqueData, c => c.Password = OLD_PASSWORD);

            await contentRepository
            .Users()
            .Authentication()
            .SignInAuthenticatedUserAsync(new SignInAuthenticatedUserCommand()
            {
                UserId = userId
            });

            var command = new UpdateCurrentUserPasswordCommand()
            {
                NewPassword = OLD_PASSWORD,
                OldPassword = NEW_PASSWORD
            };

            await contentRepository
            .Awaiting(r => r.ExecuteCommandAsync(command))
            .Should()
            .ThrowAsync <InvalidCredentialsAuthenticationException>()
            .WithMemberNames(nameof(command.OldPassword));
        }
Beispiel #2
0
        public async Task <ActionResult> UpdatePassword(UpdateCurrentUserPasswordCommand command,
                                                        CancellationToken token)
        {
            await Mediator.Send(command, token);

            return(NoContent());
        }
        public void ConfirmPasswordIsValid_ShouldNotHaveError()
        {
            _command = new UpdateCurrentUserPasswordCommand {
                ConfirmNewPassword = "******"
            };

            _sut.ShouldNotHaveValidationErrorFor(x => x.ConfirmNewPassword, _command);
        }
        public void ConfirmPasswordIsNullOrEmpty_ShouldHaveError(string confirmPassword)
        {
            _command = new UpdateCurrentUserPasswordCommand {
                ConfirmNewPassword = confirmPassword
            };

            _sut.ShouldHaveValidationErrorFor(x => x.ConfirmNewPassword, _command);
        }
        public void PasswordIsDifferentFromConfirmPassword_ShouldHaveError()
        {
            _command = new UpdateCurrentUserPasswordCommand
            {
                NewPassword = "******", ConfirmNewPassword = "******"
            };

            _sut.ShouldHaveValidationErrorFor(x => x.NewPassword, _command);
        }
Beispiel #6
0
        public async Task <IActionResult> PutPassword([FromBody] UpdateCurrentUserUserPasswordCommandDto dto)
        {
            var command = new UpdateCurrentUserPasswordCommand()
            {
                OldPassword = dto.OldPassword,
                NewPassword = dto.NewPassword
            };

            return(await _apiResponseHelper.RunCommandAsync(this, command));
        }
        public void SetUp()
        {
            _service    = new Mock <IUpdateCurrentUserPasswordService>();
            _unitOfWork = new Mock <IUnitOfWork>();
            _sut        = new UpdateCurrentUserPasswordCommandHandler(_service.Object, _unitOfWork.Object);

            _command = new UpdateCurrentUserPasswordCommand {
                NewPassword = "******",
            };

            _currentUser = new User("email", "organizationId");
            _service.Setup(x => x.GetCurrentUser(default))
        public async Task WhenSystemUser_Throws()
        {
            using var app = _appFactory.Create();
            var repository = app.Services.GetContentRepositoryWithElevatedPermissions();

            var command = new UpdateCurrentUserPasswordCommand()
            {
                NewPassword = NEW_PASSWORD,
                OldPassword = OLD_PASSWORD
            };

            await repository
            .Awaiting(r => r.ExecuteCommandAsync(command))
            .Should()
            .ThrowAsync <EntityNotFoundException <User> >();
        }
        public async Task WhenNotSignedIn_Throws()
        {
            using var app = _appFactory.Create();
            var repository = app.Services.GetService <IDomainRepository>();

            var command = new UpdateCurrentUserPasswordCommand()
            {
                NewPassword = NEW_PASSWORD,
                OldPassword = OLD_PASSWORD
            };

            await repository
            .Awaiting(r => r.ExecuteCommandAsync(command))
            .Should()
            .ThrowAsync <PermissionValidationFailedException>();
        }
 public Task UpdateCurrentUserPasswordAsync(UpdateCurrentUserPasswordCommand command)
 {
     return(ExtendableContentRepository.ExecuteCommandAsync(command));
 }