Search in sources :

Example 21 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class AsyncAddEmailTest method shouldAddEmail.

@Test
public void shouldAddEmail() {
    // given
    String email = "my.mail@example.org";
    given(player.getName()).willReturn("testEr");
    given(playerCache.isAuthenticated("tester")).willReturn(true);
    PlayerAuth auth = mock(PlayerAuth.class);
    given(auth.getEmail()).willReturn(null);
    given(playerCache.getAuth("tester")).willReturn(auth);
    given(dataSource.updateEmail(any(PlayerAuth.class))).willReturn(true);
    given(validationService.validateEmail(email)).willReturn(true);
    given(validationService.isEmailFreeForRegistration(email, player)).willReturn(true);
    // when
    asyncAddEmail.addEmail(player, email);
    // then
    verify(dataSource).updateEmail(auth);
    verify(service).send(player, MessageKey.EMAIL_ADDED_SUCCESS);
    verify(auth).setEmail(email);
    verify(playerCache).updatePlayer(auth);
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 22 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class AsyncAddEmailTest method shouldNotAddMailIfItIsInvalid.

@Test
public void shouldNotAddMailIfItIsInvalid() {
    // given
    String email = "invalid_mail";
    given(player.getName()).willReturn("my_Player");
    given(playerCache.isAuthenticated("my_player")).willReturn(true);
    PlayerAuth auth = mock(PlayerAuth.class);
    given(auth.getEmail()).willReturn(null);
    given(playerCache.getAuth("my_player")).willReturn(auth);
    given(validationService.validateEmail(email)).willReturn(false);
    // when
    asyncAddEmail.addEmail(player, email);
    // then
    verify(service).send(player, MessageKey.INVALID_EMAIL);
    verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 23 with PlayerAuth

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));
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 24 with PlayerAuth

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);
}
Also used : Player(org.bukkit.entity.Player) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 25 with PlayerAuth

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);
}
Also used : Player(org.bukkit.entity.Player) AuthMeAsyncPreLoginEvent(fr.xephi.authme.events.AuthMeAsyncPreLoginEvent) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Aggregations

PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)102 Test (org.junit.Test)65 Player (org.bukkit.entity.Player)33 HashedPassword (fr.xephi.authme.security.crypts.HashedPassword)21 CommandSender (org.bukkit.command.CommandSender)16 Location (org.bukkit.Location)14 LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)9 IOException (java.io.IOException)7 World (org.bukkit.World)7 BufferedReader (java.io.BufferedReader)6 FileReader (java.io.FileReader)6 ArrayList (java.util.ArrayList)5 ValidationResult (fr.xephi.authme.service.ValidationService.ValidationResult)4 Connection (java.sql.Connection)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 AuthMeMatchers.hasAuthLocation (fr.xephi.authme.AuthMeMatchers.hasAuthLocation)3 File (java.io.File)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3