Search in sources :

Example 56 with PlayerAuth

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

the class CrazyLoginConverter method migrateAccount.

/**
     * Moves an account from CrazyLogin to the AuthMe database.
     *
     * @param line line read from the CrazyLogin file (one account)
     */
private void migrateAccount(String line) {
    String[] args = line.split("\\|");
    if (args.length < 2 || "name".equalsIgnoreCase(args[0])) {
        return;
    }
    String playerName = args[0];
    String password = args[1];
    if (password != null) {
        PlayerAuth auth = PlayerAuth.builder().name(playerName.toLowerCase()).realName(playerName).password(password, null).build();
        database.saveAuth(auth);
    }
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 57 with PlayerAuth

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

the class NewAPITest 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));
}
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 58 with PlayerAuth

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

the class AbstractDataSourceConverterTest method shouldConvertAndSkipExistingPlayers.

@Test
public void shouldConvertAndSkipExistingPlayers() {
    // given
    DataSource source = mock(DataSource.class);
    DataSource destination = mock(DataSource.class);
    DataSourceType destinationType = DataSourceType.MYSQL;
    given(destination.getType()).willReturn(destinationType);
    List<PlayerAuth> auths = Arrays.asList(mockAuthWithName("Steven"), mockAuthWithName("bobby"), mockAuthWithName("Jack"));
    given(source.getAllAuths()).willReturn(auths);
    given(destination.isAuthAvailable(auths.get(0).getNickname())).willReturn(true);
    Converter converter = new DataSourceConverterTestImpl<>(source, destination, destinationType);
    CommandSender sender = mock(CommandSender.class);
    // when
    converter.execute(sender);
    // then
    verify(destination).getType();
    verify(destination, times(3)).isAuthAvailable(anyString());
    verify(destination, times(2)).saveAuth(any(PlayerAuth.class));
    verify(destination, times(2)).updateQuitLoc(any(PlayerAuth.class));
    verifyNoMoreInteractions(destination);
    verify(sender).sendMessage(argThat(containsString(auths.get(0).getNickname())));
    verify(sender).sendMessage(argThat(containsString("successfully converted")));
}
Also used : DataSourceType(fr.xephi.authme.datasource.DataSourceType) CommandSender(org.bukkit.command.CommandSender) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) DataSource(fr.xephi.authme.datasource.DataSource) Test(org.junit.Test)

Example 59 with PlayerAuth

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

the class CrazyLoginConverterTest method shouldImportUsers.

@Test
public void shouldImportUsers() {
    // given
    given(settings.getProperty(ConverterSettings.CRAZYLOGIN_FILE_NAME)).willReturn("crazylogin.db");
    CommandSender sender = mock(CommandSender.class);
    // when
    crazyLoginConverter.execute(sender);
    // then
    ArgumentCaptor<PlayerAuth> authCaptor = ArgumentCaptor.forClass(PlayerAuth.class);
    verify(dataSource, times(2)).saveAuth(authCaptor.capture());
    List<PlayerAuth> savedAuths = authCaptor.getAllValues();
    assertNameAndRealName(savedAuths.get(0), "qotato", "qotaTo");
    assertThat(savedAuths.get(0).getPassword(), equalToHash("8267663ab198a96437b9f455429a2c1b6c943111613c217bf2703c14d08a309d34e510ddb5549507b1500759dbcf9d4a99bc765ff37b32bd31adbb1e92e74ac5"));
    assertNameAndRealName(savedAuths.get(1), "bobby", "Bobby");
    assertThat(savedAuths.get(1).getPassword(), equalToHash("ad50dbc841e6321210530801f5219a5ffb4c7c41f11878d465374a4b8db2965c50f69b6098918a58e4adea312e3633c7724b15e24a217009e6fa2b3c299d55f2"));
}
Also used : CommandSender(org.bukkit.command.CommandSender) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 60 with PlayerAuth

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

the class ForceFlatToSqliteTest method shouldConvertToSqlite.

@Test
public void shouldConvertToSqlite() {
    // given
    DataSource dataSource = mock(DataSource.class);
    given(dataSource.getType()).willReturn(DataSourceType.MYSQL);
    ForceFlatToSqlite converter = new ForceFlatToSqlite(flatFile, dataSource);
    // when
    converter.execute(null);
    // then
    ArgumentCaptor<PlayerAuth> authCaptor = ArgumentCaptor.forClass(PlayerAuth.class);
    verify(dataSource, times(7)).saveAuth(authCaptor.capture());
    List<PlayerAuth> auths = authCaptor.getAllValues();
    assertThat(auths, hasItem(hasAuthBasicData("bobby", "Player", "your@email.com", "123.45.67.89")));
    assertThat(auths, hasItem(hasAuthLocation(1.05, 2.1, 4.2, "world", 0, 0)));
    assertThat(auths, hasItem(hasAuthBasicData("user", "Player", "user@example.org", "34.56.78.90")));
    assertThat(auths, hasItem(hasAuthLocation(124.1, 76.3, -127.8, "nether", 0, 0)));
    assertThat(auths, hasItem(hasAuthBasicData("eightfields", "Player", "your@email.com", "6.6.6.66")));
    assertThat(auths, hasItem(hasAuthLocation(8.8, 17.6, 26.4, "eightworld", 0, 0)));
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) DataSource(fr.xephi.authme.datasource.DataSource) 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