#792 Add columns for registration IP and registration date
- Add columns for reg date and IP - Rename "ip" to "last IP"
This commit is contained in:
+8
-8
@@ -12,8 +12,6 @@ import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -22,9 +20,10 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static fr.xephi.authme.AuthMeMatchers.hasAuthBasicData;
|
||||
import static fr.xephi.authme.AuthMeMatchers.hasAuthLocation;
|
||||
import static fr.xephi.authme.AuthMeMatchers.stringWithLength;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -116,17 +115,15 @@ public class EmailRegisterExecutorProviderTest {
|
||||
Player player = mock(Player.class);
|
||||
TestHelper.mockPlayerIp(player, "123.45.67.89");
|
||||
given(player.getName()).willReturn("Veronica");
|
||||
World world = mock(World.class);
|
||||
given(world.getName()).willReturn("someWorld");
|
||||
given(player.getLocation()).willReturn(new Location(world, 48, 96, 144));
|
||||
EmailRegisterParams params = EmailRegisterParams.of(player, "test@example.com");
|
||||
|
||||
// when
|
||||
PlayerAuth auth = executor.buildPlayerAuth(params);
|
||||
|
||||
// then
|
||||
assertThat(auth, hasAuthBasicData("veronica", "Veronica", "test@example.com", "123.45.67.89"));
|
||||
assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld", 0, 0));
|
||||
assertThat(auth, hasAuthBasicData("veronica", "Veronica", "test@example.com", "127.0.0.1"));
|
||||
assertThat(auth.getRegistrationIp(), equalTo("123.45.67.89"));
|
||||
assertIsCloseTo(auth.getRegistrationDate(), System.currentTimeMillis(), 1000);
|
||||
assertThat(auth.getPassword().getHash(), stringWithLength(12));
|
||||
}
|
||||
|
||||
@@ -167,4 +164,7 @@ public class EmailRegisterExecutorProviderTest {
|
||||
verifyZeroInteractions(syncProcessManager);
|
||||
}
|
||||
|
||||
private static void assertIsCloseTo(long value1, long value2, long tolerance) {
|
||||
assertThat(Math.abs(value1 - value2), not(greaterThan(tolerance)));
|
||||
}
|
||||
}
|
||||
|
||||
+9
-8
@@ -13,8 +13,6 @@ import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.service.ValidationService.ValidationResult;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -24,8 +22,9 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static fr.xephi.authme.AuthMeMatchers.equalToHash;
|
||||
import static fr.xephi.authme.AuthMeMatchers.hasAuthBasicData;
|
||||
import static fr.xephi.authme.AuthMeMatchers.hasAuthLocation;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -98,17 +97,15 @@ public class PasswordRegisterExecutorTest {
|
||||
invocation -> new HashedPassword(invocation.getArgument(0)));
|
||||
Player player = mockPlayerWithName("S1m0N");
|
||||
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, 1.1f, 0.28f));
|
||||
PasswordRegisterParams params = PasswordRegisterParams.of(player, "pass", "mail@example.org");
|
||||
|
||||
// when
|
||||
PlayerAuth auth = executor.buildPlayerAuth(params);
|
||||
|
||||
// then
|
||||
assertThat(auth, hasAuthBasicData("s1m0n", "S1m0N", "mail@example.org", "123.45.67.89"));
|
||||
assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld", 1.1f, 0.28f));
|
||||
assertThat(auth, hasAuthBasicData("s1m0n", "S1m0N", "mail@example.org", "127.0.0.1"));
|
||||
assertThat(auth.getRegistrationIp(), equalTo("123.45.67.89"));
|
||||
assertIsCloseTo(auth.getRegistrationDate(), System.currentTimeMillis(), 500);
|
||||
assertThat(auth.getPassword(), equalToHash("pass"));
|
||||
}
|
||||
|
||||
@@ -149,4 +146,8 @@ public class PasswordRegisterExecutorTest {
|
||||
given(player.getName()).willReturn(name);
|
||||
return player;
|
||||
}
|
||||
|
||||
private static void assertIsCloseTo(long value1, long value2, long tolerance) {
|
||||
assertThat(Math.abs(value1 - value2), not(greaterThan(tolerance)));
|
||||
}
|
||||
}
|
||||
|
||||
+7
-9
@@ -3,13 +3,13 @@ package fr.xephi.authme.process.register.executors;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
|
||||
import static fr.xephi.authme.AuthMeMatchers.equalToHash;
|
||||
import static fr.xephi.authme.AuthMeMatchers.hasAuthBasicData;
|
||||
import static fr.xephi.authme.AuthMeMatchers.hasAuthLocation;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -26,10 +26,6 @@ public class PlayerAuthBuilderHelperTest {
|
||||
given(player.getName()).willReturn("Noah");
|
||||
String ip = "192.168.34.47";
|
||||
TestHelper.mockPlayerIp(player, ip);
|
||||
World world = mock(World.class);
|
||||
given(world.getName()).willReturn("worldName");
|
||||
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";
|
||||
|
||||
@@ -37,8 +33,10 @@ public class PlayerAuthBuilderHelperTest {
|
||||
PlayerAuth auth = PlayerAuthBuilderHelper.createPlayerAuth(player, hashedPassword, email);
|
||||
|
||||
// then
|
||||
assertThat(auth, hasAuthBasicData("noah", "Noah", email, ip));
|
||||
assertThat(auth, hasAuthLocation(123, 80, -99, "worldName", 2.45f, 7.61f));
|
||||
assertThat(auth, hasAuthBasicData("noah", "Noah", email, "127.0.0.1"));
|
||||
assertThat(auth.getRegistrationIp(), equalTo("192.168.34.47"));
|
||||
assertThat(Math.abs(auth.getRegistrationDate() - System.currentTimeMillis()), lessThan(1000L));
|
||||
assertThat(auth.getPassword(), equalToHash("myHash0001"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user