Merge branch 'master' of https://github.com/AuthMe/AuthMeReloaded into 930-captcha-for-register
This commit is contained in:
@@ -28,6 +28,7 @@ import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.time.Instant;
|
||||
|
||||
import static fr.xephi.authme.IsEqualByReflectionMatcher.isEqualTo;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
@@ -202,7 +203,7 @@ public class AuthMeApiTest {
|
||||
|
||||
// then
|
||||
assertThat(result, not(nullValue()));
|
||||
assertThat(result, equalTo(new Date(1501597979)));
|
||||
assertThat(result, equalTo(new Date(1501597979L)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -222,6 +223,40 @@ public class AuthMeApiTest {
|
||||
verify(dataSource).getAuth(name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetLastLoginTime() {
|
||||
// given
|
||||
String name = "David";
|
||||
PlayerAuth auth = PlayerAuth.builder().name(name)
|
||||
.lastLogin(1501597979L)
|
||||
.build();
|
||||
given(playerCache.getAuth(name)).willReturn(auth);
|
||||
|
||||
// when
|
||||
Instant result = api.getLastLoginTime(name);
|
||||
|
||||
// then
|
||||
assertThat(result, not(nullValue()));
|
||||
assertThat(result, equalTo(Instant.ofEpochMilli(1501597979L)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleNullLastLoginTime() {
|
||||
// given
|
||||
String name = "John";
|
||||
PlayerAuth auth = PlayerAuth.builder().name(name)
|
||||
.lastLogin(null)
|
||||
.build();
|
||||
given(dataSource.getAuth(name)).willReturn(auth);
|
||||
|
||||
// when
|
||||
Instant result = api.getLastLoginTime(name);
|
||||
|
||||
// then
|
||||
assertThat(result, nullValue());
|
||||
verify(dataSource).getAuth(name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnNullForUnavailablePlayer() {
|
||||
// given
|
||||
|
||||
+4
-2
@@ -15,6 +15,8 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.containsStringIgnoringCase;
|
||||
import static org.hamcrest.Matchers.equalToIgnoringCase;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -55,7 +57,7 @@ public class RecentPlayersCommandTest {
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString("Recently logged in players")));
|
||||
verify(sender).sendMessage("- Hannah (08:09 AM, 11 Nov with IP 11.11.11.11)");
|
||||
verify(sender).sendMessage("- MATT (11:15 PM, 09 Nov with IP 22.11.22.33)");
|
||||
verify(sender).sendMessage(argThat(equalToIgnoringCase("- Hannah (08:09 AM, 11 Nov with IP 11.11.11.11)")));
|
||||
verify(sender).sendMessage(argThat(equalToIgnoringCase("- MATT (11:15 PM, 09 Nov with IP 22.11.22.33)")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import fr.xephi.authme.datasource.DataSourceResult;
|
||||
import fr.xephi.authme.mail.EmailService;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.PasswordRecoveryService;
|
||||
import fr.xephi.authme.service.RecoveryCodeService;
|
||||
@@ -22,6 +23,7 @@ import org.mockito.Mock;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static fr.xephi.authme.service.BukkitServiceTestHelper.setBukkitServiceToRunTaskAsynchronously;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
@@ -63,6 +65,9 @@ public class RecoverEmailCommandTest {
|
||||
@Mock
|
||||
private RecoveryCodeService recoveryCodeService;
|
||||
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@BeforeClass
|
||||
public static void initLogger() {
|
||||
TestHelper.setupLogger();
|
||||
@@ -179,6 +184,7 @@ public class RecoverEmailCommandTest {
|
||||
String code = "a94f37";
|
||||
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true);
|
||||
given(recoveryCodeService.generateCode(name)).willReturn(code);
|
||||
setBukkitServiceToRunTaskAsynchronously(bukkitService);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(email.toUpperCase()));
|
||||
@@ -201,6 +207,7 @@ public class RecoverEmailCommandTest {
|
||||
String email = "vulture@example.com";
|
||||
given(dataSource.getEmail(name)).willReturn(DataSourceResult.of(email));
|
||||
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(false);
|
||||
setBukkitServiceToRunTaskAsynchronously(bukkitService);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(email));
|
||||
|
||||
@@ -107,14 +107,14 @@ public class LimboPersistenceTest {
|
||||
Player player = mock(Player.class);
|
||||
Logger logger = TestHelper.setupLogger();
|
||||
LimboPersistenceHandler handler = getHandler();
|
||||
doThrow(IllegalAccessException.class).when(handler).getLimboPlayer(player);
|
||||
doThrow(RuntimeException.class).when(handler).getLimboPlayer(player);
|
||||
|
||||
// when
|
||||
LimboPlayer result = limboPersistence.getLimboPlayer(player);
|
||||
|
||||
// then
|
||||
assertThat(result, nullValue());
|
||||
verify(logger).warning(argThat(containsString("[IllegalAccessException]")));
|
||||
verify(logger).warning(argThat(containsString("[RuntimeException]")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package fr.xephi.authme.security.crypts;
|
||||
|
||||
/**
|
||||
* Test for {@link CmwCrypt}.
|
||||
*/
|
||||
public class CmwCryptTest extends AbstractEncryptionMethodTest {
|
||||
|
||||
public CmwCryptTest() {
|
||||
super(new CmwCrypt(),
|
||||
"1619d7adc23f4f633f11014d2f22b7d8", // password
|
||||
"c651798d2d9da38f86654107ae60c86a", // PassWord1
|
||||
"1fff869a744700cdb623a403c46e93ea", // &^%te$t?Pw@_
|
||||
"6436230e0effff37af79302147319dda"); // âË_3(íù*
|
||||
}
|
||||
}
|
||||
@@ -117,12 +117,6 @@ public class UtilsTest {
|
||||
assertThat(Utils.isCollectionEmpty(null), equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnCoreCount() {
|
||||
// given / when / then
|
||||
assertThat(Utils.getCoreCount(), greaterThan(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldLogAndSendWarning() {
|
||||
// given
|
||||
|
||||
Reference in New Issue
Block a user