mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-03 01:10:17 +01:00
Removed IP Hashes from database
This commit is contained in:
parent
775baf5a00
commit
24342947e3
@ -33,10 +33,8 @@ import com.djrapitops.plan.system.importing.data.BukkitUserImportRefiner;
|
||||
import com.djrapitops.plan.system.importing.data.ServerImportData;
|
||||
import com.djrapitops.plan.system.importing.data.UserImportData;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.utilities.SHA256Hash;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@ -211,11 +209,7 @@ public abstract class BukkitImporter implements Importer {
|
||||
return userImportData.getIps().parallelStream()
|
||||
.map(ip -> {
|
||||
String geoLoc = geolocationCache.getCountry(ip);
|
||||
try {
|
||||
return new GeoInfo(ip, geoLoc, date, new SHA256Hash(ip).create());
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
return new GeoInfo(ip, geoLoc, date);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -18,13 +18,11 @@ package com.djrapitops.plan.data.container;
|
||||
|
||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||
import com.djrapitops.plan.data.store.objects.DateMap;
|
||||
import com.djrapitops.plan.utilities.SHA256Hash;
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* Data class that contains information about IP and Geolocation.
|
||||
@ -35,18 +33,16 @@ public class GeoInfo implements DateHolder, Serializable {
|
||||
|
||||
private final String ip;
|
||||
private final String geolocation;
|
||||
private final String ipHash;
|
||||
private final long date;
|
||||
|
||||
public GeoInfo(InetAddress address, String geolocation, long lastUsed) throws NoSuchAlgorithmException {
|
||||
this(formatIP(address), geolocation, lastUsed, new SHA256Hash(address.getHostAddress()).create());
|
||||
public GeoInfo(InetAddress address, String geolocation, long lastUsed) {
|
||||
this(formatIP(address), geolocation, lastUsed);
|
||||
}
|
||||
|
||||
public GeoInfo(String ip, String geolocation, long date, String ipHash) {
|
||||
public GeoInfo(String ip, String geolocation, long date) {
|
||||
this.ip = ip;
|
||||
this.geolocation = geolocation;
|
||||
this.date = date;
|
||||
this.ipHash = ipHash;
|
||||
}
|
||||
|
||||
public static DateMap<GeoInfo> intoDateMap(Iterable<GeoInfo> geoInfo) {
|
||||
@ -106,23 +102,18 @@ public class GeoInfo implements DateHolder, Serializable {
|
||||
return date;
|
||||
}
|
||||
|
||||
public String getIpHash() {
|
||||
return ipHash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
GeoInfo geoInfo = (GeoInfo) o;
|
||||
return Objects.equal(ip, geoInfo.ip) &&
|
||||
Objects.equal(geolocation, geoInfo.geolocation) &&
|
||||
Objects.equal(ipHash, geoInfo.ipHash);
|
||||
Objects.equal(geolocation, geoInfo.geolocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(ip, geolocation, ipHash);
|
||||
return Objects.hashCode(ip, geolocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -130,7 +121,6 @@ public class GeoInfo implements DateHolder, Serializable {
|
||||
return "GeoInfo{" +
|
||||
"ip='" + ip + '\'' +
|
||||
", geolocation='" + geolocation + '\'' +
|
||||
", ipHash='" + ipHash + '\'' +
|
||||
", date=" + date +
|
||||
'}';
|
||||
}
|
||||
|
@ -149,9 +149,9 @@ public abstract class SQLDB extends AbstractDatabase {
|
||||
new UserInfoOptimizationPatch(),
|
||||
new GeoInfoOptimizationPatch(),
|
||||
new TransferTableRemovalPatch(),
|
||||
new IPHashPatch(),
|
||||
new IPAnonPatch(),
|
||||
new BadAFKThresholdValuePatch()
|
||||
new BadAFKThresholdValuePatch(),
|
||||
new DeleteIPHashesPatch()
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -164,8 +164,7 @@ public class DataStoreQueries {
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setLong(1, geoInfo.getDate());
|
||||
statement.setString(2, playerUUID.toString());
|
||||
statement.setString(3, geoInfo.getIpHash());
|
||||
statement.setString(4, geoInfo.getGeolocation());
|
||||
statement.setString(3, geoInfo.getGeolocation());
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -176,9 +175,8 @@ public class DataStoreQueries {
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, playerUUID.toString());
|
||||
statement.setString(2, geoInfo.getIp());
|
||||
statement.setString(3, geoInfo.getIpHash());
|
||||
statement.setString(4, geoInfo.getGeolocation());
|
||||
statement.setLong(5, geoInfo.getDate());
|
||||
statement.setString(3, geoInfo.getGeolocation());
|
||||
statement.setLong(4, geoInfo.getDate());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -97,15 +97,13 @@ public class LargeStoreQueries {
|
||||
// Every GeoInfo
|
||||
for (GeoInfo info : playerEntry.getValue()) {
|
||||
String ip = info.getIp();
|
||||
String ipHash = info.getIpHash();
|
||||
String geoLocation = info.getGeolocation();
|
||||
long lastUsed = info.getDate();
|
||||
|
||||
statement.setString(1, playerUUID.toString());
|
||||
statement.setString(2, ip);
|
||||
statement.setString(3, ipHash);
|
||||
statement.setString(4, geoLocation);
|
||||
statement.setLong(5, lastUsed);
|
||||
statement.setString(3, geoLocation);
|
||||
statement.setLong(4, lastUsed);
|
||||
|
||||
statement.addBatch();
|
||||
}
|
||||
|
@ -49,7 +49,6 @@ public class GeoInfoQueries {
|
||||
GeoInfoTable.IP + ", " +
|
||||
GeoInfoTable.GEOLOCATION + ", " +
|
||||
GeoInfoTable.LAST_USED + ", " +
|
||||
GeoInfoTable.IP_HASH + ", " +
|
||||
GeoInfoTable.USER_UUID +
|
||||
" FROM " + GeoInfoTable.TABLE_NAME;
|
||||
|
||||
@ -64,9 +63,8 @@ public class GeoInfoQueries {
|
||||
|
||||
String ip = set.getString(GeoInfoTable.IP);
|
||||
String geolocation = set.getString(GeoInfoTable.GEOLOCATION);
|
||||
String ipHash = set.getString(GeoInfoTable.IP_HASH);
|
||||
long lastUsed = set.getLong(GeoInfoTable.LAST_USED);
|
||||
userGeoInfo.add(new GeoInfo(ip, geolocation, lastUsed, ipHash));
|
||||
userGeoInfo.add(new GeoInfo(ip, geolocation, lastUsed));
|
||||
|
||||
geoInformation.put(uuid, userGeoInfo);
|
||||
}
|
||||
@ -97,9 +95,8 @@ public class GeoInfoQueries {
|
||||
while (set.next()) {
|
||||
String ip = set.getString(GeoInfoTable.IP);
|
||||
String geolocation = set.getString(GeoInfoTable.GEOLOCATION);
|
||||
String ipHash = set.getString(GeoInfoTable.IP_HASH);
|
||||
long lastUsed = set.getLong(GeoInfoTable.LAST_USED);
|
||||
geoInfo.add(new GeoInfo(ip, geolocation, lastUsed, ipHash));
|
||||
geoInfo.add(new GeoInfo(ip, geolocation, lastUsed));
|
||||
}
|
||||
return geoInfo;
|
||||
}
|
||||
@ -110,8 +107,7 @@ public class GeoInfoQueries {
|
||||
String sql = "SELECT " + GeoInfoTable.TABLE_NAME + "." + GeoInfoTable.USER_UUID + ", " +
|
||||
GeoInfoTable.GEOLOCATION + ", " +
|
||||
GeoInfoTable.LAST_USED + ", " +
|
||||
GeoInfoTable.IP + ", " +
|
||||
GeoInfoTable.IP_HASH +
|
||||
GeoInfoTable.IP +
|
||||
" FROM " + GeoInfoTable.TABLE_NAME +
|
||||
" INNER JOIN " + UserInfoTable.TABLE_NAME + " on " +
|
||||
GeoInfoTable.TABLE_NAME + "." + GeoInfoTable.USER_UUID + "=" + UserInfoTable.TABLE_NAME + "." + UserInfoTable.USER_UUID +
|
||||
@ -132,9 +128,8 @@ public class GeoInfoQueries {
|
||||
|
||||
String ip = set.getString(GeoInfoTable.IP);
|
||||
String geolocation = set.getString(GeoInfoTable.GEOLOCATION);
|
||||
String ipHash = set.getString(GeoInfoTable.IP_HASH);
|
||||
long lastUsed = set.getLong(GeoInfoTable.LAST_USED);
|
||||
userGeoInfo.add(new GeoInfo(ip, geolocation, lastUsed, ipHash));
|
||||
userGeoInfo.add(new GeoInfo(ip, geolocation, lastUsed));
|
||||
|
||||
geoInformation.put(uuid, userGeoInfo);
|
||||
}
|
||||
|
@ -0,0 +1,54 @@
|
||||
package com.djrapitops.plan.db.patches;
|
||||
|
||||
import com.djrapitops.plan.db.access.ExecStatement;
|
||||
import com.djrapitops.plan.db.access.HasMoreThanZeroQueryStatement;
|
||||
import com.djrapitops.plan.db.sql.tables.GeoInfoTable;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Patch for removing ip_hash values from plan_ips table.
|
||||
* <p>
|
||||
* The patch is a response to a concern:
|
||||
* "Hashed IP addresses are pseudonymised not anonymised and can be easily decoded using a rainbow table".
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class DeleteIPHashesPatch extends Patch {
|
||||
|
||||
private boolean hasNoHashColumn;
|
||||
|
||||
@Override
|
||||
public boolean hasBeenApplied() {
|
||||
hasNoHashColumn = !hasColumn(GeoInfoTable.TABLE_NAME, "ip_hash");
|
||||
|
||||
String sql = SELECT + "COUNT(1) as c" + FROM + GeoInfoTable.TABLE_NAME +
|
||||
WHERE + "ip_hash" + IS_NOT_NULL;
|
||||
|
||||
return hasNoHashColumn || !query(new HasMoreThanZeroQueryStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyPatch() {
|
||||
if (hasNoHashColumn) {
|
||||
return;
|
||||
}
|
||||
|
||||
String sql = "UPDATE " + GeoInfoTable.TABLE_NAME + " SET ip_hash=?" + WHERE + "ip_hash" + IS_NOT_NULL;
|
||||
execute(new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setNull(1, Types.VARCHAR);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -44,13 +44,11 @@ public class GeoInfoOptimizationPatch extends Patch {
|
||||
execute("INSERT INTO " + tableName + " (" +
|
||||
GeoInfoTable.USER_UUID + ", " +
|
||||
GeoInfoTable.IP + ", " +
|
||||
GeoInfoTable.IP_HASH + ", " +
|
||||
GeoInfoTable.LAST_USED + ", " +
|
||||
GeoInfoTable.GEOLOCATION +
|
||||
") SELECT " +
|
||||
"(SELECT plan_users.uuid FROM plan_users WHERE plan_users.id = " + tempTableName + ".user_id LIMIT 1), " +
|
||||
GeoInfoTable.IP + ", " +
|
||||
GeoInfoTable.IP_HASH + ", " +
|
||||
GeoInfoTable.LAST_USED + ", " +
|
||||
GeoInfoTable.GEOLOCATION +
|
||||
" FROM " + tempTableName
|
||||
|
@ -24,7 +24,6 @@ import com.djrapitops.plan.db.sql.tables.GeoInfoTable;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@ -73,8 +72,7 @@ public class IPAnonPatch extends Patch {
|
||||
|
||||
private void anonymizeIPs(Map<UUID, List<GeoInfo>> allGeoInfo) {
|
||||
String sql = "UPDATE " + GeoInfoTable.TABLE_NAME + " SET " +
|
||||
GeoInfoTable.IP + "=?, " +
|
||||
GeoInfoTable.IP_HASH + "=? " +
|
||||
GeoInfoTable.IP + "=? " +
|
||||
"WHERE " + GeoInfoTable.IP + "=?";
|
||||
|
||||
execute(new ExecBatchStatement(sql) {
|
||||
@ -99,11 +97,10 @@ public class IPAnonPatch extends Patch {
|
||||
geoInfo.getDate()
|
||||
);
|
||||
statement.setString(1, updatedInfo.getIp());
|
||||
statement.setString(2, updatedInfo.getIpHash());
|
||||
statement.setString(3, geoInfo.getIp());
|
||||
statement.setString(2, geoInfo.getIp());
|
||||
statement.addBatch();
|
||||
} catch (UnknownHostException | NoSuchAlgorithmException ignore) {
|
||||
// This ip is already anonymised or completely unusable.
|
||||
} catch (UnknownHostException ignore) {
|
||||
// This ip is completely unusable.
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -120,11 +117,11 @@ public class IPAnonPatch extends Patch {
|
||||
String identifiers = hasUserIdColumn ? userIdColumn : "id, uuid";
|
||||
|
||||
execute("INSERT INTO plan_ips (" +
|
||||
identifiers + ", ip, ip_hash, geolocation, last_used" +
|
||||
identifiers + ", ip, geolocation, last_used" +
|
||||
") SELECT " +
|
||||
identifiers + ", ip, ip_hash, geolocation, MAX(last_used) FROM plan_ips_temp GROUP BY ip_hash, " +
|
||||
identifiers + ", ip, geolocation, MAX(last_used) FROM plan_ips_temp GROUP BY ip, " +
|
||||
(hasUserIdColumn ? userIdColumn : "uuid") +
|
||||
", ip, geolocation");
|
||||
", geolocation");
|
||||
dropTable(tempTableName);
|
||||
}
|
||||
|
||||
|
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.db.patches;
|
||||
|
||||
import com.djrapitops.plan.db.sql.tables.GeoInfoTable;
|
||||
|
||||
public class IPHashPatch extends Patch {
|
||||
|
||||
@Override
|
||||
public boolean hasBeenApplied() {
|
||||
return hasColumn(GeoInfoTable.TABLE_NAME, GeoInfoTable.IP_HASH);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyPatch() {
|
||||
addColumn(GeoInfoTable.TABLE_NAME, GeoInfoTable.IP_HASH + " varchar(200) DEFAULT ''");
|
||||
}
|
||||
}
|
@ -28,8 +28,8 @@ import com.djrapitops.plan.db.sql.parsing.Sql;
|
||||
* {@link Version10Patch}
|
||||
* {@link GeoInfoLastUsedPatch}
|
||||
* {@link IPAnonPatch}
|
||||
* {@link IPHashPatch}
|
||||
* {@link GeoInfoOptimizationPatch}
|
||||
* {@link DeleteIPHashesPatch}
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@ -40,22 +40,19 @@ public class GeoInfoTable {
|
||||
public static final String ID = "id";
|
||||
public static final String USER_UUID = "uuid";
|
||||
public static final String IP = "ip";
|
||||
public static final String IP_HASH = "ip_hash";
|
||||
public static final String GEOLOCATION = "geolocation";
|
||||
public static final String LAST_USED = "last_used";
|
||||
|
||||
public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME + " ("
|
||||
+ USER_UUID + ", "
|
||||
+ IP + ", "
|
||||
+ IP_HASH + ", "
|
||||
+ GEOLOCATION + ", "
|
||||
+ LAST_USED
|
||||
+ ") VALUES (?, ?, ?, ?, ?)";
|
||||
+ ") VALUES (?, ?, ?, ?)";
|
||||
|
||||
public static final String UPDATE_STATEMENT = "UPDATE " + TABLE_NAME + " SET "
|
||||
+ LAST_USED + "=?" +
|
||||
" WHERE " + USER_UUID + "=?" +
|
||||
" AND " + IP_HASH + "=?" +
|
||||
" AND " + GEOLOCATION + "=?";
|
||||
|
||||
private GeoInfoTable() {
|
||||
@ -68,7 +65,6 @@ public class GeoInfoTable {
|
||||
.column(USER_UUID, Sql.varchar(36)).notNull()
|
||||
.column(IP, Sql.varchar(39)).notNull()
|
||||
.column(GEOLOCATION, Sql.varchar(50)).notNull()
|
||||
.column(IP_HASH, Sql.varchar(200))
|
||||
.column(LAST_USED, Sql.LONG).notNull().defaultValue("0")
|
||||
.toString();
|
||||
}
|
||||
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.utilities;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Base64;
|
||||
|
||||
public class SHA256Hash {
|
||||
|
||||
private final String original;
|
||||
|
||||
public SHA256Hash(String original) {
|
||||
this.original = original;
|
||||
}
|
||||
|
||||
public String create() throws NoSuchAlgorithmException {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
digest.update(original.getBytes(StandardCharsets.UTF_8));
|
||||
return Base64.getEncoder().encodeToString(digest.digest());
|
||||
}
|
||||
}
|
@ -74,7 +74,6 @@ import com.djrapitops.plan.system.settings.config.Config;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.paths.DatabaseSettings;
|
||||
import com.djrapitops.plan.system.settings.paths.WebserverSettings;
|
||||
import com.djrapitops.plan.utilities.SHA256Hash;
|
||||
import com.djrapitops.plan.utilities.comparators.DateHolderRecentComparator;
|
||||
import com.djrapitops.plugin.logging.console.TestPluginLogger;
|
||||
import com.djrapitops.plugin.logging.error.ConsoleErrorLogger;
|
||||
@ -273,13 +272,13 @@ public abstract class CommonDBTest {
|
||||
String expectedGeoLoc = "TestLocation";
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
saveGeoInfo(playerUUID, new GeoInfo(expectedIP, expectedGeoLoc, time, "3"));
|
||||
saveGeoInfo(playerUUID, new GeoInfo(expectedIP, expectedGeoLoc, time));
|
||||
commitTest();
|
||||
|
||||
List<GeoInfo> geolocations = db.query(GeoInfoQueries.fetchAllGeoInformation()).getOrDefault(playerUUID, new ArrayList<>());
|
||||
assertEquals(1, geolocations.size());
|
||||
|
||||
GeoInfo expected = new GeoInfo("1.2.xx.xx", expectedGeoLoc, time, new SHA256Hash(expectedIP).create());
|
||||
GeoInfo expected = new GeoInfo("1.2.xx.xx", expectedGeoLoc, time);
|
||||
assertEquals(expected, geolocations.get(0));
|
||||
}
|
||||
|
||||
@ -502,7 +501,7 @@ public abstract class CommonDBTest {
|
||||
|
||||
execute(DataStoreQueries.storeSession(session));
|
||||
db.executeTransaction(new NicknameStoreTransaction(playerUUID, new Nickname("TestNick", System.currentTimeMillis(), serverUUID), (uuid, name) -> false /* Not cached */));
|
||||
saveGeoInfo(playerUUID, new GeoInfo("1.2.3.4", "TestLoc", 223456789L, "3"));
|
||||
saveGeoInfo(playerUUID, new GeoInfo("1.2.3.4", "TestLoc", 223456789L));
|
||||
|
||||
assertTrue(db.query(PlayerFetchQueries.isPlayerRegistered(playerUUID)));
|
||||
|
||||
@ -553,8 +552,7 @@ public abstract class CommonDBTest {
|
||||
db.executeTransaction(
|
||||
new NicknameStoreTransaction(playerUUID, new Nickname("TestNick", System.currentTimeMillis(), serverUUID), (uuid, name) -> false /* Not cached */)
|
||||
);
|
||||
saveGeoInfo(playerUUID, new GeoInfo("1.2.3.4", "TestLoc", 223456789L,
|
||||
new SHA256Hash("1.2.3.4").create()));
|
||||
saveGeoInfo(playerUUID, new GeoInfo("1.2.3.4", "TestLoc", 223456789L));
|
||||
|
||||
assertTrue(db.query(PlayerFetchQueries.isPlayerRegistered(playerUUID)));
|
||||
|
||||
@ -875,7 +873,7 @@ public abstract class CommonDBTest {
|
||||
OptionalAssert.equals(1, container.getValue(PlayerKeys.KICK_COUNT));
|
||||
|
||||
List<GeoInfo> expectedGeoInfo =
|
||||
Collections.singletonList(new GeoInfo("1.2.3.4", "TestLoc", 223456789, "ZpT4PJ9HbaMfXfa8xSADTn5X1CHSR7nTT0ntv8hKdkw="));
|
||||
Collections.singletonList(new GeoInfo("1.2.3.4", "TestLoc", 223456789));
|
||||
OptionalAssert.equals(expectedGeoInfo, container.getValue(PlayerKeys.GEO_INFO));
|
||||
|
||||
List<Nickname> expectedNicknames = Collections.singletonList(new Nickname("TestNick", -1, serverUUID));
|
||||
|
@ -83,13 +83,13 @@ public class MySQLTest extends CommonDBTest {
|
||||
db.executeTransaction(new PlayerRegisterTransaction(secondUuid, () -> 0L, ""));
|
||||
db.executeTransaction(new PlayerRegisterTransaction(thirdUuid, () -> 0L, ""));
|
||||
|
||||
saveGeoInfo(firstUuid, new GeoInfo("-", "Norway", 0, "3"));
|
||||
saveGeoInfo(firstUuid, new GeoInfo("-", "Finland", 5, "3"));
|
||||
saveGeoInfo(secondUuid, new GeoInfo("-", "Sweden", 0, "3"));
|
||||
saveGeoInfo(thirdUuid, new GeoInfo("-", "Denmark", 0, "3"));
|
||||
saveGeoInfo(fourthUuid, new GeoInfo("-", "Denmark", 0, "3"));
|
||||
saveGeoInfo(fifthUuid, new GeoInfo("-", "Not Known", 0, "3"));
|
||||
saveGeoInfo(sixthUuid, new GeoInfo("-", "Local Machine", 0, "3"));
|
||||
saveGeoInfo(firstUuid, new GeoInfo("-", "Norway", 0));
|
||||
saveGeoInfo(firstUuid, new GeoInfo("-", "Finland", 5));
|
||||
saveGeoInfo(secondUuid, new GeoInfo("-", "Sweden", 0));
|
||||
saveGeoInfo(thirdUuid, new GeoInfo("-", "Denmark", 0));
|
||||
saveGeoInfo(fourthUuid, new GeoInfo("-", "Denmark", 0));
|
||||
saveGeoInfo(fifthUuid, new GeoInfo("-", "Not Known", 0));
|
||||
saveGeoInfo(sixthUuid, new GeoInfo("-", "Local Machine", 0));
|
||||
|
||||
Map<String, Integer> got = db.query(ServerAggregateQueries.networkGeolocationCounts());
|
||||
|
||||
|
@ -100,13 +100,13 @@ public class SQLiteTest extends CommonDBTest {
|
||||
db.executeTransaction(new PlayerRegisterTransaction(secondUuid, () -> 0L, ""));
|
||||
db.executeTransaction(new PlayerRegisterTransaction(thirdUuid, () -> 0L, ""));
|
||||
|
||||
saveGeoInfo(firstUuid, new GeoInfo("-", "Norway", 0, "3"));
|
||||
saveGeoInfo(firstUuid, new GeoInfo("-", "Finland", 5, "3"));
|
||||
saveGeoInfo(secondUuid, new GeoInfo("-", "Sweden", 0, "3"));
|
||||
saveGeoInfo(thirdUuid, new GeoInfo("-", "Denmark", 0, "3"));
|
||||
saveGeoInfo(fourthUuid, new GeoInfo("-", "Denmark", 0, "3"));
|
||||
saveGeoInfo(fifthUuid, new GeoInfo("-", "Not Known", 0, "3"));
|
||||
saveGeoInfo(sixthUuid, new GeoInfo("-", "Local Machine", 0, "3"));
|
||||
saveGeoInfo(firstUuid, new GeoInfo("-", "Norway", 0));
|
||||
saveGeoInfo(firstUuid, new GeoInfo("-", "Finland", 5));
|
||||
saveGeoInfo(secondUuid, new GeoInfo("-", "Sweden", 0));
|
||||
saveGeoInfo(thirdUuid, new GeoInfo("-", "Denmark", 0));
|
||||
saveGeoInfo(fourthUuid, new GeoInfo("-", "Denmark", 0));
|
||||
saveGeoInfo(fifthUuid, new GeoInfo("-", "Not Known", 0));
|
||||
saveGeoInfo(sixthUuid, new GeoInfo("-", "Local Machine", 0));
|
||||
|
||||
Map<String, Integer> got = db.query(ServerAggregateQueries.networkGeolocationCounts());
|
||||
|
||||
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.utilities;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.platform.runner.JUnitPlatform;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@RunWith(JUnitPlatform.class)
|
||||
class SHA256HashTest {
|
||||
|
||||
@Test
|
||||
void sameStringReturnsSameHash() throws NoSuchAlgorithmException {
|
||||
String expected = new SHA256Hash("1.3.4.5").create();
|
||||
String result = new SHA256Hash("1.3.4.5").create();
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
}
|
@ -98,7 +98,7 @@ public class RandomData {
|
||||
public static List<GeoInfo> randomGeoInfo() {
|
||||
List<GeoInfo> test = new ArrayList<>();
|
||||
for (int i = 0; i < 20; i++) {
|
||||
GeoInfo geoInfo = new GeoInfo(randomString(10), randomString(10), r.nextLong(), "");
|
||||
GeoInfo geoInfo = new GeoInfo(randomString(10), randomString(10), r.nextLong());
|
||||
test.add(geoInfo);
|
||||
}
|
||||
return test;
|
||||
|
@ -28,7 +28,6 @@ import com.djrapitops.plan.system.info.server.Server;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -72,7 +71,7 @@ public class TestData {
|
||||
geoInfos.add(new GeoInfo(InetAddress.getByName("43b9:416b:3cb2:649d:ebaf:872:d89a:343d"), "Not Known", playerFirstJoin));
|
||||
geoInfos.add(new GeoInfo(InetAddress.getByName("127.0.0.1"), "Local Machine", playerFirstJoin));
|
||||
geoInfos.add(new GeoInfo(InetAddress.getByName("181.103.227.78"), "Argentina", playerFirstJoin));
|
||||
} catch (UnknownHostException | NoSuchAlgorithmException e) {
|
||||
} catch (UnknownHostException e) {
|
||||
Logger.getGlobal().log(Level.WARNING, e, () -> "Failed to create GeoInfo");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user