use of fr.xephi.authme.service.ValidationService in project AuthMeReloaded by AuthMe.
the class SetPasswordCommandTest method shouldChangePassword.
@Test
public void shouldChangePassword() {
// given
Player player = mock(Player.class);
String name = "Jerry";
given(player.getName()).willReturn(name);
given(recoveryService.canChangePassword(player)).willReturn(true);
HashedPassword hashedPassword = passwordSecurity.computeHash("abc123", name);
given(passwordSecurity.computeHash("abc123", name)).willReturn(hashedPassword);
given(validationService.validatePassword("abc123", name)).willReturn(new ValidationService.ValidationResult());
// when
command.runCommand(player, Collections.singletonList("abc123"));
// then
verify(validationService).validatePassword("abc123", name);
verify(dataSource).updatePassword(name, hashedPassword);
verify(commonService).send(player, MessageKey.PASSWORD_CHANGED_SUCCESS);
}
use of fr.xephi.authme.service.ValidationService in project AuthMeReloaded by AuthMe.
the class SetPasswordCommandTest method shouldRejectInvalidPassword.
@Test
public void shouldRejectInvalidPassword() {
// given
Player player = mock(Player.class);
String name = "Morgan";
given(player.getName()).willReturn(name);
String password = "newPW";
given(validationService.validatePassword(password, name)).willReturn(new ValidationService.ValidationResult(MessageKey.INVALID_PASSWORD_LENGTH));
given(recoveryService.canChangePassword(player)).willReturn(true);
// when
command.executeCommand(player, Collections.singletonList(password));
// then
verify(validationService).validatePassword(password, name);
verify(commonService).send(player, MessageKey.INVALID_PASSWORD_LENGTH, new String[0]);
}
Aggregations