mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-02 23:23:39 +01:00
commit
2486a50236
@ -863,10 +863,10 @@ public class MySQL implements DataSource {
|
|||||||
try (Connection con = getConnection()) {
|
try (Connection con = getConnection()) {
|
||||||
Statement st = con.createStatement();
|
Statement st = con.createStatement();
|
||||||
ResultSet rs = st.executeQuery("SELECT * FROM " + tableName);
|
ResultSet rs = st.executeQuery("SELECT * FROM " + tableName);
|
||||||
PreparedStatement pst = con.prepareStatement("SELECT data FROM xf_user_authenticate WHERE " + col.ID + "=?;");
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
PlayerAuth pAuth = buildAuthFromResultSet(rs);
|
PlayerAuth pAuth = buildAuthFromResultSet(rs);
|
||||||
if (hashAlgorithm == HashAlgorithm.XFBCRYPT) {
|
if (hashAlgorithm == HashAlgorithm.XFBCRYPT) {
|
||||||
|
try (PreparedStatement pst = con.prepareStatement("SELECT data FROM xf_user_authenticate WHERE " + col.ID + "=?;")) {
|
||||||
int id = rs.getInt(col.ID);
|
int id = rs.getInt(col.ID);
|
||||||
pst.setInt(1, id);
|
pst.setInt(1, id);
|
||||||
ResultSet rs2 = pst.executeQuery();
|
ResultSet rs2 = pst.executeQuery();
|
||||||
@ -877,9 +877,9 @@ public class MySQL implements DataSource {
|
|||||||
}
|
}
|
||||||
rs2.close();
|
rs2.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
auths.add(pAuth);
|
auths.add(pAuth);
|
||||||
}
|
}
|
||||||
pst.close();
|
|
||||||
rs.close();
|
rs.close();
|
||||||
st.close();
|
st.close();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
|
@ -145,8 +145,6 @@ public final class Settings {
|
|||||||
denyTabcompleteBeforeLogin = load(RestrictionSettings.DENY_TABCOMPLETE_BEFORE_LOGIN);
|
denyTabcompleteBeforeLogin = load(RestrictionSettings.DENY_TABCOMPLETE_BEFORE_LOGIN);
|
||||||
hideTablistBeforeLogin = load(RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN);
|
hideTablistBeforeLogin = load(RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN);
|
||||||
|
|
||||||
plugin.checkProtocolLib();
|
|
||||||
|
|
||||||
passwordMaxLength = load(SecuritySettings.MAX_PASSWORD_LENGTH);
|
passwordMaxLength = load(SecuritySettings.MAX_PASSWORD_LENGTH);
|
||||||
backupWindowsPath = configFile.getString("BackupSystem.MysqlWindowsPath", "C:\\Program Files\\MySQL\\MySQL Server 5.1\\");
|
backupWindowsPath = configFile.getString("BackupSystem.MysqlWindowsPath", "C:\\Program Files\\MySQL\\MySQL Server 5.1\\");
|
||||||
isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true);
|
isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true);
|
||||||
|
@ -23,13 +23,13 @@ public class Spawn extends CustomConfiguration {
|
|||||||
|
|
||||||
private Spawn() {
|
private Spawn() {
|
||||||
super(new File(Settings.PLUGIN_FOLDER, "spawn.yml"));
|
super(new File(Settings.PLUGIN_FOLDER, "spawn.yml"));
|
||||||
reload();
|
load();
|
||||||
|
save();
|
||||||
|
spawnPriority = Settings.spawnPriority.split(",");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reload() {
|
public static void reload() {
|
||||||
getInstance().load();
|
spawn = new Spawn();
|
||||||
getInstance().save();
|
|
||||||
spawnPriority = Settings.spawnPriority.split(",");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,10 +4,13 @@ import fr.xephi.authme.cache.auth.PlayerAuth;
|
|||||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static fr.xephi.authme.datasource.AuthMeMatchers.equalToHash;
|
import static fr.xephi.authme.datasource.AuthMeMatchers.equalToHash;
|
||||||
import static fr.xephi.authme.datasource.AuthMeMatchers.hasAuthBasicData;
|
import static fr.xephi.authme.datasource.AuthMeMatchers.hasAuthBasicData;
|
||||||
import static fr.xephi.authme.datasource.AuthMeMatchers.hasAuthLocation;
|
import static fr.xephi.authme.datasource.AuthMeMatchers.hasAuthLocation;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
import static org.hamcrest.Matchers.nullValue;
|
import static org.hamcrest.Matchers.nullValue;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
@ -98,13 +101,104 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||||||
// when
|
// when
|
||||||
int userMailCount = dataSource.countAuthsByEmail("user@example.ORG");
|
int userMailCount = dataSource.countAuthsByEmail("user@example.ORG");
|
||||||
int invalidMailCount = dataSource.countAuthsByEmail("not.in.db@example.com");
|
int invalidMailCount = dataSource.countAuthsByEmail("not.in.db@example.com");
|
||||||
dataSource.saveAuth(PlayerAuth.builder().name("Test").email("user@EXAMPLE.org").build());
|
boolean response = dataSource.saveAuth(
|
||||||
|
PlayerAuth.builder().name("Test").email("user@EXAMPLE.org").build());
|
||||||
int newUserCount = dataSource.countAuthsByEmail("user@Example.org");
|
int newUserCount = dataSource.countAuthsByEmail("user@Example.org");
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(userMailCount, equalTo(1));
|
assertThat(userMailCount, equalTo(1));
|
||||||
assertThat(invalidMailCount, equalTo(0));
|
assertThat(invalidMailCount, equalTo(0));
|
||||||
|
assertThat(response, equalTo(true));
|
||||||
assertThat(newUserCount, equalTo(2));
|
assertThat(newUserCount, equalTo(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnAllAuths() {
|
||||||
|
// given
|
||||||
|
DataSource dataSource = getDataSource();
|
||||||
|
|
||||||
|
// when
|
||||||
|
List<PlayerAuth> authList = dataSource.getAllAuths();
|
||||||
|
boolean response = dataSource.saveAuth(
|
||||||
|
PlayerAuth.builder().name("Test").email("user@EXAMPLE.org").build());
|
||||||
|
List<PlayerAuth> newAuthList = dataSource.getAllAuths();
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(response, equalTo(true));
|
||||||
|
assertThat(authList, hasSize(2));
|
||||||
|
assertThat(newAuthList, hasSize(3));
|
||||||
|
boolean hasBobby = false;
|
||||||
|
for (PlayerAuth auth : authList) {
|
||||||
|
if (auth.getNickname().equals("bobby")) {
|
||||||
|
hasBobby = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertThat(hasBobby, equalTo(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldUpdatePassword() {
|
||||||
|
// given
|
||||||
|
DataSource dataSource = getDataSource();
|
||||||
|
HashedPassword newHash = new HashedPassword("new_hash");
|
||||||
|
|
||||||
|
// when
|
||||||
|
boolean response1 = dataSource.updatePassword("user", newHash);
|
||||||
|
boolean response2 = dataSource.updatePassword("non-existent-name", new HashedPassword("sd"));
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(response1 && response2, equalTo(true));
|
||||||
|
assertThat(dataSource.getPassword("user"), equalToHash(newHash));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRemovePlayerAuth() {
|
||||||
|
// given
|
||||||
|
DataSource dataSource = getDataSource();
|
||||||
|
|
||||||
|
// when
|
||||||
|
boolean response1 = dataSource.removeAuth("bobby");
|
||||||
|
boolean response2 = dataSource.removeAuth("does-not-exist");
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(response1 && response2, equalTo(true));
|
||||||
|
assertThat(dataSource.getAuth("bobby"), nullValue());
|
||||||
|
assertThat(dataSource.isAuthAvailable("bobby"), equalTo(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldUpdateSession() {
|
||||||
|
// given
|
||||||
|
DataSource dataSource = getDataSource();
|
||||||
|
PlayerAuth bobby = PlayerAuth.builder()
|
||||||
|
.name("bobby").realName("BOBBY").lastLogin(123L)
|
||||||
|
.ip("12.12.12.12").build();
|
||||||
|
|
||||||
|
// when
|
||||||
|
boolean response = dataSource.updateSession(bobby);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(response, equalTo(true));
|
||||||
|
PlayerAuth result = dataSource.getAuth("bobby");
|
||||||
|
assertThat(result, hasAuthBasicData("bobby", "BOBBY", "your@email.com", "12.12.12.12"));
|
||||||
|
assertThat(result.getLastLogin(), equalTo(123L));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldUpdateLastLoc() {
|
||||||
|
// given
|
||||||
|
DataSource dataSource = getDataSource();
|
||||||
|
PlayerAuth user = PlayerAuth.builder()
|
||||||
|
.name("user").locX(143).locY(-42.12).locZ(29.47)
|
||||||
|
.locWorld("the_end").build();
|
||||||
|
|
||||||
|
// when
|
||||||
|
boolean response = dataSource.updateQuitLoc(user);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(response, equalTo(true));
|
||||||
|
assertThat(dataSource.getAuth("user"), hasAuthLocation(143, -42.12, 29.47, "the_end"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,21 +17,26 @@ public final class AuthMeMatchers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Matcher<? super HashedPassword> equalToHash(final String hash) {
|
public static Matcher<? super HashedPassword> equalToHash(final String hash) {
|
||||||
return equalToHash(hash, null);
|
return equalToHash(new HashedPassword(hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Matcher<? super HashedPassword> equalToHash(final String hash, final String salt) {
|
public static Matcher<? super HashedPassword> equalToHash(final String hash, final String salt) {
|
||||||
|
return equalToHash(new HashedPassword(hash, salt));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Matcher<? super HashedPassword> equalToHash(final HashedPassword hash) {
|
||||||
return new TypeSafeMatcher<HashedPassword>() {
|
return new TypeSafeMatcher<HashedPassword>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean matchesSafely(HashedPassword item) {
|
public boolean matchesSafely(HashedPassword item) {
|
||||||
return Objects.equals(hash, item.getHash()) && Objects.equals(salt, item.getSalt());
|
return Objects.equals(hash.getHash(), item.getHash())
|
||||||
|
&& Objects.equals(hash.getSalt(), item.getSalt());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void describeTo(Description description) {
|
public void describeTo(Description description) {
|
||||||
String representation = "'" + hash + "'";
|
String representation = "'" + hash.getHash() + "'";
|
||||||
if (salt != null) {
|
if (hash.getSalt() != null) {
|
||||||
representation += ", '" + salt + "'";
|
representation += ", '" + hash.getSalt() + "'";
|
||||||
}
|
}
|
||||||
description.appendValue("HashedPassword(" + representation + ")");
|
description.appendValue("HashedPassword(" + representation + ")");
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,8 @@ public class MySqlIntegrationTest extends AbstractDataSourceIntegrationTest {
|
|||||||
|
|
||||||
/** Mock of a settings instance. */
|
/** Mock of a settings instance. */
|
||||||
private static NewSetting settings;
|
private static NewSetting settings;
|
||||||
/** Collection of SQL statements to execute for initialization of a test. */
|
/** SQL statement to execute before running a test. */
|
||||||
private static String[] sqlInitialize;
|
private static String sqlInitialize;
|
||||||
/** Connection to the H2 test database. */
|
/** Connection to the H2 test database. */
|
||||||
private HikariDataSource hikariSource;
|
private HikariDataSource hikariSource;
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ public class MySqlIntegrationTest extends AbstractDataSourceIntegrationTest {
|
|||||||
ConsoleLoggerTestInitializer.setupLogger();
|
ConsoleLoggerTestInitializer.setupLogger();
|
||||||
|
|
||||||
Path sqlInitFile = TestHelper.getJarPath("/datasource-integration/sql-initialize.sql");
|
Path sqlInitFile = TestHelper.getJarPath("/datasource-integration/sql-initialize.sql");
|
||||||
sqlInitialize = new String(Files.readAllBytes(sqlInitFile)).split(";\\n");
|
sqlInitialize = new String(Files.readAllBytes(sqlInitFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@ -73,9 +73,7 @@ public class MySqlIntegrationTest extends AbstractDataSourceIntegrationTest {
|
|||||||
|
|
||||||
try (Statement st = connection.createStatement()) {
|
try (Statement st = connection.createStatement()) {
|
||||||
st.execute("DROP TABLE IF EXISTS authme");
|
st.execute("DROP TABLE IF EXISTS authme");
|
||||||
for (String statement : sqlInitialize) {
|
st.execute(sqlInitialize);
|
||||||
st.execute(statement);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
hikariSource = ds;
|
hikariSource = ds;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ public class SQLiteIntegrationTest extends AbstractDataSourceIntegrationTest {
|
|||||||
Path sqlInitFile = TestHelper.getJarPath("/datasource-integration/sql-initialize.sql");
|
Path sqlInitFile = TestHelper.getJarPath("/datasource-integration/sql-initialize.sql");
|
||||||
// Note ljacqu 20160221: It appears that we can only run one statement per Statement.execute() so we split
|
// Note ljacqu 20160221: It appears that we can only run one statement per Statement.execute() so we split
|
||||||
// the SQL file by ";\n" as to get the individual statements
|
// the SQL file by ";\n" as to get the individual statements
|
||||||
sqlInitialize = new String(Files.readAllBytes(sqlInitFile)).split(";\\n");
|
sqlInitialize = new String(Files.readAllBytes(sqlInitFile)).split(";(\\r?)\\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
Loading…
Reference in New Issue
Block a user