use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.
the class RegisterAdminCommandTest method shouldRegisterOfflinePlayer.
@Test
public void shouldRegisterOfflinePlayer() {
// given
String user = "someone";
String password = "Al1O3P49S5%";
given(validationService.validatePassword(password, user)).willReturn(new ValidationResult());
given(dataSource.isAuthAvailable(user)).willReturn(false);
given(dataSource.saveAuth(any(PlayerAuth.class))).willReturn(true);
HashedPassword hashedPassword = new HashedPassword("$aea2345EW235dfsa@#R%987048");
given(passwordSecurity.computeHash(password, user)).willReturn(hashedPassword);
given(bukkitService.getPlayerExact(user)).willReturn(null);
CommandSender sender = mock(CommandSender.class);
// when
command.executeCommand(sender, Arrays.asList(user, password));
TestHelper.runOptionallyAsyncTask(bukkitService);
// then
verify(validationService).validatePassword(password, user);
verify(commandService).send(sender, MessageKey.REGISTER_SUCCESS);
ArgumentCaptor<PlayerAuth> captor = ArgumentCaptor.forClass(PlayerAuth.class);
verify(dataSource).saveAuth(captor.capture());
assertAuthHasInfo(captor.getValue(), user, hashedPassword);
verify(dataSource).setUnlogged(user);
}
use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.
the class RegisterAdminCommandTest method shouldHandleSavingError.
@Test
public void shouldHandleSavingError() {
// given
String user = "test-test";
String password = "afdjhfkt";
given(validationService.validatePassword(password, user)).willReturn(new ValidationResult());
given(dataSource.isAuthAvailable(user)).willReturn(false);
given(dataSource.saveAuth(any(PlayerAuth.class))).willReturn(false);
HashedPassword hashedPassword = new HashedPassword("235sdf4w5udsgf");
given(passwordSecurity.computeHash(password, user)).willReturn(hashedPassword);
CommandSender sender = mock(CommandSender.class);
// when
command.executeCommand(sender, Arrays.asList(user, password));
TestHelper.runOptionallyAsyncTask(bukkitService);
// then
verify(validationService).validatePassword(password, user);
verify(commandService).send(sender, MessageKey.ERROR);
ArgumentCaptor<PlayerAuth> captor = ArgumentCaptor.forClass(PlayerAuth.class);
verify(dataSource).saveAuth(captor.capture());
assertAuthHasInfo(captor.getValue(), user, hashedPassword);
}
use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.
the class RegisterAdminCommandTest method shouldRegisterOnlinePlayer.
@Test
public void shouldRegisterOnlinePlayer() {
// given
String user = "someone";
String password = "Al1O3P49S5%";
given(validationService.validatePassword(password, user)).willReturn(new ValidationResult());
given(dataSource.isAuthAvailable(user)).willReturn(false);
given(dataSource.saveAuth(any(PlayerAuth.class))).willReturn(true);
HashedPassword hashedPassword = new HashedPassword("$aea2345EW235dfsa@#R%987048");
given(passwordSecurity.computeHash(password, user)).willReturn(hashedPassword);
Player player = mock(Player.class);
given(bukkitService.getPlayerExact(user)).willReturn(player);
String kickForAdminRegister = "Admin registered you -- log in again";
given(commandService.retrieveSingleMessage(MessageKey.KICK_FOR_ADMIN_REGISTER)).willReturn(kickForAdminRegister);
CommandSender sender = mock(CommandSender.class);
// when
command.executeCommand(sender, Arrays.asList(user, password));
TestHelper.runOptionallyAsyncTask(bukkitService);
runSyncTaskFromOptionallyAsyncTask(bukkitService);
// then
verify(validationService).validatePassword(password, user);
verify(commandService).send(sender, MessageKey.REGISTER_SUCCESS);
ArgumentCaptor<PlayerAuth> captor = ArgumentCaptor.forClass(PlayerAuth.class);
verify(dataSource).saveAuth(captor.capture());
assertAuthHasInfo(captor.getValue(), user, hashedPassword);
verify(dataSource).setUnlogged(user);
verify(player).kickPlayer(kickForAdminRegister);
}
use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.
the class ValidationServiceTest method shouldRejectPasswordSameAsUsername.
@Test
public void shouldRejectPasswordSameAsUsername() {
// given/when
ValidationResult error = validationService.validatePassword("bobby", "Bobby");
// then
assertErrorEquals(error, MessageKey.PASSWORD_IS_USERNAME_ERROR);
}
use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.
the class ValidationServiceTest method shouldRejectTooLongPassword.
@Test
public void shouldRejectTooLongPassword() {
// given/when
ValidationResult error = validationService.validatePassword(Strings.repeat("a", 30), "player");
// then
assertErrorEquals(error, MessageKey.INVALID_PASSWORD_LENGTH);
}
Aggregations