Search in sources :

Example 46 with PlayerAuth

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

the class LastLoginCommandTest method shouldDisplayLastLoginOfUser.

@Test
public void shouldDisplayLastLoginOfUser() {
    // given
    String player = "SomePlayer";
    long lastLogin = System.currentTimeMillis() - (412 * DAY_IN_MSEC + 10 * HOUR_IN_MSEC - 9000);
    PlayerAuth auth = mock(PlayerAuth.class);
    given(auth.getLastLogin()).willReturn(lastLogin);
    given(auth.getIp()).willReturn("123.45.66.77");
    given(dataSource.getAuth(player)).willReturn(auth);
    CommandSender sender = mock(CommandSender.class);
    // when
    command.executeCommand(sender, Collections.singletonList(player));
    // then
    verify(dataSource).getAuth(player);
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(sender, times(3)).sendMessage(captor.capture());
    String lastLoginString = new Date(lastLogin).toString();
    assertThat(captor.getAllValues().get(0), allOf(containsString(player), containsString(lastLoginString)));
    assertThat(captor.getAllValues().get(1), containsString("412 days 9 hours"));
    assertThat(captor.getAllValues().get(2), containsString("123.45.66.77"));
}
Also used : CommandSender(org.bukkit.command.CommandSender) Matchers.containsString(org.hamcrest.Matchers.containsString) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Date(java.util.Date) Test(org.junit.Test)

Example 47 with PlayerAuth

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

the class LastLoginCommandTest method shouldDisplayLastLoginOfCommandSender.

@Test
public void shouldDisplayLastLoginOfCommandSender() {
    // given
    String name = "CommandSender";
    CommandSender sender = mock(CommandSender.class);
    given(sender.getName()).willReturn(name);
    long lastLogin = System.currentTimeMillis() - (412 * DAY_IN_MSEC + 10 * HOUR_IN_MSEC - 9000);
    PlayerAuth auth = mock(PlayerAuth.class);
    given(auth.getLastLogin()).willReturn(lastLogin);
    given(auth.getIp()).willReturn("123.45.66.77");
    given(dataSource.getAuth(name)).willReturn(auth);
    // when
    command.executeCommand(sender, Collections.emptyList());
    // then
    verify(dataSource).getAuth(name);
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(sender, times(3)).sendMessage(captor.capture());
    String lastLoginString = new Date(lastLogin).toString();
    assertThat(captor.getAllValues().get(0), allOf(containsString(name), containsString(lastLoginString)));
    assertThat(captor.getAllValues().get(1), containsString("412 days 9 hours"));
    assertThat(captor.getAllValues().get(2), containsString("123.45.66.77"));
}
Also used : CommandSender(org.bukkit.command.CommandSender) Matchers.containsString(org.hamcrest.Matchers.containsString) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Date(java.util.Date) Test(org.junit.Test)

Example 48 with PlayerAuth

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

the class PurgeLastPositionCommandTest method shouldResetAllLastPositions.

@Test
public void shouldResetAllLastPositions() {
    // given
    PlayerAuth auth1 = mock(PlayerAuth.class);
    PlayerAuth auth2 = mock(PlayerAuth.class);
    PlayerAuth auth3 = mock(PlayerAuth.class);
    given(dataSource.getAllAuths()).willReturn(Arrays.asList(auth1, auth2, auth3));
    CommandSender sender = mock(CommandSender.class);
    // when
    command.executeCommand(sender, Collections.singletonList("*"));
    // then
    verify(dataSource).getAllAuths();
    verifyPositionWasReset(auth1);
    verifyPositionWasReset(auth2);
    verifyPositionWasReset(auth3);
    verify(sender).sendMessage(argThat(containsString("last position locations are now reset")));
}
Also used : CommandSender(org.bukkit.command.CommandSender) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 49 with PlayerAuth

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

the class AuthMeApiTest method shouldGetLastLocation.

@Test
public void shouldGetLastLocation() {
    // given
    String name = "Gary";
    Player player = mockPlayerWithName(name);
    PlayerAuth auth = PlayerAuth.builder().name(name).locWorld("world").locX(12.4).locY(24.6).locZ(-438.2).locYaw(3.41f).locPitch(0.29f).build();
    given(playerCache.getAuth(name)).willReturn(auth);
    Server server = mock(Server.class);
    ReflectionTestUtils.setField(Bukkit.class, null, "server", server);
    World world = mock(World.class);
    given(server.getWorld(auth.getWorld())).willReturn(world);
    // when
    Location result = api.getLastLocation(player);
    // then
    assertThat(result, not(nullValue()));
    assertThat(result.getX(), equalTo(auth.getQuitLocX()));
    assertThat(result.getY(), equalTo(auth.getQuitLocY()));
    assertThat(result.getZ(), equalTo(auth.getQuitLocZ()));
    assertThat(result.getWorld(), equalTo(world));
    assertThat(result.getYaw(), equalTo(auth.getYaw()));
    assertThat(result.getPitch(), equalTo(auth.getPitch()));
}
Also used : Player(org.bukkit.entity.Player) Server(org.bukkit.Server) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) World(org.bukkit.World) Location(org.bukkit.Location) Test(org.junit.Test)

Example 50 with PlayerAuth

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

the class LoginSecurityConverterTest method shouldConvertFromMySql.

@Test
public void shouldConvertFromMySql() throws IOException, SQLException {
    // given
    Connection connection = initializeMySqlTable();
    CommandSender sender = mock(CommandSender.class);
    // when
    converter.performConversion(sender, connection);
    // then
    ArgumentCaptor<PlayerAuth> captor = ArgumentCaptor.forClass(PlayerAuth.class);
    verify(dataSource, times(3)).saveAuth(captor.capture());
    assertThat(captor.getAllValues().get(0).getNickname(), equalTo("player1"));
    assertThat(captor.getAllValues().get(0).getRealName(), equalTo("Player1"));
    assertThat(captor.getAllValues().get(0).getLastLogin(), equalTo(1494242093000L));
    assertThat(captor.getAllValues().get(0).getPassword(), equalToHash("$2a$10$E1Ri7XKeIIBv4qVaiPplgepT7QH9xGFh3hbHfcmCjq7hiW.UBTiGK"));
    assertThat(captor.getAllValues().get(0).getIp(), equalTo("127.0.0.1"));
    assertThat(captor.getAllValues().get(1).getNickname(), equalTo("player2"));
    assertThat(captor.getAllValues().get(1).getLastLogin(), equalTo(1489317753000L));
    assertThat(captor.getAllValues().get(1).getIp(), equalTo("127.4.5.6"));
    assertThat(captor.getAllValues().get(2).getRealName(), equalTo("Player3"));
    assertThat(captor.getAllValues().get(2).getPassword(), equalToHash("$2a$10$WFui8KSXMLDOVXKFpCLyPukPi4M82w1cv/rNojsAnwJjba3pp8sba"));
    assertThat(captor.getAllValues().get(2), hasAuthLocation(14.24, 67.99, -12.83, "hubb", -10f, 185f));
}
Also used : Connection(java.sql.Connection) CommandSender(org.bukkit.command.CommandSender) 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