Merge branch 'master' of https://github.com/AuthMe/AuthMeReloaded into 1141-optional-additional-2fa-auth
This commit is contained in:
@@ -30,21 +30,9 @@ public class CodeClimateConfigTest {
|
||||
assertThat(excludePaths, not(empty()));
|
||||
removeTestsExclusionOrThrow(excludePaths);
|
||||
for (String path : excludePaths) {
|
||||
verifySourceFileExists(path);
|
||||
}
|
||||
}
|
||||
|
||||
private static void verifySourceFileExists(String path) {
|
||||
// Note ljacqu 20170323: In the future, we could have legitimate exclusions that don't fulfill these checks,
|
||||
// in which case this test needs to be adapted accordingly.
|
||||
if (!path.startsWith(TestHelper.SOURCES_FOLDER)) {
|
||||
fail("Unexpected path '" + path + "': expected to start with sources folder");
|
||||
} else if (!path.endsWith(".java")) {
|
||||
fail("Expected path '" + path + "' to end with '.java'");
|
||||
}
|
||||
|
||||
if (!new File(path).exists()) {
|
||||
fail("Path '" + path + "' does not exist!");
|
||||
if (!new File(path).exists()) {
|
||||
fail("Path '" + path + "' does not exist!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.command.help.HelpMessagesService;
|
||||
import fr.xephi.authme.service.HelpTranslationGenerator;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
/**
|
||||
* Test for {@link UpdateHelpMessagesCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class UpdateHelpMessagesCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private UpdateHelpMessagesCommand command;
|
||||
|
||||
@Mock
|
||||
private HelpTranslationGenerator helpTranslationGenerator;
|
||||
@Mock
|
||||
private HelpMessagesService helpMessagesService;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldUpdateHelpMessage() throws IOException {
|
||||
// given
|
||||
File updatedFile = new File("some/path/help_xx.yml");
|
||||
given(helpTranslationGenerator.updateHelpFile()).willReturn(updatedFile);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.emptyList());
|
||||
|
||||
// then
|
||||
verify(helpMessagesService).reloadMessagesFile();
|
||||
verify(sender).sendMessage("Successfully updated the help file 'help_xx.yml'");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCatchAndReportException() throws IOException {
|
||||
// given
|
||||
given(helpTranslationGenerator.updateHelpFile()).willThrow(new IOException("Couldn't do the thing"));
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.emptyList());
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage("Could not update help file: Couldn't do the thing");
|
||||
verifyZeroInteractions(helpMessagesService);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package fr.xephi.authme.message;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.command.help.HelpSection;
|
||||
import fr.xephi.authme.util.ExceptionUtils;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -85,7 +86,7 @@ public class YamlTextFileCheckerTest {
|
||||
errors.add("Message for '" + mandatoryKey + "' is empty");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
errors.add("Could not load file: " + StringUtils.formatException(e));
|
||||
errors.add("Could not load file: " + ExceptionUtils.formatException(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import fr.xephi.authme.process.register.executors.RegistrationMethod;
|
||||
import fr.xephi.authme.process.register.executors.TwoFactorRegisterParams;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -21,11 +20,11 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.only;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -108,7 +107,7 @@ public class AsyncRegisterTest {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void shouldStopForFailedExecutorCheck() {
|
||||
public void shouldStopForCanceledEvent() {
|
||||
// given
|
||||
String name = "edbert";
|
||||
Player player = mockPlayerWithName(name);
|
||||
@@ -116,14 +115,13 @@ public class AsyncRegisterTest {
|
||||
given(playerCache.isAuthenticated(name)).willReturn(false);
|
||||
given(commonService.getProperty(RegistrationSettings.IS_ENABLED)).willReturn(true);
|
||||
given(dataSource.isAuthAvailable(name)).willReturn(false);
|
||||
given(commonService.getProperty(PluginSettings.USE_ASYNC_TASKS)).willReturn(true);
|
||||
RegistrationExecutor executor = mock(RegistrationExecutor.class);
|
||||
TwoFactorRegisterParams params = TwoFactorRegisterParams.of(player);
|
||||
singletonStoreWillReturn(registrationExecutorStore, executor);
|
||||
doAnswer((Answer<Void>) invocation -> {
|
||||
((AuthMeAsyncPreRegisterEvent) invocation.getArgument(0)).setCanRegister(false);
|
||||
return null;
|
||||
}).when(bukkitService).callEvent(any(AuthMeAsyncPreRegisterEvent.class));
|
||||
|
||||
AuthMeAsyncPreRegisterEvent canceledEvent = new AuthMeAsyncPreRegisterEvent(player, true);
|
||||
canceledEvent.setCanRegister(false);
|
||||
given(bukkitService.createAndCallEvent(any(Function.class))).willReturn(canceledEvent);
|
||||
|
||||
// when
|
||||
asyncRegister.register(RegistrationMethod.TWO_FACTOR_REGISTRATION, params);
|
||||
@@ -134,7 +132,7 @@ public class AsyncRegisterTest {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void shouldStopForCancelledEvent() {
|
||||
public void shouldStopForFailedExecutorCheck() {
|
||||
// given
|
||||
String name = "edbert";
|
||||
Player player = mockPlayerWithName(name);
|
||||
@@ -143,12 +141,14 @@ public class AsyncRegisterTest {
|
||||
given(commonService.getProperty(RegistrationSettings.IS_ENABLED)).willReturn(true);
|
||||
given(commonService.getProperty(RestrictionSettings.MAX_REGISTRATION_PER_IP)).willReturn(0);
|
||||
given(dataSource.isAuthAvailable(name)).willReturn(false);
|
||||
given(commonService.getProperty(PluginSettings.USE_ASYNC_TASKS)).willReturn(true);
|
||||
RegistrationExecutor executor = mock(RegistrationExecutor.class);
|
||||
TwoFactorRegisterParams params = TwoFactorRegisterParams.of(player);
|
||||
given(executor.isRegistrationAdmitted(params)).willReturn(false);
|
||||
singletonStoreWillReturn(registrationExecutorStore, executor);
|
||||
|
||||
given(bukkitService.createAndCallEvent(any(Function.class)))
|
||||
.willReturn(new AuthMeAsyncPreRegisterEvent(player, false));
|
||||
|
||||
// when
|
||||
asyncRegister.register(RegistrationMethod.TWO_FACTOR_REGISTRATION, params);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package fr.xephi.authme.security;
|
||||
|
||||
import ch.jalu.injector.Injector;
|
||||
import ch.jalu.injector.InjectorBuilder;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.security.crypts.Argon2;
|
||||
import fr.xephi.authme.security.crypts.EncryptionMethod;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
@@ -40,6 +41,7 @@ public class HashAlgorithmIntegrationTest {
|
||||
given(settings.getProperty(SecuritySettings.PBKDF2_NUMBER_OF_ROUNDS)).willReturn(10_000);
|
||||
injector = new InjectorBuilder().addDefaultHandlers("fr.xephi.authme").create();
|
||||
injector.register(Settings.class, settings);
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -123,4 +123,13 @@ public class HashUtilsTest {
|
||||
assertThat(HashUtils.isValidBcryptHash("#2ae5fc78"), equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCompareStrings() {
|
||||
// given / when / then
|
||||
assertThat(HashUtils.isEqual("test", "test"), equalTo(true));
|
||||
assertThat(HashUtils.isEqual("test", "Test"), equalTo(false));
|
||||
assertThat(HashUtils.isEqual("1234", "1234."), equalTo(false));
|
||||
assertThat(HashUtils.isEqual("ພາສາຫວຽດນາມ", "ພາສາຫວຽດນາມ"), equalTo(true));
|
||||
assertThat(HashUtils.isEqual("test", "tëst"), equalTo(false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ import fr.xephi.authme.ReflectionTestUtils;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.ConcurrentModificationException;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -58,4 +60,16 @@ public class ExceptionUtilsTest {
|
||||
// given / when / then
|
||||
TestHelper.validateHasOnlyPrivateEmptyConstructor(ExceptionUtils.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFormatException() {
|
||||
// given
|
||||
MalformedURLException ex = new MalformedURLException("Unrecognized URL format");
|
||||
|
||||
// when
|
||||
String result = ExceptionUtils.formatException(ex);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo("[MalformedURLException]: Unrecognized URL format"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package fr.xephi.authme.util;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
@@ -63,18 +61,6 @@ public class StringUtilsTest {
|
||||
assertFalse(StringUtils.isEmpty(" test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFormatException() {
|
||||
// given
|
||||
MalformedURLException ex = new MalformedURLException("Unrecognized URL format");
|
||||
|
||||
// when
|
||||
String result = StringUtils.formatException(ex);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo("[MalformedURLException]: Unrecognized URL format"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetDifferenceWithNullString() {
|
||||
// given/when/then
|
||||
|
||||
Reference in New Issue
Block a user