use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.
the class ValidationServiceTest method shouldRejectUnsafePassword.
@Test
public void shouldRejectUnsafePassword() {
// given/when
ValidationResult error = validationService.validatePassword("unsafe", "playertest");
// then
assertErrorEquals(error, MessageKey.PASSWORD_UNSAFE_ERROR);
}
use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.
the class ChangePasswordAdminCommandTest method shouldRejectInvalidPassword.
@Test
public void shouldRejectInvalidPassword() {
// given
CommandSender sender = mock(CommandSender.class);
given(validationService.validatePassword("Bobby", "bobby")).willReturn(new ValidationResult(MessageKey.PASSWORD_IS_USERNAME_ERROR));
// when
command.executeCommand(sender, Arrays.asList("bobby", "Bobby"));
// then
verify(validationService).validatePassword("Bobby", "bobby");
verify(service).send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR, new String[0]);
verifyZeroInteractions(dataSource);
}
use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.
the class ChangePasswordAdminCommandTest method shouldReportWhenSaveFailed.
@Test
public void shouldReportWhenSaveFailed() {
// given
CommandSender sender = mock(CommandSender.class);
String player = "my_user12";
String password = "passPass";
given(playerCache.isAuthenticated(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(false);
// when
command.executeCommand(sender, Arrays.asList(player, password));
runOptionallyAsyncTask(bukkitService);
// then
verify(validationService).validatePassword(password, player);
verify(service).send(sender, MessageKey.ERROR);
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 ChangePasswordAdminCommandTest method shouldRejectCommandForUnknownUser.
@Test
public void shouldRejectCommandForUnknownUser() {
// given
CommandSender sender = mock(CommandSender.class);
String player = "player";
String password = "password";
given(playerCache.isAuthenticated(player)).willReturn(false);
given(validationService.validatePassword(password, player)).willReturn(new ValidationResult());
// when
command.executeCommand(sender, Arrays.asList(player, password));
runOptionallyAsyncTask(bukkitService);
// then
verify(service).send(sender, MessageKey.UNKNOWN_USER);
verify(dataSource, never()).updatePassword(any(PlayerAuth.class));
}
use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.
the class ChangePasswordCommand method runCommand.
@Override
public void runCommand(Player player, List<String> arguments) {
String oldPassword = arguments.get(0);
String newPassword = arguments.get(1);
String name = player.getName().toLowerCase();
if (!playerCache.isAuthenticated(name)) {
commonService.send(player, MessageKey.NOT_LOGGED_IN);
return;
}
// Make sure the password is allowed
ValidationResult passwordValidation = validationService.validatePassword(newPassword, name);
if (passwordValidation.hasError()) {
commonService.send(player, passwordValidation.getMessageKey(), passwordValidation.getArgs());
return;
}
management.performPasswordChange(player, oldPassword, newPassword);
}
Aggregations