Search in sources :

Example 1 with ValidationResult

use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.

the class InputValidator method validatePassword.

private void validatePassword(CommandSender sender, String password) {
    ValidationResult validationResult = validationService.validatePassword(password, "");
    sender.sendMessage("Validation of password '" + password + "' returned:");
    if (validationResult.hasError()) {
        messages.send(sender, validationResult.getMessageKey(), validationResult.getArgs());
    } else {
        sender.sendMessage(ChatColor.DARK_GREEN + "Valid password!");
    }
}
Also used : ValidationResult(fr.xephi.authme.service.ValidationService.ValidationResult)

Example 2 with ValidationResult

use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.

the class PasswordRegisterExecutorTest method shouldDetectInvalidPasswordAndInformPlayer.

@Test
public void shouldDetectInvalidPasswordAndInformPlayer() {
    // given
    String password = "myPass";
    String name = "player040";
    given(validationService.validatePassword(password, name)).willReturn(new ValidationResult(MessageKey.PASSWORD_CHARACTERS_ERROR, "[a-z]"));
    Player player = mockPlayerWithName(name);
    PasswordRegisterParams params = PasswordRegisterParams.of(player, password, null);
    // when
    boolean result = executor.isRegistrationAdmitted(params);
    // then
    assertThat(result, equalTo(false));
    verify(validationService).validatePassword(password, name);
    verify(commonService).send(player, MessageKey.PASSWORD_CHARACTERS_ERROR, "[a-z]");
}
Also used : Player(org.bukkit.entity.Player) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ValidationResult(fr.xephi.authme.service.ValidationService.ValidationResult) Test(org.junit.Test)

Example 3 with ValidationResult

use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.

the class ChangePasswordCommandTest method shouldRejectInvalidPassword.

@Test
public void shouldRejectInvalidPassword() {
    // given
    CommandSender sender = initPlayerWithName("abc12", true);
    String password = "newPW";
    given(validationService.validatePassword(password, "abc12")).willReturn(new ValidationResult(MessageKey.INVALID_PASSWORD_LENGTH));
    // when
    command.executeCommand(sender, Arrays.asList("tester", password));
    // then
    verify(validationService).validatePassword(password, "abc12");
    verify(commandService).send(sender, MessageKey.INVALID_PASSWORD_LENGTH, new String[0]);
}
Also used : CommandSender(org.bukkit.command.CommandSender) BlockCommandSender(org.bukkit.command.BlockCommandSender) Matchers.containsString(org.hamcrest.Matchers.containsString) ValidationResult(fr.xephi.authme.service.ValidationService.ValidationResult) Test(org.junit.Test)

Example 4 with ValidationResult

use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.

the class ChangePasswordCommandTest method shouldForwardTheDataForValidPassword.

@Test
public void shouldForwardTheDataForValidPassword() {
    // given
    String oldPass = "oldpass";
    String newPass = "abc123";
    Player player = initPlayerWithName("parker", true);
    given(validationService.validatePassword("abc123", "parker")).willReturn(new ValidationResult());
    // when
    command.executeCommand(player, Arrays.asList(oldPass, newPass));
    // then
    verify(validationService).validatePassword(newPass, "parker");
    verify(commandService, never()).send(eq(player), any(MessageKey.class));
    verify(management).performPasswordChange(player, oldPass, newPass);
}
Also used : Player(org.bukkit.entity.Player) MessageKey(fr.xephi.authme.message.MessageKey) Matchers.containsString(org.hamcrest.Matchers.containsString) ValidationResult(fr.xephi.authme.service.ValidationService.ValidationResult) Test(org.junit.Test)

Example 5 with ValidationResult

use of fr.xephi.authme.service.ValidationService.ValidationResult in project AuthMeReloaded by AuthMe.

the class RegisterAdminCommandTest method shouldRejectAlreadyRegisteredAccount.

@Test
public void shouldRejectAlreadyRegisteredAccount() {
    // given
    String user = "my_name55";
    String password = "@some-pass@";
    given(validationService.validatePassword(password, user)).willReturn(new ValidationResult());
    given(dataSource.isAuthAvailable(user)).willReturn(true);
    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.NAME_ALREADY_REGISTERED);
    verify(dataSource, never()).saveAuth(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)

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