use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class AsyncAddEmailTest method shouldNotAddMailIfPlayerAlreadyHasEmail.
@Test
public void shouldNotAddMailIfPlayerAlreadyHasEmail() {
// given
given(player.getName()).willReturn("my_Player");
given(playerCache.isAuthenticated("my_player")).willReturn(true);
PlayerAuth auth = mock(PlayerAuth.class);
given(auth.getEmail()).willReturn("another@mail.tld");
given(playerCache.getAuth("my_player")).willReturn(auth);
// when
asyncAddEmail.addEmail(player, "some.mail@example.org");
// then
verify(service).send(player, MessageKey.USAGE_CHANGE_EMAIL);
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class AsynchronousLoginTest method shouldNotForceLoginUserWithAlreadyOnlineIp.
@Test
public void shouldNotForceLoginUserWithAlreadyOnlineIp() {
// given
String name = "oscar";
String ip = "127.0.12.245";
Player player = mockPlayer(name);
TestHelper.mockPlayerIp(player, ip);
given(playerCache.isAuthenticated(name)).willReturn(false);
PlayerAuth auth = PlayerAuth.builder().name(name).build();
given(dataSource.getAuth(name)).willReturn(auth);
given(commonService.getProperty(DatabaseSettings.MYSQL_COL_GROUP)).willReturn("");
doReturn(true).when(asynchronousLogin).hasReachedMaxLoggedInPlayersForIp(any(Player.class), anyString());
// when
asynchronousLogin.forceLogin(player);
// then
verify(playerCache, only()).isAuthenticated(name);
verify(commonService).send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
verify(dataSource, only()).getAuth(name);
verify(asynchronousLogin).hasReachedMaxLoggedInPlayersForIp(player, ip);
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class AsynchronousLoginTest method shouldNotForceLoginForCanceledEvent.
@Test
public void shouldNotForceLoginForCanceledEvent() {
// given
String name = "oscar";
String ip = "127.0.12.245";
Player player = mockPlayer(name);
TestHelper.mockPlayerIp(player, ip);
given(playerCache.isAuthenticated(name)).willReturn(false);
PlayerAuth auth = PlayerAuth.builder().name(name).build();
given(dataSource.getAuth(name)).willReturn(auth);
given(commonService.getProperty(DatabaseSettings.MYSQL_COL_GROUP)).willReturn("");
given(commonService.getProperty(PluginSettings.USE_ASYNC_TASKS)).willReturn(true);
doReturn(false).when(asynchronousLogin).hasReachedMaxLoggedInPlayersForIp(any(Player.class), anyString());
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
((AuthMeAsyncPreLoginEvent) invocation.getArgument(0)).setCanLogin(false);
return null;
}
}).when(bukkitService).callEvent(any(AuthMeAsyncPreLoginEvent.class));
// when
asynchronousLogin.forceLogin(player);
// then
verify(playerCache, only()).isAuthenticated(name);
verify(dataSource, only()).getAuth(name);
verify(asynchronousLogin).hasReachedMaxLoggedInPlayersForIp(player, ip);
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class AsyncChangeEmailTest method shouldRejectAlreadyUsedEmail.
@Test
public void shouldRejectAlreadyUsedEmail() {
// given
String newEmail = "new@example.com";
given(player.getName()).willReturn("Username");
given(playerCache.isAuthenticated("username")).willReturn(true);
PlayerAuth auth = authWithMail("old@example.com");
given(playerCache.getAuth("username")).willReturn(auth);
given(validationService.validateEmail(newEmail)).willReturn(true);
given(validationService.isEmailFreeForRegistration(newEmail, player)).willReturn(false);
// when
process.changeEmail(player, "old@example.com", newEmail);
// then
verify(dataSource, never()).updateEmail(any(PlayerAuth.class));
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
verify(service).send(player, MessageKey.EMAIL_ALREADY_USED_ERROR);
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class AsyncChangeEmailTest method shouldShowErrorIfSaveFails.
@Test
public void shouldShowErrorIfSaveFails() {
// given
String newEmail = "new@mail.tld";
given(player.getName()).willReturn("Bobby");
given(playerCache.isAuthenticated("bobby")).willReturn(true);
PlayerAuth auth = authWithMail("old@mail.tld");
given(playerCache.getAuth("bobby")).willReturn(auth);
given(dataSource.updateEmail(auth)).willReturn(false);
given(validationService.validateEmail(newEmail)).willReturn(true);
given(validationService.isEmailFreeForRegistration(newEmail, player)).willReturn(true);
// when
process.changeEmail(player, "old@mail.tld", newEmail);
// then
verify(dataSource).updateEmail(auth);
verify(playerCache, never()).updatePlayer(auth);
verify(service).send(player, MessageKey.ERROR);
}
Aggregations