#815 Save yaw & pitch for last login in SQL data sources
This commit is contained in:
@@ -16,15 +16,15 @@ public final class AuthMeMatchers {
|
||||
private AuthMeMatchers() {
|
||||
}
|
||||
|
||||
public static Matcher<? super HashedPassword> equalToHash(final String hash) {
|
||||
public static Matcher<? super HashedPassword> equalToHash(String hash) {
|
||||
return equalToHash(new HashedPassword(hash));
|
||||
}
|
||||
|
||||
public static Matcher<? super HashedPassword> equalToHash(final String hash, final String salt) {
|
||||
public static Matcher<? super HashedPassword> equalToHash(String hash, String salt) {
|
||||
return equalToHash(new HashedPassword(hash, salt));
|
||||
}
|
||||
|
||||
public static Matcher<? super HashedPassword> equalToHash(final HashedPassword hash) {
|
||||
public static Matcher<? super HashedPassword> equalToHash(HashedPassword hash) {
|
||||
return new TypeSafeMatcher<HashedPassword>() {
|
||||
@Override
|
||||
public boolean matchesSafely(HashedPassword item) {
|
||||
@@ -43,8 +43,8 @@ public final class AuthMeMatchers {
|
||||
};
|
||||
}
|
||||
|
||||
public static Matcher<? super PlayerAuth> hasAuthBasicData(final String name, final String realName,
|
||||
final String email, final String ip) {
|
||||
public static Matcher<? super PlayerAuth> hasAuthBasicData(String name, String realName,
|
||||
String email, String ip) {
|
||||
return new TypeSafeMatcher<PlayerAuth>() {
|
||||
@Override
|
||||
public boolean matchesSafely(PlayerAuth item) {
|
||||
@@ -59,29 +59,43 @@ public final class AuthMeMatchers {
|
||||
description.appendValue(String.format("PlayerAuth with name %s, realname %s, email %s, ip %s",
|
||||
name, realName, email, ip));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeMismatchSafely(PlayerAuth item, Description description) {
|
||||
description.appendValue(String.format("PlayerAuth with name %s, realname %s, email %s, ip %s",
|
||||
item.getNickname(), item.getRealName(), item.getEmail(), item.getIp()));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Matcher<? super PlayerAuth> hasAuthLocation(final double x, final double y, final double z,
|
||||
final String world) {
|
||||
public static Matcher<? super PlayerAuth> hasAuthLocation(PlayerAuth auth) {
|
||||
return hasAuthLocation(auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(),
|
||||
auth.getYaw(), auth.getPitch());
|
||||
}
|
||||
|
||||
public static Matcher<? super PlayerAuth> hasAuthLocation(double x, double y, double z,
|
||||
String world, float yaw, float pitch) {
|
||||
return new TypeSafeMatcher<PlayerAuth>() {
|
||||
@Override
|
||||
public boolean matchesSafely(PlayerAuth item) {
|
||||
return Objects.equals(x, item.getQuitLocX())
|
||||
&& Objects.equals(y, item.getQuitLocY())
|
||||
&& Objects.equals(z, item.getQuitLocZ())
|
||||
&& Objects.equals(world, item.getWorld());
|
||||
&& Objects.equals(world, item.getWorld())
|
||||
&& Objects.equals(yaw, item.getYaw())
|
||||
&& Objects.equals(pitch, item.getPitch());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendValue(String.format("PlayerAuth with quit location (x: %f, y: %f, z: %f, world: %s)",
|
||||
x, y, z, world));
|
||||
description.appendValue(
|
||||
String.format("PlayerAuth with quit location (x: %f, y: %f, z: %f, world: %s, yaw: %f, pitch: %f)",
|
||||
x, y, z, world, yaw, pitch));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Matcher<String> stringWithLength(final int length) {
|
||||
public static Matcher<String> stringWithLength(int length) {
|
||||
return new TypeSafeMatcher<String>() {
|
||||
@Override
|
||||
protected boolean matchesSafely(String item) {
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package fr.xephi.authme.api.v3;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ReflectionTestUtils;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.service.PluginHookService;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.service.PluginHookService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -43,8 +42,6 @@ public class AuthMeApiTest {
|
||||
@InjectMocks
|
||||
private AuthMeApi api;
|
||||
|
||||
@Mock
|
||||
private AuthMe authMe;
|
||||
@Mock
|
||||
private PluginHookService pluginHookService;
|
||||
@Mock
|
||||
@@ -120,6 +117,8 @@ public class AuthMeApiTest {
|
||||
.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);
|
||||
@@ -136,6 +135,8 @@ public class AuthMeApiTest {
|
||||
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()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -96,12 +96,12 @@ public abstract class AbstractDataSourceIntegrationTest {
|
||||
assertThat(invalidAuth, nullValue());
|
||||
|
||||
assertThat(bobbyAuth, hasAuthBasicData("bobby", "Bobby", "your@email.com", "123.45.67.89"));
|
||||
assertThat(bobbyAuth, hasAuthLocation(1.05, 2.1, 4.2, "world"));
|
||||
assertThat(bobbyAuth, hasAuthLocation(1.05, 2.1, 4.2, "world", -0.44f, 2.77f));
|
||||
assertThat(bobbyAuth.getLastLogin(), equalTo(1449136800L));
|
||||
assertThat(bobbyAuth.getPassword(), equalToHash("$SHA$11aa0706173d7272$dbba966"));
|
||||
|
||||
assertThat(userAuth, hasAuthBasicData("user", "user", "user@example.org", "34.56.78.90"));
|
||||
assertThat(userAuth, hasAuthLocation(124.1, 76.3, -127.8, "nether"));
|
||||
assertThat(userAuth, hasAuthLocation(124.1, 76.3, -127.8, "nether", 0.23f, 4.88f));
|
||||
assertThat(userAuth.getLastLogin(), equalTo(1453242857L));
|
||||
assertThat(userAuth.getPassword(), equalToHash("b28c32f624a4eb161d6adc9acb5bfc5b", "f750ba32"));
|
||||
}
|
||||
@@ -229,14 +229,14 @@ public abstract class AbstractDataSourceIntegrationTest {
|
||||
DataSource dataSource = getDataSource();
|
||||
PlayerAuth user = PlayerAuth.builder()
|
||||
.name("user").locX(143).locY(-42.12).locZ(29.47)
|
||||
.locWorld("the_end").build();
|
||||
.locWorld("the_end").locYaw(2.2f).locPitch(0.45f).build();
|
||||
|
||||
// when
|
||||
boolean response = dataSource.updateQuitLoc(user);
|
||||
|
||||
// then
|
||||
assertThat(response, equalTo(true));
|
||||
assertThat(dataSource.getAuth("user"), hasAuthLocation(143, -42.12, 29.47, "the_end"));
|
||||
assertThat(dataSource.getAuth("user"), hasAuthLocation(user));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -62,15 +62,15 @@ public class FlatFileIntegrationTest {
|
||||
// then
|
||||
assertThat(authList, hasSize(7));
|
||||
assertThat(getName("bobby", authList), hasAuthBasicData("bobby", "bobby", "your@email.com", "123.45.67.89"));
|
||||
assertThat(getName("bobby", authList), hasAuthLocation(1.05, 2.1, 4.2, "world"));
|
||||
assertThat(getName("bobby", authList), hasAuthLocation(1.05, 2.1, 4.2, "world", 0, 0));
|
||||
assertThat(getName("bobby", authList).getPassword(), equalToHash("$SHA$11aa0706173d7272$dbba966"));
|
||||
assertThat(getName("twofields", authList), hasAuthBasicData("twofields", "twofields", "your@email.com", "127.0.0.1"));
|
||||
assertThat(getName("twofields", authList).getPassword(), equalToHash("hash1234"));
|
||||
assertThat(getName("threefields", authList), hasAuthBasicData("threefields", "threefields", "your@email.com", "33.33.33.33"));
|
||||
assertThat(getName("fourfields", authList), hasAuthBasicData("fourfields", "fourfields", "your@email.com", "4.4.4.4"));
|
||||
assertThat(getName("fourfields", authList).getLastLogin(), equalTo(404040404L));
|
||||
assertThat(getName("sevenfields", authList), hasAuthLocation(7.7, 14.14, 21.21, "world"));
|
||||
assertThat(getName("eightfields", authList), hasAuthLocation(8.8, 17.6, 26.4, "eightworld"));
|
||||
assertThat(getName("sevenfields", authList), hasAuthLocation(7.7, 14.14, 21.21, "world", 0, 0));
|
||||
assertThat(getName("eightfields", authList), hasAuthLocation(8.8, 17.6, 26.4, "eightworld", 0, 0));
|
||||
assertThat(getName("eightfields", authList).getLastLogin(), equalTo(1234567888L));
|
||||
assertThat(getName("eightfields", authList).getPassword(), equalToHash("hash8168"));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package fr.xephi.authme.datasource;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import fr.xephi.authme.datasource.AbstractResourceClosingTest;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.MySQL;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package fr.xephi.authme.datasource;
|
||||
|
||||
import fr.xephi.authme.datasource.AbstractResourceClosingTest;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.SQLite;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
|
||||
@@ -64,11 +64,11 @@ public class ForceFlatToSqliteTest {
|
||||
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")));
|
||||
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")));
|
||||
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")));
|
||||
assertThat(auths, hasItem(hasAuthLocation(8.8, 17.6, 26.4, "eightworld", 0, 0)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -126,7 +126,7 @@ public class EmailRegisterExecutorProviderTest {
|
||||
|
||||
// then
|
||||
assertThat(auth, hasAuthBasicData("veronica", "Veronica", "test@example.com", "123.45.67.89"));
|
||||
assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld"));
|
||||
assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld", 0, 0));
|
||||
assertThat(auth.getPassword().getHash(), stringWithLength(12));
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -100,7 +100,7 @@ public class PasswordRegisterExecutorTest {
|
||||
TestHelper.mockPlayerIp(player, "123.45.67.89");
|
||||
World world = mock(World.class);
|
||||
given(world.getName()).willReturn("someWorld");
|
||||
given(player.getLocation()).willReturn(new Location(world, 48, 96, 144));
|
||||
given(player.getLocation()).willReturn(new Location(world, 48, 96, 144, 1.1f, 0.28f));
|
||||
PasswordRegisterParams params = PasswordRegisterParams.of(player, "pass", "mail@example.org");
|
||||
|
||||
// when
|
||||
@@ -108,7 +108,7 @@ public class PasswordRegisterExecutorTest {
|
||||
|
||||
// then
|
||||
assertThat(auth, hasAuthBasicData("s1m0n", "S1m0N", "mail@example.org", "123.45.67.89"));
|
||||
assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld"));
|
||||
assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld", 1.1f, 0.28f));
|
||||
assertThat(auth.getPassword(), equalToHash("pass"));
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ public class PlayerAuthBuilderHelperTest {
|
||||
TestHelper.mockPlayerIp(player, ip);
|
||||
World world = mock(World.class);
|
||||
given(world.getName()).willReturn("worldName");
|
||||
Location location = new Location(world, 123, 80, -99);
|
||||
Location location = new Location(world, 123, 80, -99, 2.45f, 7.61f);
|
||||
given(player.getLocation()).willReturn(location);
|
||||
HashedPassword hashedPassword = new HashedPassword("myHash0001");
|
||||
String email = "test@example.org";
|
||||
@@ -38,7 +38,7 @@ public class PlayerAuthBuilderHelperTest {
|
||||
|
||||
// then
|
||||
assertThat(auth, hasAuthBasicData("noah", "Noah", email, ip));
|
||||
assertThat(auth, hasAuthLocation(123, 80, -99, "worldName"));
|
||||
assertThat(auth, hasAuthLocation(123, 80, -99, "worldName", 2.45f, 7.61f));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -10,6 +10,8 @@ CREATE TABLE authme (
|
||||
y DOUBLE NOT NULL DEFAULT '0.0',
|
||||
z DOUBLE NOT NULL DEFAULT '0.0',
|
||||
world VARCHAR(255) NOT NULL DEFAULT 'world',
|
||||
yaw FLOAT,
|
||||
pitch FLOAT,
|
||||
email VARCHAR(255) DEFAULT 'your@email.com',
|
||||
isLogged INT DEFAULT '0', realname VARCHAR(255) NOT NULL DEFAULT 'Player',
|
||||
salt varchar(255),
|
||||
@@ -18,7 +20,7 @@ CREATE TABLE authme (
|
||||
CONSTRAINT table_const_prim PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
INSERT INTO authme (id, username, password, ip, lastlogin, x, y, z, world, email, isLogged, realname, salt)
|
||||
VALUES (1,'bobby','$SHA$11aa0706173d7272$dbba966','123.45.67.89',1449136800,1.05,2.1,4.2,'world','your@email.com',0,'Bobby',NULL);
|
||||
INSERT INTO authme (id, username, password, ip, lastlogin, x, y, z, world, email, isLogged, realname, salt)
|
||||
VALUES (NULL,'user','b28c32f624a4eb161d6adc9acb5bfc5b','34.56.78.90',1453242857,124.1,76.3,-127.8,'nether','user@example.org',0,'user','f750ba32');
|
||||
INSERT INTO authme (id, username, password, ip, lastlogin, x, y, z, world, yaw, pitch, email, isLogged, realname, salt)
|
||||
VALUES (1,'bobby','$SHA$11aa0706173d7272$dbba966','123.45.67.89',1449136800,1.05,2.1,4.2,'world',-0.44,2.77,'your@email.com',0,'Bobby',NULL);
|
||||
INSERT INTO authme (id, username, password, ip, lastlogin, x, y, z, world, yaw, pitch, email, isLogged, realname, salt)
|
||||
VALUES (NULL,'user','b28c32f624a4eb161d6adc9acb5bfc5b','34.56.78.90',1453242857,124.1,76.3,-127.8,'nether',0.23,4.88,'user@example.org',0,'user','f750ba32');
|
||||
|
||||
Reference in New Issue
Block a user