Search in sources :

Example 1 with ValidationService

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

Example 2 with ValidationService

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

Aggregations

ValidationService (fr.xephi.authme.service.ValidationService)2 Player (org.bukkit.entity.Player)2 Test (org.junit.Test)2 HashedPassword (fr.xephi.authme.security.crypts.HashedPassword)1