Search in sources :

Example 6 with ValidationResult

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

Example 7 with ValidationResult

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

Example 8 with ValidationResult

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

Example 9 with ValidationResult

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

Example 10 with ValidationResult

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);
}
Also used : 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