Search in sources :

Example 11 with ValidationResult

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);
}
Also used : ValidationResult(fr.xephi.authme.service.ValidationService.ValidationResult) Test(org.junit.Test)

Example 12 with ValidationResult

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);
}
Also used : CommandSender(org.bukkit.command.CommandSender) ValidationResult(fr.xephi.authme.service.ValidationService.ValidationResult) Test(org.junit.Test)

Example 13 with ValidationResult

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);
}
Also used : CommandSender(org.bukkit.command.CommandSender) ValidationResult(fr.xephi.authme.service.ValidationService.ValidationResult) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Example 14 with ValidationResult

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));
}
Also used : CommandSender(org.bukkit.command.CommandSender) ValidationResult(fr.xephi.authme.service.ValidationService.ValidationResult) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 15 with ValidationResult

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);
}
Also used : ValidationResult(fr.xephi.authme.service.ValidationService.ValidationResult)

Aggregations

ValidationResult (fr.xephi.authme.service.ValidationService.ValidationResult)25 Test (org.junit.Test)20 CommandSender (org.bukkit.command.CommandSender)11 HashedPassword (fr.xephi.authme.security.crypts.HashedPassword)8 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)6 Player (org.bukkit.entity.Player)5 Matchers.containsString (org.hamcrest.Matchers.containsString)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 MessageKey (fr.xephi.authme.message.MessageKey)1 BlockCommandSender (org.bukkit.command.BlockCommandSender)1