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"));
}
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"));
}
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")));
}
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()));
}
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));
}
Aggregations