use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.
the class ChangePasswordAdminCommandTest method shouldUpdatePasswordOfOfflineUser.
@Test
public void shouldUpdatePasswordOfOfflineUser() {
// given
CommandSender sender = mock(CommandSender.class);
String player = "my_user12";
String password = "passPass";
given(playerCache.isAuthenticated(player)).willReturn(false);
given(dataSource.isAuthAvailable(player)).willReturn(true);
given(validationService.validatePassword(password, player)).willReturn(new ValidationResult());
HashedPassword hashedPassword = mock(HashedPassword.class);
given(passwordSecurity.computeHash(password, player)).willReturn(hashedPassword);
given(dataSource.updatePassword(player, hashedPassword)).willReturn(true);
// when
command.executeCommand(sender, Arrays.asList(player, password));
runOptionallyAsyncTask(bukkitService);
// then
verify(validationService).validatePassword(password, player);
verify(service).send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS);
verify(passwordSecurity).computeHash(password, player);
verify(dataSource).updatePassword(player, hashedPassword);
}
use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.
the class ValidationServiceTest method shouldRejectPasswordNotMatchingPattern.
@Test
public void shouldRejectPasswordNotMatchingPattern() {
// given/when
// service mock returns pattern a-zA-Z -> numbers should not be accepted
ValidationResult error = validationService.validatePassword("invalid1234", "myPlayer");
// then
assertErrorEquals(error, MessageKey.PASSWORD_CHARACTERS_ERROR, "[a-zA-Z]+");
}
use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.
the class ValidationServiceTest method shouldAcceptValidPassword.
@Test
public void shouldAcceptValidPassword() {
// given/when
ValidationResult error = validationService.validatePassword("safePass", "some_user");
// then
assertThat(error.hasError(), equalTo(false));
}
use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.
the class ValidationServiceTest method shouldRejectTooShortPassword.
@Test
public void shouldRejectTooShortPassword() {
// given/when
ValidationResult error = validationService.validatePassword("ab", "tester");
// then
assertErrorEquals(error, MessageKey.INVALID_PASSWORD_LENGTH);
}
use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.
the class PasswordRegisterExecutorTest method shouldCheckPasswordValidity.
@Test
public void shouldCheckPasswordValidity() {
// given
String password = "myPass";
String name = "player040";
given(validationService.validatePassword(password, name)).willReturn(new ValidationResult());
Player player = mockPlayerWithName(name);
PasswordRegisterParams params = PasswordRegisterParams.of(player, password, null);
// when
boolean result = executor.isRegistrationAdmitted(params);
// then
assertThat(result, equalTo(true));
verify(validationService).validatePassword(password, name);
}
Aggregations