Search in sources :

Example 21 with ValidationResult

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

the class ChangePasswordAdminCommandTest method shouldUpdatePasswordOfOfflineUser.

@Test
public void shouldUpdatePasswordOfOfflineUser() {
    // given
    CommandSender sender = mock(CommandSender.class);
    String player = "my_user12";
    String password = "passPass";
    given(playerCache.isAuthenticated(player)).willReturn(false);
    given(dataSource.isAuthAvailable(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(true);
    // when
    command.executeCommand(sender, Arrays.asList(player, password));
    runOptionallyAsyncTask(bukkitService);
    // then
    verify(validationService).validatePassword(password, player);
    verify(service).send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS);
    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 22 with ValidationResult

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

the class ValidationServiceTest method shouldRejectPasswordNotMatchingPattern.

@Test
public void shouldRejectPasswordNotMatchingPattern() {
    // given/when
    // service mock returns pattern a-zA-Z -> numbers should not be accepted
    ValidationResult error = validationService.validatePassword("invalid1234", "myPlayer");
    // then
    assertErrorEquals(error, MessageKey.PASSWORD_CHARACTERS_ERROR, "[a-zA-Z]+");
}
Also used : ValidationResult(fr.xephi.authme.service.ValidationService.ValidationResult) Test(org.junit.Test)

Example 23 with ValidationResult

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

the class ValidationServiceTest method shouldAcceptValidPassword.

@Test
public void shouldAcceptValidPassword() {
    // given/when
    ValidationResult error = validationService.validatePassword("safePass", "some_user");
    // then
    assertThat(error.hasError(), equalTo(false));
}
Also used : ValidationResult(fr.xephi.authme.service.ValidationService.ValidationResult) Test(org.junit.Test)

Example 24 with ValidationResult

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

the class ValidationServiceTest method shouldRejectTooShortPassword.

@Test
public void shouldRejectTooShortPassword() {
    // given/when
    ValidationResult error = validationService.validatePassword("ab", "tester");
    // then
    assertErrorEquals(error, MessageKey.INVALID_PASSWORD_LENGTH);
}
Also used : ValidationResult(fr.xephi.authme.service.ValidationService.ValidationResult) Test(org.junit.Test)

Example 25 with ValidationResult

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

the class PasswordRegisterExecutorTest method shouldCheckPasswordValidity.

@Test
public void shouldCheckPasswordValidity() {
    // given
    String password = "myPass";
    String name = "player040";
    given(validationService.validatePassword(password, name)).willReturn(new ValidationResult());
    Player player = mockPlayerWithName(name);
    PasswordRegisterParams params = PasswordRegisterParams.of(player, password, null);
    // when
    boolean result = executor.isRegistrationAdmitted(params);
    // then
    assertThat(result, equalTo(true));
    verify(validationService).validatePassword(password, name);
}
Also used : Player(org.bukkit.entity.Player) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ValidationResult(fr.xephi.authme.service.ValidationService.ValidationResult) 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