Merge branch 'master' into 745-captcha-login-message
This commit is contained in:
@@ -19,9 +19,8 @@ import fr.xephi.authme.task.purge.PurgeService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginLoader;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
@@ -29,13 +28,12 @@ import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static fr.xephi.authme.settings.TestSettingsMigrationServices.alwaysFulfilled;
|
||||
import static fr.xephi.authme.settings.properties.AuthMeSettingsRetriever.buildConfigurationData;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
@@ -50,9 +48,6 @@ import static org.mockito.Mockito.mock;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AuthMeInitializationTest {
|
||||
|
||||
@Mock
|
||||
private PluginLoader pluginLoader;
|
||||
|
||||
@Mock
|
||||
private Server server;
|
||||
|
||||
@@ -61,7 +56,6 @@ public class AuthMeInitializationTest {
|
||||
|
||||
private AuthMe authMe;
|
||||
private File dataFolder;
|
||||
private File settingsFile;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
@@ -74,13 +68,13 @@ public class AuthMeInitializationTest {
|
||||
@Before
|
||||
public void initAuthMe() throws IOException {
|
||||
dataFolder = temporaryFolder.newFolder();
|
||||
settingsFile = new File(dataFolder, "config.yml");
|
||||
File settingsFile = new File(dataFolder, "config.yml");
|
||||
JavaPluginLoader pluginLoader = new JavaPluginLoader(server);
|
||||
Files.copy(TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "config.test.yml"), settingsFile);
|
||||
|
||||
// Mock / wire various Bukkit components
|
||||
given(server.getLogger()).willReturn(mock(Logger.class));
|
||||
ReflectionTestUtils.setField(Bukkit.class, null, "server", server);
|
||||
given(server.getScheduler()).willReturn(mock(BukkitScheduler.class));
|
||||
given(server.getPluginManager()).willReturn(pluginManager);
|
||||
|
||||
// PluginDescriptionFile is final: need to create a sample one
|
||||
@@ -88,14 +82,14 @@ public class AuthMeInitializationTest {
|
||||
"AuthMe", "N/A", AuthMe.class.getCanonicalName());
|
||||
|
||||
// Initialize AuthMe
|
||||
authMe = new AuthMe(pluginLoader, server, descriptionFile, dataFolder, null);
|
||||
authMe = new AuthMe(pluginLoader, descriptionFile, dataFolder, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldInitializeAllServices() {
|
||||
// given
|
||||
Settings settings =
|
||||
new Settings(dataFolder, mock(PropertyResource.class), alwaysFulfilled(), buildConfigurationData());
|
||||
new Settings(dataFolder, mock(PropertyResource.class), null, buildConfigurationData());
|
||||
|
||||
Injector injector = new InjectorBuilder().addDefaultHandlers("fr.xephi.authme").create();
|
||||
injector.provide(DataFolder.class, dataFolder);
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -26,8 +26,8 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -18,8 +18,8 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -29,18 +29,18 @@ import static fr.xephi.authme.command.FoundResultStatus.UNKNOWN_LABEL;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyList;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyListOf;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link CommandHandler}.
|
||||
@@ -85,7 +85,7 @@ public class CommandHandlerTest {
|
||||
given(injector.newInstance(any(Class.class))).willAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Class<?> clazz = (Class<?>) invocation.getArguments()[0];
|
||||
Class<?> clazz = invocation.getArgument(0);
|
||||
if (ExecutableCommand.class.isAssignableFrom(clazz)) {
|
||||
Class<? extends ExecutableCommand> commandClass = (Class<? extends ExecutableCommand>) clazz;
|
||||
ExecutableCommand mock = mock(commandClass);
|
||||
@@ -108,7 +108,7 @@ public class CommandHandlerTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
doReturn(TestLoginCommand.class).when(command).getExecutableCommand();
|
||||
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class)))
|
||||
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyList()))
|
||||
.willReturn(new FoundCommandResult(command, asList("Authme", "Login"), asList("myPass"), 0.0, SUCCESS));
|
||||
|
||||
// when
|
||||
@@ -129,7 +129,7 @@ public class CommandHandlerTest {
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class)))
|
||||
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyList()))
|
||||
.willReturn(new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.0, NO_PERMISSION));
|
||||
|
||||
// when
|
||||
@@ -148,7 +148,7 @@ public class CommandHandlerTest {
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyList())).willReturn(
|
||||
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.0, INCORRECT_ARGUMENTS));
|
||||
given(permissionsManager.hasPermission(sender, command.getPermission())).willReturn(true);
|
||||
|
||||
@@ -170,7 +170,7 @@ public class CommandHandlerTest {
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyList())).willReturn(
|
||||
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.0, INCORRECT_ARGUMENTS));
|
||||
given(permissionsManager.hasPermission(sender, command.getPermission())).willReturn(false);
|
||||
|
||||
@@ -192,7 +192,7 @@ public class CommandHandlerTest {
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyList())).willReturn(
|
||||
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.0, MISSING_BASE_COMMAND));
|
||||
|
||||
// when
|
||||
@@ -212,7 +212,7 @@ public class CommandHandlerTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(command.getLabels()).willReturn(Collections.singletonList("test_cmd"));
|
||||
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyList())).willReturn(
|
||||
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.01, UNKNOWN_LABEL));
|
||||
|
||||
// when
|
||||
@@ -237,8 +237,7 @@ public class CommandHandlerTest {
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(command.getLabels()).willReturn(Collections.singletonList("test_cmd"));
|
||||
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyList())).willReturn(
|
||||
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 1.0, UNKNOWN_LABEL));
|
||||
|
||||
// when
|
||||
@@ -263,7 +262,7 @@ public class CommandHandlerTest {
|
||||
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
doReturn(TestRegisterCommand.class).when(command).getExecutableCommand();
|
||||
given(commandMapper.mapPartsToCommand(eq(sender), anyListOf(String.class)))
|
||||
given(commandMapper.mapPartsToCommand(eq(sender), anyList()))
|
||||
.willReturn(new FoundCommandResult(command, asList("AuthMe", "REGISTER"), asList("testArg"), 0.0, SUCCESS));
|
||||
|
||||
// when
|
||||
|
||||
@@ -28,9 +28,10 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -257,7 +258,7 @@ public class CommandMapperTest {
|
||||
// given
|
||||
List<String> parts = asList("email", "helptest", "arg1");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
|
||||
given(permissionsManager.hasPermission(eq(sender), isNull())).willReturn(true);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import com.github.authme.configme.properties.Property;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.message.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Test for {@link CommandService}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CommandServiceTest {
|
||||
|
||||
@InjectMocks
|
||||
private CommandService commandService;
|
||||
@Mock
|
||||
private Messages messages;
|
||||
@Mock
|
||||
private Settings settings;
|
||||
@Mock
|
||||
private ValidationService validationService;
|
||||
|
||||
@Test
|
||||
public void shouldSendMessage() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
commandService.send(sender, MessageKey.INVALID_EMAIL);
|
||||
|
||||
// then
|
||||
verify(messages).send(sender, MessageKey.INVALID_EMAIL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSendMessageWithReplacements() {
|
||||
// given
|
||||
CommandSender sender = mock(Player.class);
|
||||
|
||||
// when
|
||||
commandService.send(sender, MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE, "10");
|
||||
|
||||
// then
|
||||
verify(messages).send(sender, MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE, "10");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRetrieveMessage() {
|
||||
// given
|
||||
MessageKey key = MessageKey.USAGE_CAPTCHA;
|
||||
String[] givenMessages = new String[]{"Lorem ipsum...", "Test line test"};
|
||||
given(messages.retrieve(key)).willReturn(givenMessages);
|
||||
|
||||
// when
|
||||
String[] result = commandService.retrieveMessage(key);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(givenMessages));
|
||||
verify(messages).retrieve(key);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRetrieveProperty() {
|
||||
// given
|
||||
Property<Integer> property = SecuritySettings.CAPTCHA_LENGTH;
|
||||
given(settings.getProperty(property)).willReturn(7);
|
||||
|
||||
// when
|
||||
int result = commandService.getProperty(property);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(7));
|
||||
verify(settings).getProperty(property);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnSettings() {
|
||||
// given/when
|
||||
Settings result = commandService.getSettings();
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(settings));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldValidateEmail() {
|
||||
// given
|
||||
String email = "test@example.tld";
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
|
||||
// when
|
||||
boolean result = commandService.validateEmail(email);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
||||
verify(validationService).validateEmail(email);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCheckIfEmailCanBeUsed() {
|
||||
// given
|
||||
String email = "mail@example.com";
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(validationService.isEmailFreeForRegistration(email, sender))
|
||||
.willReturn(true);
|
||||
|
||||
// when
|
||||
boolean result = commandService.isEmailFreeForRegistration(email, sender);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
||||
verify(validationService).isEmailFreeForRegistration(email, sender);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,10 +10,10 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link PlayerCommand}.
|
||||
@@ -27,7 +27,7 @@ public class PlayerCommandTest {
|
||||
PlayerCommandImpl command = new PlayerCommandImpl();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
command.executeCommand(sender, Collections.emptyList());
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString("only for players")));
|
||||
@@ -54,7 +54,7 @@ public class PlayerCommandTest {
|
||||
PlayerCommandWithAlt command = new PlayerCommandWithAlt();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
command.executeCommand(sender, Collections.emptyList());
|
||||
|
||||
// then
|
||||
verify(sender, times(1)).sendMessage(argThat(containsString("use /authme test <command> instead")));
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -28,13 +28,13 @@ import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link HelpCommand}.
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -20,8 +20,8 @@ import java.util.List;
|
||||
import static fr.xephi.authme.TestHelper.runInnerRunnable;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -36,7 +36,7 @@ public class AccountsCommandTest {
|
||||
@InjectMocks
|
||||
private AccountsCommand command;
|
||||
@Mock
|
||||
private CommandService service;
|
||||
private CommonService service;
|
||||
@Mock
|
||||
private DataSource dataSource;
|
||||
@Mock
|
||||
@@ -83,7 +83,6 @@ public class AccountsCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
List<String> arguments = Collections.singletonList("SomeUser");
|
||||
given(dataSource.getAuth("someuser")).willReturn(mock(PlayerAuth.class));
|
||||
given(dataSource.getAllAuthsByIp(anyString())).willReturn(Collections.<String>emptyList());
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, arguments);
|
||||
|
||||
+4
-5
@@ -3,12 +3,12 @@ package fr.xephi.authme.command.executable.authme;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.service.ValidationService.ValidationResult;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -17,13 +17,13 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static fr.xephi.authme.TestHelper.runOptionallyAsyncTask;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -39,7 +39,7 @@ public class ChangePasswordAdminCommandTest {
|
||||
private ChangePasswordAdminCommand command;
|
||||
|
||||
@Mock
|
||||
private CommandService service;
|
||||
private CommonService service;
|
||||
|
||||
@Mock
|
||||
private PasswordSecurity passwordSecurity;
|
||||
@@ -84,7 +84,6 @@ public class ChangePasswordAdminCommandTest {
|
||||
String player = "player";
|
||||
String password = "password";
|
||||
given(playerCache.isAuthenticated(player)).willReturn(false);
|
||||
given(dataSource.getAuth(player)).willReturn(null);
|
||||
given(validationService.validatePassword(password, player)).willReturn(new ValidationResult());
|
||||
|
||||
// when
|
||||
|
||||
@@ -2,10 +2,10 @@ package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import ch.jalu.injector.Injector;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.datasource.converter.Converter;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -13,7 +13,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@@ -23,14 +23,14 @@ import java.util.Set;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link ConverterCommand}.
|
||||
@@ -42,7 +42,7 @@ public class ConverterCommandTest {
|
||||
private ConverterCommand command;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@@ -7,18 +7,18 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link FirstSpawnCommand}.
|
||||
|
||||
+10
-12
@@ -10,17 +10,16 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link ForceLoginCommand}.
|
||||
@@ -44,7 +43,7 @@ public class ForceLoginCommandTest {
|
||||
public void shouldRejectOfflinePlayer() {
|
||||
// given
|
||||
String playerName = "Bobby";
|
||||
Player player = mockPlayer(false, playerName);
|
||||
Player player = mockPlayer(false);
|
||||
given(bukkitService.getPlayerExact(playerName)).willReturn(player);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
@@ -53,7 +52,7 @@ public class ForceLoginCommandTest {
|
||||
|
||||
// then
|
||||
verify(bukkitService).getPlayerExact(playerName);
|
||||
verify(sender).sendMessage(argThat(equalTo("Player needs to be online!")));
|
||||
verify(sender).sendMessage("Player needs to be online!");
|
||||
verifyZeroInteractions(management);
|
||||
}
|
||||
|
||||
@@ -69,7 +68,7 @@ public class ForceLoginCommandTest {
|
||||
|
||||
// then
|
||||
verify(bukkitService).getPlayerExact(playerName);
|
||||
verify(sender).sendMessage(argThat(equalTo("Player needs to be online!")));
|
||||
verify(sender).sendMessage("Player needs to be online!");
|
||||
verifyZeroInteractions(management);
|
||||
}
|
||||
|
||||
@@ -77,7 +76,7 @@ public class ForceLoginCommandTest {
|
||||
public void shouldRejectPlayerWithMissingPermission() {
|
||||
// given
|
||||
String playerName = "testTest";
|
||||
Player player = mockPlayer(true, playerName);
|
||||
Player player = mockPlayer(true);
|
||||
given(bukkitService.getPlayerExact(playerName)).willReturn(player);
|
||||
given(permissionsManager.hasPermission(player, PlayerPermission.CAN_LOGIN_BE_FORCED)).willReturn(false);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
@@ -95,7 +94,7 @@ public class ForceLoginCommandTest {
|
||||
public void shouldForceLoginPlayer() {
|
||||
// given
|
||||
String playerName = "tester23";
|
||||
Player player = mockPlayer(true, playerName);
|
||||
Player player = mockPlayer(true);
|
||||
given(bukkitService.getPlayerExact(playerName)).willReturn(player);
|
||||
given(permissionsManager.hasPermission(player, PlayerPermission.CAN_LOGIN_BE_FORCED)).willReturn(true);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
@@ -112,24 +111,23 @@ public class ForceLoginCommandTest {
|
||||
public void shouldForceLoginSenderSelf() {
|
||||
// given
|
||||
String senderName = "tester23";
|
||||
Player player = mockPlayer(true, senderName);
|
||||
Player player = mockPlayer(true);
|
||||
given(bukkitService.getPlayerExact(senderName)).willReturn(player);
|
||||
given(permissionsManager.hasPermission(player, PlayerPermission.CAN_LOGIN_BE_FORCED)).willReturn(true);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(sender.getName()).willReturn(senderName);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
command.executeCommand(sender, Collections.emptyList());
|
||||
|
||||
// then
|
||||
verify(bukkitService).getPlayerExact(senderName);
|
||||
verify(management).forceLogin(player);
|
||||
}
|
||||
|
||||
private static Player mockPlayer(boolean isOnline, String name) {
|
||||
private static Player mockPlayer(boolean isOnline) {
|
||||
Player player = mock(Player.class);
|
||||
given(player.isOnline()).willReturn(isOnline);
|
||||
given(player.getName()).willReturn(name);
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link GetEmailCommand}.
|
||||
@@ -32,7 +32,7 @@ public class GetEmailCommandTest {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Mock
|
||||
private CommandService service;
|
||||
private CommonService service;
|
||||
|
||||
@Test
|
||||
public void shouldReportUnknownUser() {
|
||||
|
||||
@@ -8,17 +8,17 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link GetIpCommand}.
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
@@ -39,7 +39,7 @@ public class LastLoginCommandTest {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Mock
|
||||
private CommandService service;
|
||||
private CommonService service;
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
+4
-4
@@ -1,14 +1,14 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.task.purge.PurgeService;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.task.purge.PurgeService;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@@ -16,11 +16,11 @@ import java.util.Set;
|
||||
|
||||
import static com.google.common.collect.Sets.newHashSet;
|
||||
import static org.hamcrest.Matchers.arrayContainingInAnyOrder;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link PurgeBannedPlayersCommand}.
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
@@ -17,11 +17,11 @@ import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link PurgeCommand}.
|
||||
|
||||
+4
-4
@@ -1,24 +1,24 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link PurgeLastPositionCommand}.
|
||||
@@ -33,7 +33,7 @@ public class PurgeLastPositionCommandTest {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Mock
|
||||
private CommandService service;
|
||||
private CommonService service;
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
+5
-5
@@ -3,12 +3,12 @@ package fr.xephi.authme.command.executable.authme;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.limbo.LimboCache;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.service.ValidationService.ValidationResult;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -19,15 +19,15 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static fr.xephi.authme.TestHelper.runSyncTaskFromOptionallyAsyncTask;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -51,7 +51,7 @@ public class RegisterAdminCommandTest {
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private ValidationService validationService;
|
||||
@@ -164,7 +164,7 @@ public class RegisterAdminCommandTest {
|
||||
Player player = mock(Player.class);
|
||||
given(bukkitService.getPlayerExact(user)).willReturn(player);
|
||||
String kickForAdminRegister = "Admin registered you -- log in again";
|
||||
given(commandService.retrieveSingle(MessageKey.KICK_FOR_ADMIN_REGISTER)).willReturn(kickForAdminRegister);
|
||||
given(commandService.retrieveSingleMessage(MessageKey.KICK_FOR_ADMIN_REGISTER)).willReturn(kickForAdminRegister);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
|
||||
@@ -3,13 +3,13 @@ package fr.xephi.authme.command.executable.authme;
|
||||
import ch.jalu.injector.Injector;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSourceType;
|
||||
import fr.xephi.authme.initialization.Reloadable;
|
||||
import fr.xephi.authme.initialization.SettingsDependent;
|
||||
import fr.xephi.authme.output.LogLevel;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.output.LogLevel;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
@@ -21,7 +21,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -29,13 +29,13 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link ReloadCommand}.
|
||||
@@ -59,7 +59,7 @@ public class ReloadCommandTest {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpLogger() {
|
||||
|
||||
@@ -2,22 +2,23 @@ package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static fr.xephi.authme.TestHelper.runOptionallyAsyncTask;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -37,27 +38,30 @@ public class SetEmailCommandTest {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Mock
|
||||
private ValidationService validationService;
|
||||
|
||||
@Test
|
||||
public void shouldRejectInvalidMail() {
|
||||
// given
|
||||
String user = "somebody";
|
||||
String email = "some.test@example.org";
|
||||
given(commandService.validateEmail(email)).willReturn(false);
|
||||
given(validationService.validateEmail(email)).willReturn(false);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(user, email));
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(email);
|
||||
verify(validationService).validateEmail(email);
|
||||
verify(commandService).send(sender, MessageKey.INVALID_EMAIL);
|
||||
verifyZeroInteractions(dataSource);
|
||||
}
|
||||
@@ -67,7 +71,7 @@ public class SetEmailCommandTest {
|
||||
// given
|
||||
String user = "nonexistent";
|
||||
String email = "mail@example.com";
|
||||
given(commandService.validateEmail(email)).willReturn(true);
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
given(dataSource.getAuth(user)).willReturn(null);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
@@ -76,7 +80,7 @@ public class SetEmailCommandTest {
|
||||
runOptionallyAsyncTask(bukkitService);
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(email);
|
||||
verify(validationService).validateEmail(email);
|
||||
verify(dataSource).getAuth(user);
|
||||
verify(commandService).send(sender, MessageKey.UNKNOWN_USER);
|
||||
verifyNoMoreInteractions(dataSource);
|
||||
@@ -87,20 +91,20 @@ public class SetEmailCommandTest {
|
||||
// given
|
||||
String user = "someone";
|
||||
String email = "mail@example.com";
|
||||
given(commandService.validateEmail(email)).willReturn(true);
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(dataSource.getAuth(user)).willReturn(auth);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(commandService.isEmailFreeForRegistration(email, sender)).willReturn(false);
|
||||
given(validationService.isEmailFreeForRegistration(email, sender)).willReturn(false);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(user, email));
|
||||
runOptionallyAsyncTask(bukkitService);
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(email);
|
||||
verify(validationService).validateEmail(email);
|
||||
verify(dataSource).getAuth(user);
|
||||
verify(commandService).isEmailFreeForRegistration(email, sender);
|
||||
verify(validationService).isEmailFreeForRegistration(email, sender);
|
||||
verify(commandService).send(sender, MessageKey.EMAIL_ALREADY_USED_ERROR);
|
||||
verifyNoMoreInteractions(dataSource);
|
||||
verifyZeroInteractions(auth);
|
||||
@@ -111,11 +115,11 @@ public class SetEmailCommandTest {
|
||||
// given
|
||||
String user = "Bobby";
|
||||
String email = "new-addr@example.org";
|
||||
given(commandService.validateEmail(email)).willReturn(true);
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(dataSource.getAuth(user)).willReturn(auth);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(commandService.isEmailFreeForRegistration(email, sender)).willReturn(true);
|
||||
given(validationService.isEmailFreeForRegistration(email, sender)).willReturn(true);
|
||||
given(dataSource.updateEmail(auth)).willReturn(false);
|
||||
|
||||
// when
|
||||
@@ -123,9 +127,9 @@ public class SetEmailCommandTest {
|
||||
runOptionallyAsyncTask(bukkitService);
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(email);
|
||||
verify(validationService).validateEmail(email);
|
||||
verify(dataSource).getAuth(user);
|
||||
verify(commandService).isEmailFreeForRegistration(email, sender);
|
||||
verify(validationService).isEmailFreeForRegistration(email, sender);
|
||||
verify(commandService).send(sender, MessageKey.ERROR);
|
||||
verify(dataSource).updateEmail(auth);
|
||||
verifyNoMoreInteractions(dataSource);
|
||||
@@ -136,11 +140,11 @@ public class SetEmailCommandTest {
|
||||
// given
|
||||
String user = "Bobby";
|
||||
String email = "new-addr@example.org";
|
||||
given(commandService.validateEmail(email)).willReturn(true);
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(dataSource.getAuth(user)).willReturn(auth);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(commandService.isEmailFreeForRegistration(email, sender)).willReturn(true);
|
||||
given(validationService.isEmailFreeForRegistration(email, sender)).willReturn(true);
|
||||
given(dataSource.updateEmail(auth)).willReturn(true);
|
||||
given(playerCache.getAuth(user)).willReturn(null);
|
||||
|
||||
@@ -149,9 +153,9 @@ public class SetEmailCommandTest {
|
||||
runOptionallyAsyncTask(bukkitService);
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(email);
|
||||
verify(validationService).validateEmail(email);
|
||||
verify(dataSource).getAuth(user);
|
||||
verify(commandService).isEmailFreeForRegistration(email, sender);
|
||||
verify(validationService).isEmailFreeForRegistration(email, sender);
|
||||
verify(commandService).send(sender, MessageKey.EMAIL_CHANGED_SUCCESS);
|
||||
verify(dataSource).updateEmail(auth);
|
||||
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
|
||||
@@ -163,11 +167,11 @@ public class SetEmailCommandTest {
|
||||
// given
|
||||
String user = "Bobby";
|
||||
String email = "new-addr@example.org";
|
||||
given(commandService.validateEmail(email)).willReturn(true);
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(dataSource.getAuth(user)).willReturn(auth);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(commandService.isEmailFreeForRegistration(email, sender)).willReturn(true);
|
||||
given(validationService.isEmailFreeForRegistration(email, sender)).willReturn(true);
|
||||
given(dataSource.updateEmail(auth)).willReturn(true);
|
||||
given(playerCache.getAuth(user)).willReturn(mock(PlayerAuth.class));
|
||||
|
||||
@@ -176,9 +180,9 @@ public class SetEmailCommandTest {
|
||||
runOptionallyAsyncTask(bukkitService);
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(email);
|
||||
verify(validationService).validateEmail(email);
|
||||
verify(dataSource).getAuth(user);
|
||||
verify(commandService).isEmailFreeForRegistration(email, sender);
|
||||
verify(validationService).isEmailFreeForRegistration(email, sender);
|
||||
verify(commandService).send(sender, MessageKey.EMAIL_CHANGED_SUCCESS);
|
||||
verify(dataSource).updateEmail(auth);
|
||||
verify(playerCache).updatePlayer(auth);
|
||||
|
||||
+2
-2
@@ -7,15 +7,15 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link SetFirstSpawnCommand}.
|
||||
|
||||
@@ -7,15 +7,15 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link SetSpawnCommand}.
|
||||
@@ -39,7 +39,7 @@ public class SetSpawnCommandTest {
|
||||
given(spawnLoader.setSpawn(location)).willReturn(true);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
command.executeCommand(player, Collections.emptyList());
|
||||
|
||||
// then
|
||||
verify(spawnLoader).setSpawn(location);
|
||||
@@ -55,7 +55,7 @@ public class SetSpawnCommandTest {
|
||||
given(spawnLoader.setSpawn(location)).willReturn(false);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
command.executeCommand(player, Collections.emptyList());
|
||||
|
||||
// then
|
||||
verify(spawnLoader).setSpawn(location);
|
||||
|
||||
@@ -7,18 +7,18 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link SpawnCommand}.
|
||||
|
||||
+4
-4
@@ -1,26 +1,26 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.service.AntiBotService;
|
||||
import fr.xephi.authme.command.CommandMapper;
|
||||
import fr.xephi.authme.command.FoundCommandResult;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import fr.xephi.authme.service.AntiBotService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link SwitchAntiBotCommand}.
|
||||
|
||||
+3
-5
@@ -1,17 +1,17 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -33,7 +33,7 @@ public class UnregisterAdminCommandTest {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
@@ -61,7 +61,6 @@ public class UnregisterAdminCommandTest {
|
||||
// given
|
||||
String user = "personaNonGrata";
|
||||
given(dataSource.isAuthAvailable(user)).willReturn(true);
|
||||
given(dataSource.removeAuth(user)).willReturn(false);
|
||||
Player player = mock(Player.class);
|
||||
given(bukkitService.getPlayerExact(user)).willReturn(player);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
@@ -80,7 +79,6 @@ public class UnregisterAdminCommandTest {
|
||||
// given
|
||||
String user = "personaNonGrata";
|
||||
given(dataSource.isAuthAvailable(user)).willReturn(true);
|
||||
given(dataSource.removeAuth(user)).willReturn(false);
|
||||
given(bukkitService.getPlayerExact(user)).willReturn(null);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -37,7 +37,7 @@ public class CaptchaCommandTest {
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private LimboCache limboCache;
|
||||
|
||||
+5
-18
@@ -1,36 +1,32 @@
|
||||
package fr.xephi.authme.command.executable.changepassword;
|
||||
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.service.ValidationService.ValidationResult;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link ChangePasswordCommand}.
|
||||
@@ -42,7 +38,7 @@ public class ChangePasswordCommandTest {
|
||||
private ChangePasswordCommand command;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private PlayerCache playerCache;
|
||||
@@ -53,22 +49,13 @@ public class ChangePasswordCommandTest {
|
||||
@Mock
|
||||
private Management management;
|
||||
|
||||
@Before
|
||||
public void setSettings() {
|
||||
when(commandService.getProperty(SecuritySettings.MIN_PASSWORD_LENGTH)).thenReturn(2);
|
||||
when(commandService.getProperty(SecuritySettings.MAX_PASSWORD_LENGTH)).thenReturn(50);
|
||||
// Only allow passwords with alphanumerical characters for the test
|
||||
when(commandService.getProperty(RestrictionSettings.ALLOWED_PASSWORD_REGEX)).thenReturn("[a-zA-Z0-9]+");
|
||||
when(commandService.getProperty(SecuritySettings.UNSAFE_PASSWORDS)).thenReturn(Collections.<String>emptyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectNonPlayerSender() {
|
||||
// given
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new ArrayList<String>());
|
||||
command.executeCommand(sender, Collections.emptyList());
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString("only for players")));
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package fr.xephi.authme.command.executable.email;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -10,12 +10,11 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
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;
|
||||
@@ -30,7 +29,7 @@ public class AddEmailCommandTest {
|
||||
private AddEmailCommand command;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private Management management;
|
||||
@@ -41,7 +40,7 @@ public class AddEmailCommandTest {
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new ArrayList<String>());
|
||||
command.executeCommand(sender, Collections.emptyList());
|
||||
|
||||
// then
|
||||
verifyZeroInteractions(management);
|
||||
@@ -52,7 +51,6 @@ public class AddEmailCommandTest {
|
||||
// given
|
||||
Player sender = mock(Player.class);
|
||||
String email = "mail@example";
|
||||
given(commandService.validateEmail(email)).willReturn(true);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(email, email));
|
||||
@@ -66,7 +64,6 @@ public class AddEmailCommandTest {
|
||||
// given
|
||||
Player sender = mock(Player.class);
|
||||
String email = "asdfasdf@example.com";
|
||||
given(commandService.validateEmail(email)).willReturn(true);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(email, "wrongConf"));
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
+11
-14
@@ -3,15 +3,14 @@ package fr.xephi.authme.command.executable.email;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.mail.SendMailSSL;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.RecoveryCodeService;
|
||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -19,17 +18,17 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static fr.xephi.authme.AuthMeMatchers.stringWithLength;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.only;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -51,7 +50,7 @@ public class RecoverEmailCommandTest {
|
||||
private PasswordSecurity passwordSecurity;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private DataSource dataSource;
|
||||
@@ -169,13 +168,10 @@ public class RecoverEmailCommandTest {
|
||||
Player sender = mock(Player.class);
|
||||
given(sender.getName()).willReturn(name);
|
||||
given(sendMailSsl.hasAllInformation()).willReturn(true);
|
||||
given(sendMailSsl.sendRecoveryCode(anyString(), anyString(), anyString())).willReturn(true);
|
||||
given(playerCache.isAuthenticated(name)).willReturn(false);
|
||||
String email = "v@example.com";
|
||||
given(dataSource.getAuth(name)).willReturn(newAuthWithEmail(email));
|
||||
int codeLength = 7;
|
||||
given(commandService.getProperty(SecuritySettings.RECOVERY_CODE_LENGTH)).willReturn(codeLength);
|
||||
int hoursValid = 12;
|
||||
given(commandService.getProperty(SecuritySettings.RECOVERY_CODE_HOURS_VALID)).willReturn(hoursValid);
|
||||
String code = "a94f37";
|
||||
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true);
|
||||
given(recoveryCodeService.generateCode(name)).willReturn(code);
|
||||
@@ -202,7 +198,6 @@ public class RecoverEmailCommandTest {
|
||||
String email = "vulture@example.com";
|
||||
PlayerAuth auth = newAuthWithEmail(email);
|
||||
given(dataSource.getAuth(name)).willReturn(auth);
|
||||
given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(20);
|
||||
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true);
|
||||
given(recoveryCodeService.isCodeValid(name, "bogus")).willReturn(false);
|
||||
|
||||
@@ -223,6 +218,7 @@ public class RecoverEmailCommandTest {
|
||||
Player sender = mock(Player.class);
|
||||
given(sender.getName()).willReturn(name);
|
||||
given(sendMailSsl.hasAllInformation()).willReturn(true);
|
||||
given(sendMailSsl.sendPasswordMail(anyString(), anyString(), anyString())).willReturn(true);
|
||||
given(playerCache.isAuthenticated(name)).willReturn(false);
|
||||
String email = "vulture@example.com";
|
||||
String code = "A6EF3AC8";
|
||||
@@ -230,7 +226,7 @@ public class RecoverEmailCommandTest {
|
||||
given(dataSource.getAuth(name)).willReturn(auth);
|
||||
given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(20);
|
||||
given(passwordSecurity.computeHash(anyString(), eq(name)))
|
||||
.willAnswer(invocation -> new HashedPassword((String) invocation.getArguments()[0]));
|
||||
.willAnswer(invocation -> new HashedPassword(invocation.getArgument(0)));
|
||||
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true);
|
||||
given(recoveryCodeService.isCodeValid(name, code)).willReturn(true);
|
||||
|
||||
@@ -257,13 +253,14 @@ public class RecoverEmailCommandTest {
|
||||
Player sender = mock(Player.class);
|
||||
given(sender.getName()).willReturn(name);
|
||||
given(sendMailSsl.hasAllInformation()).willReturn(true);
|
||||
given(sendMailSsl.sendPasswordMail(anyString(), anyString(), anyString())).willReturn(true);
|
||||
given(playerCache.isAuthenticated(name)).willReturn(false);
|
||||
String email = "shark@example.org";
|
||||
PlayerAuth auth = newAuthWithEmail(email);
|
||||
given(dataSource.getAuth(name)).willReturn(auth);
|
||||
given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(20);
|
||||
given(passwordSecurity.computeHash(anyString(), eq(name)))
|
||||
.willAnswer(invocation -> new HashedPassword((String) invocation.getArguments()[0]));
|
||||
.willAnswer(invocation -> new HashedPassword(invocation.getArgument(0)));
|
||||
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(false);
|
||||
|
||||
// when
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package fr.xephi.authme.command.executable.email;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -30,7 +30,7 @@ public class ShowEmailCommandTest {
|
||||
private ShowEmailCommand command;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@@ -8,17 +8,17 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link LoginCommand}.
|
||||
|
||||
@@ -8,16 +8,16 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link LogoutCommand}.
|
||||
|
||||
+17
-17
@@ -1,11 +1,12 @@
|
||||
package fr.xephi.authme.command.executable.register;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.mail.SendMailSSL;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
@@ -19,20 +20,19 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static fr.xephi.authme.AuthMeMatchers.stringWithLength;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link RegisterCommand}.
|
||||
@@ -44,7 +44,7 @@ public class RegisterCommandTest {
|
||||
private RegisterCommand command;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private Management management;
|
||||
@@ -52,6 +52,9 @@ public class RegisterCommandTest {
|
||||
@Mock
|
||||
private SendMailSSL sendMailSsl;
|
||||
|
||||
@Mock
|
||||
private ValidationService validationService;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
TestHelper.setupLogger();
|
||||
@@ -70,7 +73,7 @@ public class RegisterCommandTest {
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new ArrayList<String>());
|
||||
command.executeCommand(sender, Collections.emptyList());
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString("Player only!")));
|
||||
@@ -84,7 +87,7 @@ public class RegisterCommandTest {
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
command.executeCommand(player, Collections.emptyList());
|
||||
|
||||
// then
|
||||
verify(management).performRegister(player, "", "", true);
|
||||
@@ -97,7 +100,7 @@ public class RegisterCommandTest {
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
command.executeCommand(player, Collections.emptyList());
|
||||
|
||||
// then
|
||||
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
|
||||
@@ -154,11 +157,10 @@ public class RegisterCommandTest {
|
||||
public void shouldRejectInvalidEmail() {
|
||||
// given
|
||||
String playerMail = "player@example.org";
|
||||
given(commandService.validateEmail(playerMail)).willReturn(false);
|
||||
given(validationService.validateEmail(playerMail)).willReturn(false);
|
||||
|
||||
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
|
||||
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
|
||||
given(sendMailSsl.hasAllInformation()).willReturn(true);
|
||||
Player player = mock(Player.class);
|
||||
|
||||
@@ -166,7 +168,7 @@ public class RegisterCommandTest {
|
||||
command.executeCommand(player, Arrays.asList(playerMail, playerMail));
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(playerMail);
|
||||
verify(validationService).validateEmail(playerMail);
|
||||
verify(commandService).send(player, MessageKey.INVALID_EMAIL);
|
||||
verifyZeroInteractions(management);
|
||||
}
|
||||
@@ -175,11 +177,10 @@ public class RegisterCommandTest {
|
||||
public void shouldRejectInvalidEmailConfirmation() {
|
||||
// given
|
||||
String playerMail = "bobber@bobby.org";
|
||||
given(commandService.validateEmail(playerMail)).willReturn(true);
|
||||
given(validationService.validateEmail(playerMail)).willReturn(true);
|
||||
|
||||
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
|
||||
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
|
||||
given(sendMailSsl.hasAllInformation()).willReturn(true);
|
||||
Player player = mock(Player.class);
|
||||
|
||||
@@ -196,13 +197,12 @@ public class RegisterCommandTest {
|
||||
public void shouldPerformEmailRegistration() {
|
||||
// given
|
||||
String playerMail = "asfd@lakjgre.lds";
|
||||
given(commandService.validateEmail(playerMail)).willReturn(true);
|
||||
given(validationService.validateEmail(playerMail)).willReturn(true);
|
||||
int passLength = 7;
|
||||
given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(passLength);
|
||||
|
||||
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
|
||||
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
|
||||
given(sendMailSsl.hasAllInformation()).willReturn(true);
|
||||
Player player = mock(Player.class);
|
||||
|
||||
@@ -210,7 +210,7 @@ public class RegisterCommandTest {
|
||||
command.executeCommand(player, Arrays.asList(playerMail, playerMail));
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(playerMail);
|
||||
verify(validationService).validateEmail(playerMail);
|
||||
verify(sendMailSsl).hasAllInformation();
|
||||
verify(management).performRegister(eq(player), argThat(stringWithLength(passLength)), eq(playerMail), eq(true));
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,15 +1,15 @@
|
||||
package fr.xephi.authme.command.executable.unregister;
|
||||
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -31,7 +31,7 @@ public class UnregisterCommandTest {
|
||||
private Management management;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@@ -21,8 +21,8 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
|
||||
/**
|
||||
* Test for {@link HelpMessagesService}.
|
||||
|
||||
@@ -39,9 +39,9 @@ import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
|
||||
@@ -5,7 +5,7 @@ import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@ import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.data.TempbanManager.TimedCounter;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.message.Messages;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
@@ -25,8 +25,8 @@ import static org.hamcrest.Matchers.anEmptyMap;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -37,11 +37,11 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -105,7 +105,7 @@ public abstract class AbstractResourceClosingTest {
|
||||
given(settings.getProperty(any(Property.class))).willAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) {
|
||||
return ((Property) invocation.getArguments()[0]).getDefaultValue();
|
||||
return ((Property<?>) invocation.getArguments()[0]).getDefaultValue();
|
||||
}
|
||||
});
|
||||
TestHelper.setupLogger();
|
||||
|
||||
@@ -3,8 +3,6 @@ package fr.xephi.authme.datasource;
|
||||
import com.google.common.io.Files;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.FlatFile;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -4,9 +4,6 @@ import com.github.authme.configme.properties.Property;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.datasource.AbstractDataSourceIntegrationTest;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.MySQL;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import org.junit.After;
|
||||
@@ -22,7 +19,7 @@ import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
@@ -3,9 +3,6 @@ package fr.xephi.authme.datasource;
|
||||
import com.github.authme.configme.properties.Property;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.AbstractDataSourceIntegrationTest;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.SQLite;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import org.junit.After;
|
||||
@@ -25,7 +22,7 @@ import java.sql.Statement;
|
||||
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
+3
-3
@@ -13,10 +13,9 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.only;
|
||||
@@ -24,6 +23,7 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link AbstractDataSourceConverter}.
|
||||
|
||||
@@ -23,11 +23,11 @@ import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link CrazyLoginConverter}.
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -24,8 +24,8 @@ import java.util.concurrent.Executors;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -16,11 +16,11 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static fr.xephi.authme.listener.EventCancelVerifier.withServiceMock;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.only;
|
||||
|
||||
@@ -8,12 +8,12 @@ import fr.xephi.authme.message.Messages;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.permission.PlayerStatePermission;
|
||||
import fr.xephi.authme.service.AntiBotService;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
@@ -27,7 +27,7 @@ import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -175,10 +175,7 @@ public class OnJoinVerifierTest {
|
||||
|
||||
@Test
|
||||
public void shouldNotKickRegisteredPlayer() throws FailedVerificationException {
|
||||
// given
|
||||
given(settings.getProperty(RestrictionSettings.KICK_NON_REGISTERED)).willReturn(true);
|
||||
|
||||
// when
|
||||
// given / when / then
|
||||
onJoinVerifier.checkKickNonRegistered(true);
|
||||
}
|
||||
|
||||
@@ -206,7 +203,6 @@ public class OnJoinVerifierTest {
|
||||
@Test
|
||||
public void shouldRejectTooLongName() throws FailedVerificationException {
|
||||
// given
|
||||
given(settings.getProperty(RestrictionSettings.MIN_NICKNAME_LENGTH)).willReturn(4);
|
||||
given(settings.getProperty(RestrictionSettings.MAX_NICKNAME_LENGTH)).willReturn(8);
|
||||
given(settings.getProperty(RestrictionSettings.ALLOWED_NICKNAME_CHARACTERS)).willReturn("[a-zA-Z0-9]+");
|
||||
onJoinVerifier.reload(); // @PostConstruct method
|
||||
@@ -324,7 +320,6 @@ public class OnJoinVerifierTest {
|
||||
// given
|
||||
Player player = newPlayerWithName("MyPlayer");
|
||||
PlayerAuth auth = null;
|
||||
given(settings.getProperty(RegistrationSettings.PREVENT_OTHER_CASE)).willReturn(true);
|
||||
|
||||
// when
|
||||
onJoinVerifier.checkNameCasing(player, auth);
|
||||
@@ -381,14 +376,27 @@ public class OnJoinVerifierTest {
|
||||
Player player = newPlayerWithName("Bobby");
|
||||
boolean isAuthAvailable = false;
|
||||
given(permissionsManager.hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT)).willReturn(false);
|
||||
given(antiBotService.shouldKick(isAuthAvailable)).willReturn(false);
|
||||
given(antiBotService.shouldKick()).willReturn(false);
|
||||
|
||||
// when
|
||||
onJoinVerifier.checkAntibot(player, isAuthAvailable);
|
||||
|
||||
// then
|
||||
verify(permissionsManager).hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT);
|
||||
verify(antiBotService).shouldKick(isAuthAvailable);
|
||||
verify(antiBotService).shouldKick();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAllowUserWithAuth() throws FailedVerificationException {
|
||||
// given
|
||||
Player player = newPlayerWithName("Lacey");
|
||||
boolean isAuthAvailable = true;
|
||||
|
||||
// when
|
||||
onJoinVerifier.checkAntibot(player, isAuthAvailable);
|
||||
|
||||
// then
|
||||
verifyZeroInteractions(permissionsManager, antiBotService);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -397,13 +405,13 @@ public class OnJoinVerifierTest {
|
||||
Player player = newPlayerWithName("Steward");
|
||||
boolean isAuthAvailable = false;
|
||||
given(permissionsManager.hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT)).willReturn(true);
|
||||
given(antiBotService.shouldKick(isAuthAvailable)).willReturn(true);
|
||||
|
||||
// when
|
||||
onJoinVerifier.checkAntibot(player, isAuthAvailable);
|
||||
|
||||
// then
|
||||
verify(permissionsManager).hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT);
|
||||
verifyZeroInteractions(antiBotService);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -412,7 +420,7 @@ public class OnJoinVerifierTest {
|
||||
Player player = newPlayerWithName("D3");
|
||||
boolean isAuthAvailable = false;
|
||||
given(permissionsManager.hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT)).willReturn(false);
|
||||
given(antiBotService.shouldKick(isAuthAvailable)).willReturn(true);
|
||||
given(antiBotService.shouldKick()).willReturn(true);
|
||||
|
||||
// when / then
|
||||
try {
|
||||
@@ -420,7 +428,7 @@ public class OnJoinVerifierTest {
|
||||
fail("Expected exception to be thrown");
|
||||
} catch (FailedVerificationException e) {
|
||||
verify(permissionsManager).hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT);
|
||||
verify(antiBotService).shouldKick(isAuthAvailable);
|
||||
verify(antiBotService).shouldKick();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -447,7 +455,6 @@ public class OnJoinVerifierTest {
|
||||
// given
|
||||
String ip = "192.168.0.1";
|
||||
given(settings.getProperty(ProtectionSettings.ENABLE_PROTECTION)).willReturn(true);
|
||||
given(settings.getProperty(ProtectionSettings.ENABLE_PROTECTION_REGISTERED)).willReturn(false);
|
||||
given(validationService.isCountryAdmitted(ip)).willReturn(true);
|
||||
|
||||
// when
|
||||
@@ -477,7 +484,6 @@ public class OnJoinVerifierTest {
|
||||
// given
|
||||
String ip = "192.168.40.0";
|
||||
given(settings.getProperty(ProtectionSettings.ENABLE_PROTECTION)).willReturn(true);
|
||||
given(settings.getProperty(ProtectionSettings.ENABLE_PROTECTION_REGISTERED)).willReturn(true);
|
||||
given(validationService.isCountryAdmitted(ip)).willReturn(false);
|
||||
|
||||
// expect
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package fr.xephi.authme.listener;
|
||||
|
||||
import org.bukkit.event.entity.EntityAirChangeEvent;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static fr.xephi.authme.listener.EventCancelVerifier.withServiceMock;
|
||||
|
||||
/**
|
||||
* Test for {@link PlayerListener111}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PlayerListener111Test {
|
||||
|
||||
@InjectMocks
|
||||
private PlayerListener111 listener;
|
||||
|
||||
@Mock
|
||||
private ListenerService listenerService;
|
||||
|
||||
@Test
|
||||
public void shouldCancelEvent() {
|
||||
withServiceMock(listenerService)
|
||||
.check(listener::onPlayerAirChange, EntityAirChangeEvent.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static fr.xephi.authme.listener.EventCancelVerifier.withServiceMock;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static fr.xephi.authme.listener.EventCancelVerifier.withServiceMock;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static fr.xephi.authme.listener.EventCancelVerifier.withServiceMock;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
@@ -50,9 +50,9 @@ import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -379,7 +379,6 @@ public class PlayerListenerTest {
|
||||
Location to = new Location(world, 199, 70, 199);
|
||||
PlayerMoveEvent event = spy(new PlayerMoveEvent(player, from, to));
|
||||
given(listenerService.shouldCancelEvent(player)).willReturn(true);
|
||||
given(settings.getProperty(RestrictionSettings.REMOVE_SPEED)).willReturn(false);
|
||||
|
||||
// when
|
||||
listener.onPlayerMove(event);
|
||||
@@ -565,7 +564,6 @@ public class PlayerListenerTest {
|
||||
verify(onJoinVerifier).checkKickNonRegistered(true);
|
||||
verify(onJoinVerifier).checkNameCasing(player, auth);
|
||||
verify(onJoinVerifier).checkPlayerCountry(true, ip);
|
||||
verify(antiBotService).handlePlayerJoin();
|
||||
verify(teleportationService).teleportOnJoin(player);
|
||||
verifyNoModifyingCalls(event);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
package fr.xephi.authme.mail;
|
||||
|
||||
import ch.jalu.injector.testing.BeforeInjecting;
|
||||
import ch.jalu.injector.testing.DelayedInjectionRunner;
|
||||
import ch.jalu.injector.testing.InjectDelayed;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import org.apache.commons.mail.EmailException;
|
||||
import org.apache.commons.mail.HtmlEmail;
|
||||
import org.bukkit.Server;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Test for {@link SendMailSSL}.
|
||||
*/
|
||||
@RunWith(DelayedInjectionRunner.class)
|
||||
public class SendMailSSLTest {
|
||||
|
||||
@InjectDelayed
|
||||
private SendMailSSL sendMailSSL;
|
||||
|
||||
@Mock
|
||||
private Settings settings;
|
||||
@Mock
|
||||
private Server server;
|
||||
@DataFolder
|
||||
private File dataFolder;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@BeforeClass
|
||||
public static void initLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@BeforeInjecting
|
||||
public void initFields() throws IOException {
|
||||
dataFolder = temporaryFolder.newFolder();
|
||||
given(server.getServerName()).willReturn("serverName");
|
||||
given(settings.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("mail@example.org");
|
||||
given(settings.getProperty(EmailSettings.MAIL_PASSWORD)).willReturn("pass1234");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveAllInformation() {
|
||||
// given / when / then
|
||||
assertThat(sendMailSSL.hasAllInformation(), equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSendPasswordMail() throws EmailException {
|
||||
// given
|
||||
given(settings.getPasswordEmailMessage())
|
||||
.willReturn("Hi <playername />, your new password for <servername /> is <generatedpass />");
|
||||
given(settings.getProperty(EmailSettings.PASSWORD_AS_IMAGE)).willReturn(false);
|
||||
SendMailSSL sendMailSpy = spy(sendMailSSL);
|
||||
HtmlEmail email = mock(HtmlEmail.class);
|
||||
doReturn(email).when(sendMailSpy).initializeMail(anyString());
|
||||
doReturn(true).when(sendMailSpy).sendEmail(anyString(), any(HtmlEmail.class));
|
||||
|
||||
// when
|
||||
boolean result = sendMailSpy.sendPasswordMail("Player", "user@example.com", "new_password");
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
||||
verify(sendMailSpy).initializeMail("user@example.com");
|
||||
ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class);
|
||||
verify(sendMailSpy).sendEmail(messageCaptor.capture(), eq(email));
|
||||
assertThat(messageCaptor.getValue(),
|
||||
equalTo("Hi Player, your new password for serverName is new_password"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleMailCreationError() throws EmailException {
|
||||
// given
|
||||
SendMailSSL sendMailSpy = spy(sendMailSSL);
|
||||
doThrow(EmailException.class).when(sendMailSpy).initializeMail(anyString());
|
||||
|
||||
// when
|
||||
boolean result = sendMailSpy.sendPasswordMail("Player", "user@example.com", "new_password");
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(false));
|
||||
verify(sendMailSpy).initializeMail("user@example.com");
|
||||
verify(sendMailSpy, never()).sendEmail(anyString(), any(HtmlEmail.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleMailSendingFailure() throws EmailException {
|
||||
// given
|
||||
given(settings.getPasswordEmailMessage()).willReturn("Hi <playername />, your new pass is <generatedpass />");
|
||||
given(settings.getProperty(EmailSettings.PASSWORD_AS_IMAGE)).willReturn(false);
|
||||
SendMailSSL sendMailSpy = spy(sendMailSSL);
|
||||
HtmlEmail email = mock(HtmlEmail.class);
|
||||
doReturn(email).when(sendMailSpy).initializeMail(anyString());
|
||||
doReturn(false).when(sendMailSpy).sendEmail(anyString(), any(HtmlEmail.class));
|
||||
|
||||
// when
|
||||
boolean result = sendMailSpy.sendPasswordMail("bobby", "user@example.com", "myPassw0rd");
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(false));
|
||||
verify(sendMailSpy).initializeMail("user@example.com");
|
||||
ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class);
|
||||
verify(sendMailSpy).sendEmail(messageCaptor.capture(), eq(email));
|
||||
assertThat(messageCaptor.getValue(), equalTo("Hi bobby, your new pass is myPassw0rd"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSendRecoveryCode() throws EmailException {
|
||||
// given
|
||||
given(settings.getProperty(SecuritySettings.RECOVERY_CODE_HOURS_VALID)).willReturn(7);
|
||||
given(settings.getRecoveryCodeEmailMessage())
|
||||
.willReturn("Hi <playername />, your code on <servername /> is <recoverycode /> (valid <hoursvalid /> hours)");
|
||||
SendMailSSL sendMailSpy = spy(sendMailSSL);
|
||||
HtmlEmail email = mock(HtmlEmail.class);
|
||||
doReturn(email).when(sendMailSpy).initializeMail(anyString());
|
||||
doReturn(true).when(sendMailSpy).sendEmail(anyString(), any(HtmlEmail.class));
|
||||
|
||||
// when
|
||||
boolean result = sendMailSpy.sendRecoveryCode("Timmy", "tim@example.com", "12C56A");
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
||||
verify(sendMailSpy).initializeMail("tim@example.com");
|
||||
ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class);
|
||||
verify(sendMailSpy).sendEmail(messageCaptor.capture(), eq(email));
|
||||
assertThat(messageCaptor.getValue(), equalTo("Hi Timmy, your code on serverName is 12C56A (valid 7 hours)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleMailCreationErrorForRecoveryCode() throws EmailException {
|
||||
// given
|
||||
SendMailSSL sendMailSpy = spy(sendMailSSL);
|
||||
doThrow(EmailException.class).when(sendMailSpy).initializeMail(anyString());
|
||||
|
||||
// when
|
||||
boolean result = sendMailSpy.sendRecoveryCode("Player", "player@example.org", "ABC1234");
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(false));
|
||||
verify(sendMailSpy).initializeMail("player@example.org");
|
||||
verify(sendMailSpy, never()).sendEmail(anyString(), any(HtmlEmail.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleFailureToSendRecoveryCode() throws EmailException {
|
||||
// given
|
||||
given(settings.getProperty(SecuritySettings.RECOVERY_CODE_HOURS_VALID)).willReturn(7);
|
||||
given(settings.getRecoveryCodeEmailMessage()).willReturn("Hi <playername />, your code is <recoverycode />");
|
||||
SendMailSSL sendMailSpy = spy(sendMailSSL);
|
||||
HtmlEmail email = mock(HtmlEmail.class);
|
||||
doReturn(email).when(sendMailSpy).initializeMail(anyString());
|
||||
doReturn(false).when(sendMailSpy).sendEmail(anyString(), any(HtmlEmail.class));
|
||||
|
||||
// when
|
||||
boolean result = sendMailSpy.sendRecoveryCode("John", "user@example.com", "1DEF77");
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(false));
|
||||
verify(sendMailSpy).initializeMail("user@example.com");
|
||||
ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class);
|
||||
verify(sendMailSpy).sendEmail(messageCaptor.capture(), eq(email));
|
||||
assertThat(messageCaptor.getValue(), equalTo("Hi John, your code is 1DEF77"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateEmailObject() throws EmailException {
|
||||
// given
|
||||
given(settings.getProperty(EmailSettings.SMTP_PORT)).willReturn(465);
|
||||
String smtpHost = "mail.example.com";
|
||||
given(settings.getProperty(EmailSettings.SMTP_HOST)).willReturn(smtpHost);
|
||||
String senderMail = "sender@example.org";
|
||||
given(settings.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn(senderMail);
|
||||
String senderName = "Server administration";
|
||||
given(settings.getProperty(EmailSettings.MAIL_SENDER_NAME)).willReturn(senderName);
|
||||
|
||||
// when
|
||||
HtmlEmail email = sendMailSSL.initializeMail("recipient@example.com");
|
||||
|
||||
// then
|
||||
assertThat(email, not(nullValue()));
|
||||
assertThat(email.getToAddresses(), hasSize(1));
|
||||
assertThat(email.getToAddresses().get(0).getAddress(), equalTo("recipient@example.com"));
|
||||
assertThat(email.getFromAddress().getAddress(), equalTo(senderMail));
|
||||
assertThat(email.getFromAddress().getPersonal(), equalTo(senderName));
|
||||
assertThat(email.getHostName(), equalTo(smtpHost));
|
||||
assertThat(email.getSmtpPort(), equalTo("465"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateEmailObjectWithOAuth2() throws EmailException {
|
||||
// given
|
||||
given(settings.getProperty(EmailSettings.SMTP_PORT)).willReturn(587);
|
||||
given(settings.getProperty(EmailSettings.OAUTH2_TOKEN)).willReturn("oAuth2 token");
|
||||
String smtpHost = "mail.example.com";
|
||||
given(settings.getProperty(EmailSettings.SMTP_HOST)).willReturn(smtpHost);
|
||||
String senderMail = "sender@example.org";
|
||||
given(settings.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn(senderMail);
|
||||
|
||||
// when
|
||||
HtmlEmail email = sendMailSSL.initializeMail("recipient@example.com");
|
||||
|
||||
// then
|
||||
assertThat(email, not(nullValue()));
|
||||
assertThat(email.getToAddresses(), hasSize(1));
|
||||
assertThat(email.getToAddresses().get(0).getAddress(), equalTo("recipient@example.com"));
|
||||
assertThat(email.getFromAddress().getAddress(), equalTo(senderMail));
|
||||
assertThat(email.getHostName(), equalTo(smtpHost));
|
||||
assertThat(email.getSmtpPort(), equalTo("587"));
|
||||
|
||||
Properties mailProperties = email.getMailSession().getProperties();
|
||||
assertThat(mailProperties.getProperty("mail.smtp.auth.mechanisms"), equalTo("XOAUTH2"));
|
||||
assertThat(mailProperties.getProperty("mail.smtp.auth.plain.disable"), equalTo("true"));
|
||||
assertThat(mailProperties.getProperty(OAuth2SaslClientFactory.OAUTH_TOKEN_PROP), equalTo("oAuth2 token"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,14 +19,14 @@ import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link Messages}.
|
||||
@@ -160,7 +160,7 @@ public class MessagesIntegrationTest {
|
||||
messages.send(sender, key);
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(equalTo("Use /captcha THE_CAPTCHA to solve the captcha")));
|
||||
verify(sender).sendMessage("Use /captcha THE_CAPTCHA to solve the captcha");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static tools.utils.FileIoUtils.listFilesOrThrow;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
@@ -28,11 +29,7 @@ public class YamlTextFileCheckerTest {
|
||||
@BeforeClass
|
||||
public static void loadMessagesFiles() {
|
||||
File folder = TestHelper.getJarFile(MESSAGES_FOLDER);
|
||||
File[] files = folder.listFiles();
|
||||
if (files == null || files.length == 0) {
|
||||
throw new IllegalStateException("Could not read folder '" + folder.getName() + "'");
|
||||
}
|
||||
messageFiles = Arrays.asList(files);
|
||||
messageFiles = Arrays.asList(listFilesOrThrow(folder));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,17 +79,13 @@ public class YamlTextFileCheckerTest {
|
||||
* @param errors collection of errors to add to if the verification fails
|
||||
*/
|
||||
private void checkFile(File file, String mandatoryKey, List<String> errors) {
|
||||
String error = null;
|
||||
try {
|
||||
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(file);
|
||||
if (StringUtils.isEmpty(configuration.getString(mandatoryKey))) {
|
||||
error = "Message for '" + mandatoryKey + "' is empty";
|
||||
errors.add("Message for '" + mandatoryKey + "' is empty");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
error = "Could not load file: " + StringUtils.formatException(e);
|
||||
}
|
||||
if (!StringUtils.isEmpty(error)) {
|
||||
errors.add(file.getName() + ": " + error);
|
||||
errors.add("Could not load file: " + StringUtils.formatException(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@ package fr.xephi.authme.permission;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import fr.xephi.authme.ClassCollector;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import org.bukkit.configuration.MemorySection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@@ -12,9 +15,11 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static fr.xephi.authme.TestHelper.getJarFile;
|
||||
import static org.junit.Assert.fail;
|
||||
@@ -24,10 +29,6 @@ import static org.junit.Assert.fail;
|
||||
*/
|
||||
public class PermissionConsistencyTest {
|
||||
|
||||
/** All classes defining permission nodes. */
|
||||
private static final Set<Class<? extends PermissionNode>> PERMISSION_CLASSES = ImmutableSet
|
||||
.of(PlayerPermission.class, AdminPermission.class, PlayerStatePermission.class);
|
||||
|
||||
/** Wildcard permissions (present in plugin.yml but not in the codebase). */
|
||||
private static final Set<String> PLUGIN_YML_PERMISSIONS_WILDCARDS =
|
||||
ImmutableSet.of("authme.admin.*", "authme.player.*", "authme.player.email");
|
||||
@@ -35,6 +36,9 @@ public class PermissionConsistencyTest {
|
||||
/** Name of the fields that make up a permission entry in plugin.yml. */
|
||||
private static final Set<String> PERMISSION_FIELDS = ImmutableSet.of("description", "default", "children");
|
||||
|
||||
/** All classes defining permission nodes. */
|
||||
private static List<Class<? extends PermissionNode>> permissionClasses;
|
||||
|
||||
/** All known PermissionNode objects. */
|
||||
private static List<PermissionNode> permissionNodes;
|
||||
|
||||
@@ -43,6 +47,10 @@ public class PermissionConsistencyTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void gatherPermissionNodes() {
|
||||
permissionClasses = new ClassCollector(TestHelper.SOURCES_FOLDER, TestHelper.PROJECT_ROOT + "permission")
|
||||
.collectClasses(PermissionNode.class).stream()
|
||||
.filter(clz -> !clz.isInterface())
|
||||
.collect(Collectors.toList());
|
||||
permissionNodes = getPermissionsFromClasses();
|
||||
pluginYmlPermissions = getPermissionsFromPluginYmlFile();
|
||||
}
|
||||
@@ -109,7 +117,7 @@ public class PermissionConsistencyTest {
|
||||
*/
|
||||
private static List<PermissionNode> getPermissionsFromClasses() {
|
||||
List<PermissionNode> nodes = new ArrayList<>();
|
||||
for (Class<? extends PermissionNode> clazz : PERMISSION_CLASSES) {
|
||||
for (Class<? extends PermissionNode> clazz : permissionClasses) {
|
||||
nodes.addAll(Arrays.<PermissionNode>asList(clazz.getEnumConstants()));
|
||||
}
|
||||
return Collections.unmodifiableList(nodes);
|
||||
@@ -163,15 +171,16 @@ public class PermissionConsistencyTest {
|
||||
// Replace ending .* in path if present, e.g. authme.player.* -> authme.player
|
||||
// Add ending '.' since we want all children to be children, i.e. authme.playertest would not be OK
|
||||
String root = definition.node.replaceAll("\\.\\*$", "") + ".";
|
||||
List<String> badChildren = new ArrayList<>();
|
||||
for (String child : definition.children) {
|
||||
if (!child.startsWith(root)) {
|
||||
badChildren.add(child);
|
||||
}
|
||||
Set<String> expectedChildren = permissionNodes.stream().map(PermissionNode::getNode)
|
||||
.filter(n -> n.startsWith(root)).collect(Collectors.toSet());
|
||||
Set<String> missingChildren = Sets.difference(expectedChildren, definition.children);
|
||||
Set<String> unexpectedChildren = Sets.difference(definition.children, expectedChildren);
|
||||
|
||||
if (!missingChildren.isEmpty()) {
|
||||
errorList.add("Node '" + definition.node + "' has missing children: " + missingChildren);
|
||||
}
|
||||
if (!badChildren.isEmpty()) {
|
||||
errorList.add("Permission '" + definition.node + "' has children that are not logically below it: "
|
||||
+ String.join(", ", badChildren));
|
||||
if (!unexpectedChildren.isEmpty()) {
|
||||
errorList.add("Node '" + definition.node + "' has unexpected children: " + unexpectedChildren);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +190,7 @@ public class PermissionConsistencyTest {
|
||||
private static final class PermissionDefinition {
|
||||
|
||||
private final String node;
|
||||
private final List<String> children;
|
||||
private final Set<String> children;
|
||||
private final DefaultPermission expectedDefault;
|
||||
|
||||
PermissionDefinition(MemorySection memorySection) {
|
||||
@@ -193,7 +202,7 @@ public class PermissionConsistencyTest {
|
||||
collectChildren((MemorySection) memorySection.get("children"), children);
|
||||
this.children = removeStart(memorySection.getCurrentPath() + ".children.", children);
|
||||
} else {
|
||||
this.children = Collections.emptyList();
|
||||
this.children = Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,6 +252,10 @@ public class PermissionConsistencyTest {
|
||||
if (entry.getValue() instanceof MemorySection) {
|
||||
collectChildren((MemorySection) entry.getValue(), children);
|
||||
} else if (entry.getValue() instanceof Boolean) {
|
||||
if (!Boolean.TRUE.equals(entry.getValue())) {
|
||||
throw new IllegalStateException("Child entry '" + entry.getKey()
|
||||
+ "' has unexpected value '" + entry.getValue() + "'");
|
||||
}
|
||||
children.add(parentSection.getCurrentPath() + "." + entry.getKey());
|
||||
} else {
|
||||
throw new IllegalStateException("Found child entry at '" + entry.getKey() + "' with value "
|
||||
@@ -258,8 +271,8 @@ public class PermissionConsistencyTest {
|
||||
* @param list the entries to modify
|
||||
* @return list with shortened entries
|
||||
*/
|
||||
private static List<String> removeStart(String start, List<String> list) {
|
||||
List<String> result = new ArrayList<>(list.size());
|
||||
private static Set<String> removeStart(String start, List<String> list) {
|
||||
Set<String> result = new HashSet<>(list.size());
|
||||
for (String entry : list) {
|
||||
result.add(entry.substring(start.length()));
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -62,7 +62,6 @@ public class PermissionsManagerTest {
|
||||
// given
|
||||
PermissionNode node = TestPermissions.WORLD_DOMINATION;
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(sender.isOp()).willReturn(true);
|
||||
|
||||
// when
|
||||
boolean result = permissionsManager.hasPermission(sender, node);
|
||||
@@ -116,7 +115,6 @@ public class PermissionsManagerTest {
|
||||
// given
|
||||
PermissionNode node = TestPermissions.WORLD_DOMINATION;
|
||||
Player player = mock(Player.class);
|
||||
given(player.isOp()).willReturn(true);
|
||||
|
||||
// when
|
||||
boolean result = permissionsManager.hasPermission(player, node);
|
||||
|
||||
@@ -23,15 +23,15 @@ public class PermissionsSystemTypeTest {
|
||||
List<String> pluginNames = new ArrayList<>(PermissionsSystemType.values().length);
|
||||
|
||||
for (PermissionsSystemType system : PermissionsSystemType.values()) {
|
||||
assertThat("Name for enum entry '" + system + "' is not null",
|
||||
system.getName(), not(nullValue()));
|
||||
assertThat("Display name for enum entry '" + system + "' is not null",
|
||||
system.getDisplayName(), not(nullValue()));
|
||||
assertThat("Plugin name for enum entry '" + system + "' is not null",
|
||||
system.getPluginName(), not(nullValue()));
|
||||
assertThat("Only one enum entry has name '" + system.getName() + "'",
|
||||
names, not(hasItem(system.getName())));
|
||||
assertThat("Only one enum entry has display name '" + system.getDisplayName() + "'",
|
||||
names, not(hasItem(system.getDisplayName())));
|
||||
assertThat("Only one enum entry has plugin name '" + system.getPluginName() + "'",
|
||||
pluginNames, not(hasItem(system.getPluginName())));
|
||||
names.add(system.getName());
|
||||
names.add(system.getDisplayName());
|
||||
pluginNames.add(system.getPluginName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -13,10 +14,10 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -40,7 +41,10 @@ public class AsyncAddEmailTest {
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@Mock
|
||||
private ProcessService service;
|
||||
private CommonService service;
|
||||
|
||||
@Mock
|
||||
private ValidationService validationService;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
@@ -57,8 +61,8 @@ public class AsyncAddEmailTest {
|
||||
given(auth.getEmail()).willReturn(null);
|
||||
given(playerCache.getAuth("tester")).willReturn(auth);
|
||||
given(dataSource.updateEmail(any(PlayerAuth.class))).willReturn(true);
|
||||
given(service.validateEmail(email)).willReturn(true);
|
||||
given(service.isEmailFreeForRegistration(email, player)).willReturn(true);
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
given(validationService.isEmailFreeForRegistration(email, player)).willReturn(true);
|
||||
|
||||
// when
|
||||
asyncAddEmail.addEmail(player, email);
|
||||
@@ -79,10 +83,9 @@ public class AsyncAddEmailTest {
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(auth.getEmail()).willReturn(null);
|
||||
given(playerCache.getAuth("tester")).willReturn(auth);
|
||||
given(dataSource.countAuthsByEmail(email)).willReturn(0);
|
||||
given(dataSource.updateEmail(any(PlayerAuth.class))).willReturn(false);
|
||||
given(service.validateEmail(email)).willReturn(true);
|
||||
given(service.isEmailFreeForRegistration(email, player)).willReturn(true);
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
given(validationService.isEmailFreeForRegistration(email, player)).willReturn(true);
|
||||
|
||||
// when
|
||||
asyncAddEmail.addEmail(player, email);
|
||||
@@ -118,7 +121,7 @@ public class AsyncAddEmailTest {
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(auth.getEmail()).willReturn(null);
|
||||
given(playerCache.getAuth("my_player")).willReturn(auth);
|
||||
given(service.validateEmail(email)).willReturn(false);
|
||||
given(validationService.validateEmail(email)).willReturn(false);
|
||||
|
||||
// when
|
||||
asyncAddEmail.addEmail(player, email);
|
||||
@@ -137,8 +140,8 @@ public class AsyncAddEmailTest {
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(auth.getEmail()).willReturn(null);
|
||||
given(playerCache.getAuth("testname")).willReturn(auth);
|
||||
given(service.validateEmail(email)).willReturn(true);
|
||||
given(service.isEmailFreeForRegistration(email, player)).willReturn(false);
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
given(validationService.isEmailFreeForRegistration(email, player)).willReturn(false);
|
||||
|
||||
// when
|
||||
asyncAddEmail.addEmail(player, email);
|
||||
|
||||
@@ -4,17 +4,18 @@ import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -39,7 +40,10 @@ public class AsyncChangeEmailTest {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Mock
|
||||
private ProcessService service;
|
||||
private CommonService service;
|
||||
|
||||
@Mock
|
||||
private ValidationService validationService;
|
||||
|
||||
@Test
|
||||
public void shouldAddEmail() {
|
||||
@@ -50,8 +54,8 @@ public class AsyncChangeEmailTest {
|
||||
PlayerAuth auth = authWithMail("old@mail.tld");
|
||||
given(playerCache.getAuth("bobby")).willReturn(auth);
|
||||
given(dataSource.updateEmail(auth)).willReturn(true);
|
||||
given(service.validateEmail(newEmail)).willReturn(true);
|
||||
given(service.isEmailFreeForRegistration(newEmail, player)).willReturn(true);
|
||||
given(validationService.validateEmail(newEmail)).willReturn(true);
|
||||
given(validationService.isEmailFreeForRegistration(newEmail, player)).willReturn(true);
|
||||
|
||||
// when
|
||||
process.changeEmail(player, "old@mail.tld", newEmail);
|
||||
@@ -71,8 +75,8 @@ public class AsyncChangeEmailTest {
|
||||
PlayerAuth auth = authWithMail("old@mail.tld");
|
||||
given(playerCache.getAuth("bobby")).willReturn(auth);
|
||||
given(dataSource.updateEmail(auth)).willReturn(false);
|
||||
given(service.validateEmail(newEmail)).willReturn(true);
|
||||
given(service.isEmailFreeForRegistration(newEmail, player)).willReturn(true);
|
||||
given(validationService.validateEmail(newEmail)).willReturn(true);
|
||||
given(validationService.isEmailFreeForRegistration(newEmail, player)).willReturn(true);
|
||||
|
||||
// when
|
||||
process.changeEmail(player, "old@mail.tld", newEmail);
|
||||
@@ -108,7 +112,7 @@ public class AsyncChangeEmailTest {
|
||||
given(playerCache.isAuthenticated("bobby")).willReturn(true);
|
||||
PlayerAuth auth = authWithMail("old@mail.tld");
|
||||
given(playerCache.getAuth("bobby")).willReturn(auth);
|
||||
given(service.validateEmail(newEmail)).willReturn(false);
|
||||
given(validationService.validateEmail(newEmail)).willReturn(false);
|
||||
|
||||
// when
|
||||
process.changeEmail(player, "old@mail.tld", newEmail);
|
||||
@@ -127,9 +131,7 @@ public class AsyncChangeEmailTest {
|
||||
given(playerCache.isAuthenticated("bobby")).willReturn(true);
|
||||
PlayerAuth auth = authWithMail("other@address.email");
|
||||
given(playerCache.getAuth("bobby")).willReturn(auth);
|
||||
given(service.validateEmail(newEmail)).willReturn(true);
|
||||
given(service.isEmailFreeForRegistration(newEmail, player)).willReturn(true);
|
||||
|
||||
given(validationService.validateEmail(newEmail)).willReturn(true);
|
||||
|
||||
// when
|
||||
process.changeEmail(player, "old@mail.tld", newEmail);
|
||||
@@ -148,8 +150,8 @@ public class AsyncChangeEmailTest {
|
||||
given(playerCache.isAuthenticated("username")).willReturn(true);
|
||||
PlayerAuth auth = authWithMail("old@example.com");
|
||||
given(playerCache.getAuth("username")).willReturn(auth);
|
||||
given(service.validateEmail(newEmail)).willReturn(true);
|
||||
given(service.isEmailFreeForRegistration(newEmail, player)).willReturn(false);
|
||||
given(validationService.validateEmail(newEmail)).willReturn(true);
|
||||
given(validationService.isEmailFreeForRegistration(newEmail, player)).willReturn(false);
|
||||
|
||||
// when
|
||||
process.changeEmail(player, "old@example.com", newEmail);
|
||||
|
||||
@@ -8,13 +8,13 @@ import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.permission.PlayerStatePermission;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.task.LimboPlayerTaskManager;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -23,7 +23,7 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -31,9 +31,9 @@ import java.util.Collection;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -56,7 +56,7 @@ public class AsynchronousLoginTest {
|
||||
@Mock
|
||||
private PlayerCache playerCache;
|
||||
@Mock
|
||||
private ProcessService processService;
|
||||
private CommonService commonService;
|
||||
@Mock
|
||||
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||
@Mock
|
||||
@@ -81,7 +81,7 @@ public class AsynchronousLoginTest {
|
||||
|
||||
// then
|
||||
verify(playerCache, only()).isAuthenticated(name);
|
||||
verify(processService).send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
verify(commonService).send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
verifyZeroInteractions(dataSource);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class AsynchronousLoginTest {
|
||||
|
||||
// then
|
||||
verify(playerCache, only()).isAuthenticated(name);
|
||||
verify(processService).send(player, MessageKey.USER_NOT_REGISTERED);
|
||||
verify(commonService).send(player, MessageKey.USER_NOT_REGISTERED);
|
||||
verify(dataSource, only()).getAuth(name);
|
||||
}
|
||||
|
||||
@@ -111,15 +111,15 @@ public class AsynchronousLoginTest {
|
||||
int groupId = 13;
|
||||
PlayerAuth auth = PlayerAuth.builder().name(name).groupId(groupId).build();
|
||||
given(dataSource.getAuth(name)).willReturn(auth);
|
||||
given(processService.getProperty(DatabaseSettings.MYSQL_COL_GROUP)).willReturn("group");
|
||||
given(processService.getProperty(HooksSettings.NON_ACTIVATED_USERS_GROUP)).willReturn(groupId);
|
||||
given(commonService.getProperty(DatabaseSettings.MYSQL_COL_GROUP)).willReturn("group");
|
||||
given(commonService.getProperty(HooksSettings.NON_ACTIVATED_USERS_GROUP)).willReturn(groupId);
|
||||
|
||||
// when
|
||||
asynchronousLogin.forceLogin(player);
|
||||
|
||||
// then
|
||||
verify(playerCache, only()).isAuthenticated(name);
|
||||
verify(processService).send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
|
||||
verify(commonService).send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
|
||||
verify(dataSource, only()).getAuth(name);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ public class AsynchronousLoginTest {
|
||||
given(playerCache.isAuthenticated(name)).willReturn(false);
|
||||
PlayerAuth auth = PlayerAuth.builder().name(name).build();
|
||||
given(dataSource.getAuth(name)).willReturn(auth);
|
||||
given(processService.getProperty(DatabaseSettings.MYSQL_COL_GROUP)).willReturn("");
|
||||
given(commonService.getProperty(DatabaseSettings.MYSQL_COL_GROUP)).willReturn("");
|
||||
doReturn(true).when(asynchronousLogin).hasReachedMaxLoggedInPlayersForIp(any(Player.class), anyString());
|
||||
|
||||
// when
|
||||
@@ -141,7 +141,7 @@ public class AsynchronousLoginTest {
|
||||
|
||||
// then
|
||||
verify(playerCache, only()).isAuthenticated(name);
|
||||
verify(processService).send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
verify(commonService).send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
verify(dataSource, only()).getAuth(name);
|
||||
verify(asynchronousLogin).hasReachedMaxLoggedInPlayersForIp(player, ip);
|
||||
}
|
||||
@@ -156,13 +156,13 @@ public class AsynchronousLoginTest {
|
||||
given(playerCache.isAuthenticated(name)).willReturn(false);
|
||||
PlayerAuth auth = PlayerAuth.builder().name(name).build();
|
||||
given(dataSource.getAuth(name)).willReturn(auth);
|
||||
given(processService.getProperty(DatabaseSettings.MYSQL_COL_GROUP)).willReturn("");
|
||||
given(processService.getProperty(PluginSettings.USE_ASYNC_TASKS)).willReturn(true);
|
||||
given(commonService.getProperty(DatabaseSettings.MYSQL_COL_GROUP)).willReturn("");
|
||||
given(commonService.getProperty(PluginSettings.USE_ASYNC_TASKS)).willReturn(true);
|
||||
doReturn(false).when(asynchronousLogin).hasReachedMaxLoggedInPlayersForIp(any(Player.class), anyString());
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
invocation.getArgumentAt(0, AuthMeAsyncPreLoginEvent.class).setCanLogin(false);
|
||||
((AuthMeAsyncPreLoginEvent) invocation.getArgument(0)).setCanLogin(false);
|
||||
return null;
|
||||
}
|
||||
}).when(bukkitService).callEvent(any(AuthMeAsyncPreLoginEvent.class));
|
||||
@@ -181,7 +181,7 @@ public class AsynchronousLoginTest {
|
||||
public void shouldPassMaxLoginPerIpCheck() {
|
||||
// given
|
||||
Player player = mockPlayer("Carl");
|
||||
given(processService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(2);
|
||||
given(commonService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(2);
|
||||
given(permissionsManager.hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)).willReturn(false);
|
||||
mockOnlinePlayersInBukkitService();
|
||||
|
||||
@@ -198,7 +198,7 @@ public class AsynchronousLoginTest {
|
||||
public void shouldSkipIpCheckForZeroThreshold() {
|
||||
// given
|
||||
Player player = mockPlayer("Fiona");
|
||||
given(processService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(0);
|
||||
given(commonService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(0);
|
||||
|
||||
// when
|
||||
boolean result = asynchronousLogin.hasReachedMaxLoggedInPlayersForIp(player, "192.168.0.1");
|
||||
@@ -212,7 +212,7 @@ public class AsynchronousLoginTest {
|
||||
public void shouldSkipIpCheckForPlayerWithMultipleAccountsPermission() {
|
||||
// given
|
||||
Player player = mockPlayer("Frank");
|
||||
given(processService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(1);
|
||||
given(commonService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(1);
|
||||
given(permissionsManager.hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)).willReturn(true);
|
||||
|
||||
// when
|
||||
@@ -228,7 +228,7 @@ public class AsynchronousLoginTest {
|
||||
public void shouldFailIpCheckForIpWithTooManyPlayersOnline() {
|
||||
// given
|
||||
Player player = mockPlayer("Ian");
|
||||
given(processService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(2);
|
||||
given(commonService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(2);
|
||||
given(permissionsManager.hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)).willReturn(false);
|
||||
mockOnlinePlayersInBukkitService();
|
||||
|
||||
@@ -271,7 +271,6 @@ public class AsynchronousLoginTest {
|
||||
// 192.168.0.0: france (offline)
|
||||
Player playerF = mockPlayer("france");
|
||||
TestHelper.mockPlayerIp(playerF, "192.168.0.0");
|
||||
given(dataSource.isLogged(playerF.getName())).willReturn(false);
|
||||
|
||||
Collection onlinePlayers = Arrays.asList(playerA, playerB, playerC, playerD, playerE, playerF);
|
||||
given(bukkitService.getOnlinePlayers()).willReturn(onlinePlayers);
|
||||
|
||||
@@ -8,14 +8,14 @@ import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.permission.AuthGroupHandler;
|
||||
import fr.xephi.authme.permission.AuthGroupType;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.TeleportationService;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.task.LimboPlayerTaskManager;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.TeleportationService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -23,10 +23,10 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.only;
|
||||
@@ -45,7 +45,7 @@ public class AsynchronousUnregisterTest {
|
||||
@Mock
|
||||
private DataSource dataSource;
|
||||
@Mock
|
||||
private ProcessService service;
|
||||
private CommonService service;
|
||||
@Mock
|
||||
private PasswordSecurity passwordSecurity;
|
||||
@Mock
|
||||
@@ -185,7 +185,6 @@ public class AsynchronousUnregisterTest {
|
||||
Player player = mock(Player.class);
|
||||
String name = "Frank21";
|
||||
given(player.getName()).willReturn(name);
|
||||
given(player.isOnline()).willReturn(true);
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(playerCache.getAuth(name)).willReturn(auth);
|
||||
HashedPassword password = new HashedPassword("password", "in_auth_obj");
|
||||
@@ -218,9 +217,6 @@ public class AsynchronousUnregisterTest {
|
||||
String userPassword = "pass";
|
||||
given(passwordSecurity.comparePassword(userPassword, password, name)).willReturn(true);
|
||||
given(dataSource.removeAuth(name)).willReturn(true);
|
||||
given(service.getProperty(RegistrationSettings.FORCE)).willReturn(true);
|
||||
given(service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)).willReturn(true);
|
||||
given(service.getProperty(RestrictionSettings.TIMEOUT)).willReturn(12);
|
||||
|
||||
// when
|
||||
asynchronousUnregister.unregister(player, userPassword);
|
||||
@@ -238,7 +234,6 @@ public class AsynchronousUnregisterTest {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
String name = "Frank21";
|
||||
given(player.getName()).willReturn(name);
|
||||
given(player.isOnline()).willReturn(true);
|
||||
given(dataSource.removeAuth(name)).willReturn(true);
|
||||
given(service.getProperty(RegistrationSettings.FORCE)).willReturn(true);
|
||||
|
||||
@@ -32,6 +32,7 @@ public class HashAlgorithmIntegrationTest {
|
||||
Settings settings = mock(Settings.class);
|
||||
given(settings.getProperty(HooksSettings.BCRYPT_LOG2_ROUND)).willReturn(8);
|
||||
given(settings.getProperty(SecuritySettings.DOUBLE_MD5_SALT_LENGTH)).willReturn(16);
|
||||
given(settings.getProperty(SecuritySettings.PBKDF2_NUMBER_OF_ROUNDS)).willReturn(10_000);
|
||||
injector = new InjectorBuilder().addDefaultHandlers("fr.xephi.authme").create();
|
||||
injector.register(Settings.class, settings);
|
||||
}
|
||||
|
||||
@@ -21,20 +21,26 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
import static com.google.common.collect.Sets.newHashSet;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.equalToIgnoringCase;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link PasswordSecurity}.
|
||||
@@ -97,7 +103,7 @@ public class PasswordSecurityTest {
|
||||
|
||||
given(dataSource.getPassword(playerName)).willReturn(password);
|
||||
given(method.comparePassword(clearTextPass, password, playerLowerCase)).willReturn(true);
|
||||
initSettings(HashAlgorithm.BCRYPT, false);
|
||||
initSettings(HashAlgorithm.BCRYPT);
|
||||
PasswordSecurity security = newPasswordSecurity();
|
||||
|
||||
// when
|
||||
@@ -120,7 +126,7 @@ public class PasswordSecurityTest {
|
||||
|
||||
given(dataSource.getPassword(playerName)).willReturn(password);
|
||||
given(method.comparePassword(clearTextPass, password, playerLowerCase)).willReturn(false);
|
||||
initSettings(HashAlgorithm.CUSTOM, false);
|
||||
initSettings(HashAlgorithm.CUSTOM);
|
||||
PasswordSecurity security = newPasswordSecurity();
|
||||
|
||||
// when
|
||||
@@ -140,7 +146,7 @@ public class PasswordSecurityTest {
|
||||
String clearTextPass = "tables";
|
||||
|
||||
given(dataSource.getPassword(playerName)).willReturn(null);
|
||||
initSettings(HashAlgorithm.MD5, false);
|
||||
initSettings(HashAlgorithm.MD5);
|
||||
PasswordSecurity security = newPasswordSecurity();
|
||||
|
||||
// when
|
||||
@@ -168,7 +174,8 @@ public class PasswordSecurityTest {
|
||||
given(dataSource.getPassword(argThat(equalToIgnoringCase(playerName)))).willReturn(password);
|
||||
given(method.comparePassword(clearTextPass, password, playerLowerCase)).willReturn(false);
|
||||
given(method.computeHash(clearTextPass, playerLowerCase)).willReturn(newPassword);
|
||||
initSettings(HashAlgorithm.MD5, true);
|
||||
initSettings(HashAlgorithm.MD5);
|
||||
given(settings.getProperty(SecuritySettings.LEGACY_HASHES)).willReturn(newArrayList(HashAlgorithm.BCRYPT.name()));
|
||||
PasswordSecurity security = newPasswordSecurity();
|
||||
|
||||
// when
|
||||
@@ -193,7 +200,7 @@ public class PasswordSecurityTest {
|
||||
String clearTextPass = "someInvalidPassword";
|
||||
given(dataSource.getPassword(playerName)).willReturn(password);
|
||||
given(method.comparePassword(clearTextPass, password, playerName)).willReturn(false);
|
||||
initSettings(HashAlgorithm.MD5, true);
|
||||
initSettings(HashAlgorithm.MD5);
|
||||
PasswordSecurity security = newPasswordSecurity();
|
||||
|
||||
// when
|
||||
@@ -212,7 +219,7 @@ public class PasswordSecurityTest {
|
||||
String usernameLowerCase = username.toLowerCase();
|
||||
HashedPassword hashedPassword = new HashedPassword("$T$est#Hash", "__someSalt__");
|
||||
given(method.computeHash(password, usernameLowerCase)).willReturn(hashedPassword);
|
||||
initSettings(HashAlgorithm.JOOMLA, true);
|
||||
initSettings(HashAlgorithm.JOOMLA);
|
||||
PasswordSecurity security = newPasswordSecurity();
|
||||
|
||||
// when
|
||||
@@ -233,9 +240,8 @@ public class PasswordSecurityTest {
|
||||
String password = "?topSecretPass\\";
|
||||
String username = "someone12";
|
||||
HashedPassword hashedPassword = new HashedPassword("~T!est#Hash");
|
||||
given(method.computeHash(password, username)).willReturn(hashedPassword);
|
||||
given(method.hasSeparateSalt()).willReturn(true);
|
||||
initSettings(HashAlgorithm.XAUTH, false);
|
||||
initSettings(HashAlgorithm.XAUTH);
|
||||
PasswordSecurity security = newPasswordSecurity();
|
||||
|
||||
// when
|
||||
@@ -251,19 +257,21 @@ public class PasswordSecurityTest {
|
||||
@Test
|
||||
public void shouldReloadSettings() {
|
||||
// given
|
||||
initSettings(HashAlgorithm.BCRYPT, false);
|
||||
initSettings(HashAlgorithm.BCRYPT);
|
||||
PasswordSecurity passwordSecurity = newPasswordSecurity();
|
||||
given(settings.getProperty(SecuritySettings.PASSWORD_HASH)).willReturn(HashAlgorithm.MD5);
|
||||
given(settings.getProperty(SecuritySettings.SUPPORT_OLD_PASSWORD_HASH)).willReturn(true);
|
||||
List<String> legacyHashes = newArrayList(HashAlgorithm.CUSTOM.name(), HashAlgorithm.BCRYPT.name());
|
||||
given(settings.getProperty(SecuritySettings.LEGACY_HASHES)).willReturn(legacyHashes);
|
||||
|
||||
// when
|
||||
passwordSecurity.reload();
|
||||
|
||||
// then
|
||||
assertThat(ReflectionTestUtils.getFieldValue(PasswordSecurity.class, passwordSecurity, "algorithm"),
|
||||
equalTo((Object) HashAlgorithm.MD5));
|
||||
assertThat(ReflectionTestUtils.getFieldValue(PasswordSecurity.class, passwordSecurity, "supportOldAlgorithm"),
|
||||
equalTo((Object) Boolean.TRUE));
|
||||
equalTo(HashAlgorithm.MD5));
|
||||
Set<HashAlgorithm> legacyHashesSet = newHashSet(HashAlgorithm.CUSTOM, HashAlgorithm.BCRYPT);
|
||||
assertThat(ReflectionTestUtils.getFieldValue(PasswordSecurity.class, passwordSecurity, "legacyAlgorithms"),
|
||||
equalTo(legacyHashesSet));
|
||||
}
|
||||
|
||||
private PasswordSecurity newPasswordSecurity() {
|
||||
@@ -276,11 +284,10 @@ public class PasswordSecurityTest {
|
||||
return passwordSecurity;
|
||||
}
|
||||
|
||||
private void initSettings(HashAlgorithm algorithm, boolean supportOldPassword) {
|
||||
private void initSettings(HashAlgorithm algorithm) {
|
||||
given(settings.getProperty(SecuritySettings.PASSWORD_HASH)).willReturn(algorithm);
|
||||
given(settings.getProperty(SecuritySettings.SUPPORT_OLD_PASSWORD_HASH)).willReturn(supportOldPassword);
|
||||
given(settings.getProperty(SecuritySettings.LEGACY_HASHES)).willReturn(Collections.emptyList());
|
||||
given(settings.getProperty(HooksSettings.BCRYPT_LOG2_ROUND)).willReturn(8);
|
||||
given(settings.getProperty(SecuritySettings.DOUBLE_MD5_SALT_LENGTH)).willReturn(16);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ package fr.xephi.authme.security.crypts;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.security.crypts.description.AsciiRestricted;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
@@ -100,6 +102,11 @@ public abstract class AbstractEncryptionMethodTest {
|
||||
GIVEN_PASSWORDS[3], result3);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setupLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGivenPasswords() {
|
||||
// Start with the 2nd to last password if we skip long tests
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package fr.xephi.authme.security.crypts;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -13,11 +11,6 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class BcryptTest extends AbstractEncryptionMethodTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void initializeLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
public BcryptTest() {
|
||||
super(new BCRYPT(mockSettings()),
|
||||
"$2a$10$6iATmYgwJVc3YONhVcZFve3Cfb5GnwvKhJ20r.hMjmcNkIT9.Uh9K", // password
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package fr.xephi.authme.security.crypts;
|
||||
|
||||
import org.junit.Ignore;
|
||||
|
||||
/**
|
||||
* Test for {@link CryptPBKDF2}.
|
||||
*/
|
||||
@Ignore
|
||||
// TODO #685: This algorithm seems broken
|
||||
public class CryptPBKDF2Test extends AbstractEncryptionMethodTest {
|
||||
|
||||
public CryptPBKDF2Test() {
|
||||
super(new CryptPBKDF2(),
|
||||
"pbkdf2_sha256$10000$dd9b1cd071f2$[82, -69, -58, -51, 101, 105, 61, -48, -49, 25, 50, -126, 115, 36, 16, -94, 4, 84, -94, 13, -115, -12, 94, -27, 94, -103, 115, -31, -56, -18, 8, 77, 36, 78, -61, 105, -7, -114, 41, 3, 48, 122, 27, 1, 56, 76, 126, 68, -120, 127, -95, 119, -7, 100, -87, -128, -77, 83, -118, 28, 43, 84, 73, 103]", // password
|
||||
"pbkdf2_sha256$10000$4b3b650288cd$[99, 25, 45, 22, -66, -109, -109, 30, 117, 77, 22, 63, -36, -126, -116, -66, 35, 109, -33, -4, -112, 53, 48, 33, -20, 107, -100, -37, -89, 59, -29, -83, 57, -123, -40, 11, 98, 32, -74, 77, 107, -76, 95, -9, 110, -92, -31, -2, -18, 115, 43, -27, 16, 36, 75, -56, -11, 58, -62, 21, 0, 37, -59, -82]", // PassWord1
|
||||
"pbkdf2_sha256$10000$035205f5ab39$[-121, -15, 97, 35, -105, -57, -49, -60, -58, -106, 101, 78, -103, 2, -116, -120, 0, 106, -107, 10, 78, -97, 111, 98, -15, 40, -53, 84, 120, -86, 116, 12, -60, 19, 105, 1, 71, 99, 4, 43, -4, -36, 35, -110, 59, 73, -20, -8, 46, 102, 51, 84, 54, -92, -41, -84, 28, 36, 37, 26, 90, -6, -49, 70]", // &^%te$t?Pw@_
|
||||
"pbkdf2_sha256$10000$ca72ded579e9$[-81, 76, -103, 78, 68, -10, -58, -88, -57, 88, -38, 108, 115, -86, 13, -84, 80, 69, 48, 15, 105, 25, -2, 123, 9, 97, 23, -96, 95, -64, -56, 59, -124, 116, 36, 10, 96, -12, -76, -121, -51, 76, -96, -27, 84, 66, 85, 75, 95, -97, -60, -98, -41, -32, -58, 39, 82, -19, -25, 98, -15, -68, 59, -48]"); // âË_3(íù*
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +1,10 @@
|
||||
package fr.xephi.authme.security.crypts;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
/**
|
||||
* Test for {@link IPB4}.
|
||||
*/
|
||||
public class IPB4Test extends AbstractEncryptionMethodTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpSettings() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
public IPB4Test() {
|
||||
super(new IPB4(),
|
||||
new HashedPassword("$2a$13$leEvXu77OIwPwNvtZIJvaeAx8EItGHuR3nIlq8416g0gXeJaQdrr2", "leEvXu77OIwPwNvtZIJval"), //password
|
||||
|
||||
+4
-12
@@ -1,20 +1,12 @@
|
||||
package fr.xephi.authme.security.crypts;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
/**
|
||||
* Test for {@link CryptPBKDF2Django}.
|
||||
* Test for {@link Pbkdf2Django}.
|
||||
*/
|
||||
public class CryptPBKDF2DjangoTest extends AbstractEncryptionMethodTest {
|
||||
public class Pbkdf2DjangoTest extends AbstractEncryptionMethodTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setupLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
public CryptPBKDF2DjangoTest() {
|
||||
super(new CryptPBKDF2Django(),
|
||||
public Pbkdf2DjangoTest() {
|
||||
super(new Pbkdf2Django(),
|
||||
"pbkdf2_sha256$15000$50a7ff2d7e00$t7Qx2CfzMhGEbyCa3Wk5nJvNjj3N+FdxhpwJDerl4Fs=", // password
|
||||
"pbkdf2_sha256$15000$f9d8a58f3fe2$oMqmMGuJetdubW0cpubmT8CltQLjHT+L2GuwKsaWLx8=", // PassWord1
|
||||
"pbkdf2_sha256$15000$1170bc7a31f5$Ex/2aQsXm4kogLIYARpUPn04ccK5LYYjyVPpl32ALjE=", // &^%te$t?Pw@_
|
||||
@@ -0,0 +1,44 @@
|
||||
package fr.xephi.authme.security.crypts;
|
||||
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Test for {@link Pbkdf2}.
|
||||
*/
|
||||
public class Pbkdf2Test extends AbstractEncryptionMethodTest {
|
||||
|
||||
public Pbkdf2Test() {
|
||||
super(new Pbkdf2(mockSettings()),
|
||||
"pbkdf2_sha256$10000$b25801311edf$093E38B16DFF13FCE5CD64D5D888EE6E0376A3E572FE5DA6749515EA0F384413223A21C464B0BE899E64084D1FFEFD44F2AC768453C87F41B42CC6954C416900", // password
|
||||
"pbkdf2_sha256$10000$fe705da06c57$A41527BD58FED9C9E6F452FC1BA8B0C4C4224ECC63E37F71EB1A0865D2AB81BBFEBCA9B7B6A6E8AEF4717B43F8EB6FB4EDEFFBB399D9D991EF7E23013595BAF0", // PassWord1
|
||||
"pbkdf2_sha256$10000$05603593cdda$1D30D1D90D826C866755969F06C312E21CC3E8DA0B777E2C764700E4E1FD890B731FAF44753D68F3FC025D3EAA709E800FBF2AF61DB23464311FCE7D35353A30", // &^%te$t?Pw@_
|
||||
"pbkdf2_sha256$10000$fb944d66d754$F7E3BF8CB07CE3B3C8C5C534F803252F7B4FD58832E33BA62BA46CA06F23BAE12BE03A9CB5874BCFD4469E42972406F920E59F002247B23C22A8CF3D0E7BFFE0"); // âË_3(íù*
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDetectMatchForHashWithOtherRoundNumber() {
|
||||
// given
|
||||
Pbkdf2 pbkdf2 = new Pbkdf2(mockSettings());
|
||||
String hash = "pbkdf2_sha256$4128$3469b0d48b702046$DC8A54351008C6054E12FB19E0BF8A4EA6D4165E0EDC97A1ECD15231037C382DE5BF85D07D5BC9D1ADF9BBFE4CE257C6059FB1B9FF65DB69D8B205F064BE0DA9";
|
||||
String clearText = "PassWord1";
|
||||
|
||||
// when
|
||||
boolean isMatch = pbkdf2.comparePassword(clearText, new HashedPassword(hash), "");
|
||||
|
||||
// then
|
||||
assertThat(isMatch, equalTo(true));
|
||||
}
|
||||
|
||||
private static Settings mockSettings() {
|
||||
Settings settings = mock(Settings.class);
|
||||
given(settings.getProperty(SecuritySettings.PBKDF2_NUMBER_OF_ROUNDS)).willReturn(4128);
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,10 @@
|
||||
package fr.xephi.authme.security.crypts;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
/**
|
||||
* Test for {@link XFBCRYPT}.
|
||||
*/
|
||||
public class XFBCRYPTTest extends AbstractEncryptionMethodTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
public XFBCRYPTTest() {
|
||||
super(new XFBCRYPT(),
|
||||
"$2a$10$UtuON/ZG.x8EWG/zQbryB.BHfQVrfxk3H7qykzP.UJQ8YiLjZyfqq", // password
|
||||
|
||||
@@ -3,7 +3,6 @@ package fr.xephi.authme.service;
|
||||
import ch.jalu.injector.testing.BeforeInjecting;
|
||||
import ch.jalu.injector.testing.DelayedInjectionRunner;
|
||||
import ch.jalu.injector.testing.InjectDelayed;
|
||||
import fr.xephi.authme.ReflectionTestUtils;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.message.Messages;
|
||||
import fr.xephi.authme.permission.AdminPermission;
|
||||
@@ -12,6 +11,7 @@ import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@@ -22,9 +22,9 @@ import java.util.List;
|
||||
import static fr.xephi.authme.TestHelper.runSyncDelayedTaskWithDelay;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.only;
|
||||
import static org.mockito.Mockito.reset;
|
||||
@@ -52,6 +52,7 @@ public class AntiBotServiceTest {
|
||||
@BeforeInjecting
|
||||
public void initSettings() {
|
||||
given(settings.getProperty(ProtectionSettings.ANTIBOT_DURATION)).willReturn(10);
|
||||
given(settings.getProperty(ProtectionSettings.ANTIBOT_INTERVAL)).willReturn(5);
|
||||
given(settings.getProperty(ProtectionSettings.ANTIBOT_SENSIBILITY)).willReturn(5);
|
||||
given(settings.getProperty(ProtectionSettings.ENABLE_ANTIBOT)).willReturn(true);
|
||||
given(settings.getProperty(ProtectionSettings.ANTIBOT_DELAY)).willReturn(8);
|
||||
@@ -81,6 +82,7 @@ public class AntiBotServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // TODO ljacqu 20161030: Fix test
|
||||
public void shouldActivateAntibot() {
|
||||
// given - listening antibot
|
||||
runSyncDelayedTaskWithDelay(bukkitService);
|
||||
@@ -131,43 +133,12 @@ public class AntiBotServiceTest {
|
||||
runSyncDelayedTaskWithDelay(bukkitService);
|
||||
|
||||
// when
|
||||
boolean result = antiBotService.shouldKick(false);
|
||||
boolean result = antiBotService.shouldKick();
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectPlayerWithoutAuth() {
|
||||
// given - active antibot
|
||||
runSyncDelayedTaskWithDelay(bukkitService);
|
||||
antiBotService.overrideAntiBotStatus(true);
|
||||
|
||||
// when
|
||||
boolean kickWithoutAuth = antiBotService.shouldKick(false);
|
||||
boolean kickWithAuth = antiBotService.shouldKick(true);
|
||||
|
||||
// then
|
||||
assertThat(kickWithoutAuth, equalTo(true));
|
||||
assertThat(kickWithAuth, equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldIncreaseCountAndDecreaseAfterDelay() {
|
||||
// given - listening antibot
|
||||
runSyncDelayedTaskWithDelay(bukkitService);
|
||||
reset(bukkitService);
|
||||
assertThat(getAntiBotCount(antiBotService), equalTo(0));
|
||||
|
||||
// when
|
||||
antiBotService.handlePlayerJoin();
|
||||
|
||||
// then
|
||||
assertThat(getAntiBotCount(antiBotService), equalTo(1));
|
||||
runSyncDelayedTaskWithDelay(bukkitService);
|
||||
assertThat(getAntiBotCount(antiBotService), equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldActivateAntibotAfterThreshold() {
|
||||
// given
|
||||
@@ -178,19 +149,19 @@ public class AntiBotServiceTest {
|
||||
runSyncDelayedTaskWithDelay(bukkitService);
|
||||
|
||||
for (int i = 0; i < sensitivity; ++i) {
|
||||
antiBotService.handlePlayerJoin();
|
||||
antiBotService.shouldKick();
|
||||
}
|
||||
assertThat(antiBotService.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.LISTENING));
|
||||
|
||||
// when
|
||||
antiBotService.handlePlayerJoin();
|
||||
antiBotService.shouldKick();
|
||||
|
||||
// then
|
||||
assertThat(antiBotService.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.ACTIVE));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public void shouldInformPlayersOnActivation() {
|
||||
// given - listening antibot
|
||||
runSyncDelayedTaskWithDelay(bukkitService);
|
||||
@@ -222,7 +193,4 @@ public class AntiBotServiceTest {
|
||||
assertThat(antiBotService.getAntiBotStatus(), equalTo(AntiBotService.AntiBotStatus.LISTENING));
|
||||
}
|
||||
|
||||
private static int getAntiBotCount(AntiBotService antiBotService) {
|
||||
return ReflectionTestUtils.getFieldValue(AntiBotService.class, antiBotService, "antibotPlayers");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,16 @@ import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ReflectionTestUtils;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -17,6 +22,7 @@ import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Test for {@link BukkitService}.
|
||||
@@ -24,10 +30,21 @@ import static org.mockito.Mockito.mock;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class BukkitServiceTest {
|
||||
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Mock
|
||||
private AuthMe authMe;
|
||||
@Mock
|
||||
private Settings settings;
|
||||
@Mock
|
||||
private Server server;
|
||||
|
||||
@Before
|
||||
public void constructBukkitService() {
|
||||
ReflectionTestUtils.setField(Bukkit.class, null, "server", server);
|
||||
given(settings.getProperty(PluginSettings.USE_ASYNC_TASKS)).willReturn(true);
|
||||
bukkitService = new BukkitService(authMe, settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that {@link BukkitService#getOnlinePlayersIsCollection} is initialized to {@code true} on startup;
|
||||
@@ -35,11 +52,7 @@ public class BukkitServiceTest {
|
||||
*/
|
||||
@Test
|
||||
public void shouldHavePlayerListAsCollectionMethod() {
|
||||
// given
|
||||
given(settings.getProperty(PluginSettings.USE_ASYNC_TASKS)).willReturn(true);
|
||||
BukkitService bukkitService = new BukkitService(authMe, settings);
|
||||
|
||||
// when
|
||||
// given / when
|
||||
boolean doesMethodReturnCollection = ReflectionTestUtils
|
||||
.getFieldValue(BukkitService.class, bukkitService, "getOnlinePlayersIsCollection");
|
||||
|
||||
@@ -50,8 +63,6 @@ public class BukkitServiceTest {
|
||||
@Test
|
||||
public void shouldRetrieveListOfOnlinePlayersFromReflectedMethod() {
|
||||
// given
|
||||
given(settings.getProperty(PluginSettings.USE_ASYNC_TASKS)).willReturn(true);
|
||||
BukkitService bukkitService = new BukkitService(authMe, settings);
|
||||
ReflectionTestUtils.setField(BukkitService.class, bukkitService, "getOnlinePlayersIsCollection", false);
|
||||
ReflectionTestUtils.setField(BukkitService.class, bukkitService, "getOnlinePlayers",
|
||||
ReflectionTestUtils.getMethod(BukkitServiceTest.class, "onlinePlayersImpl"));
|
||||
@@ -63,6 +74,33 @@ public class BukkitServiceTest {
|
||||
assertThat(players, hasSize(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDispatchCommand() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
String command = "help test abc";
|
||||
|
||||
// when
|
||||
bukkitService.dispatchCommand(sender, command);
|
||||
|
||||
// then
|
||||
verify(server).dispatchCommand(sender, command);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDispatchConsoleCommand() {
|
||||
// given
|
||||
ConsoleCommandSender consoleSender = mock(ConsoleCommandSender.class);
|
||||
given(server.getConsoleSender()).willReturn(consoleSender);
|
||||
String command = "my command";
|
||||
|
||||
// when
|
||||
bukkitService.dispatchConsoleCommand(command);
|
||||
|
||||
// then
|
||||
verify(server).dispatchCommand(consoleSender, command);
|
||||
}
|
||||
|
||||
// Note: This method is used through reflections
|
||||
public static Player[] onlinePlayersImpl() {
|
||||
return new Player[]{
|
||||
|
||||
+12
-55
@@ -1,4 +1,4 @@
|
||||
package fr.xephi.authme.process;
|
||||
package fr.xephi.authme.service;
|
||||
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.message.Messages;
|
||||
@@ -9,14 +9,13 @@ import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -25,16 +24,13 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Test for {@link ProcessService}.
|
||||
* Test for {@link CommonService}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ProcessServiceTest {
|
||||
public class CommonServiceTest {
|
||||
|
||||
@InjectMocks
|
||||
private ProcessService processService;
|
||||
|
||||
@Mock
|
||||
private ValidationService validationService;
|
||||
private CommonService commonService;
|
||||
|
||||
@Mock
|
||||
private Settings settings;
|
||||
@@ -54,22 +50,13 @@ public class ProcessServiceTest {
|
||||
given(settings.getProperty(SecuritySettings.CAPTCHA_LENGTH)).willReturn(8);
|
||||
|
||||
// when
|
||||
int result = processService.getProperty(SecuritySettings.CAPTCHA_LENGTH);
|
||||
int result = commonService.getProperty(SecuritySettings.CAPTCHA_LENGTH);
|
||||
|
||||
// then
|
||||
verify(settings).getProperty(SecuritySettings.CAPTCHA_LENGTH);
|
||||
assertThat(result, equalTo(8));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnSettings() {
|
||||
// given/when
|
||||
Settings result = processService.getSettings();
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(settings));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSendMessageToPlayer() {
|
||||
// given
|
||||
@@ -77,7 +64,7 @@ public class ProcessServiceTest {
|
||||
MessageKey key = MessageKey.ACCOUNT_NOT_ACTIVATED;
|
||||
|
||||
// when
|
||||
processService.send(sender, key);
|
||||
commonService.send(sender, key);
|
||||
|
||||
// then
|
||||
verify(messages).send(sender, key);
|
||||
@@ -91,7 +78,7 @@ public class ProcessServiceTest {
|
||||
String[] replacements = new String[]{"test", "toast"};
|
||||
|
||||
// when
|
||||
processService.send(sender, key, replacements);
|
||||
commonService.send(sender, key, replacements);
|
||||
|
||||
// then
|
||||
verify(messages).send(sender, key, replacements);
|
||||
@@ -105,7 +92,7 @@ public class ProcessServiceTest {
|
||||
given(messages.retrieve(key)).willReturn(lines);
|
||||
|
||||
// when
|
||||
String[] result = processService.retrieveMessage(key);
|
||||
String[] result = commonService.retrieveMessage(key);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(lines));
|
||||
@@ -120,43 +107,13 @@ public class ProcessServiceTest {
|
||||
given(messages.retrieveSingle(key)).willReturn(text);
|
||||
|
||||
// when
|
||||
String result = processService.retrieveSingleMessage(key);
|
||||
String result = commonService.retrieveSingleMessage(key);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(text));
|
||||
verify(messages).retrieveSingle(key);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldValidateEmail() {
|
||||
// given
|
||||
String email = "test@example.tld";
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
|
||||
// when
|
||||
boolean result = processService.validateEmail(email);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
||||
verify(validationService).validateEmail(email);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCheckIfEmailCanBeUsed() {
|
||||
// given
|
||||
String email = "mail@example.com";
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(validationService.isEmailFreeForRegistration(email, sender))
|
||||
.willReturn(true);
|
||||
|
||||
// when
|
||||
boolean result = processService.isEmailFreeForRegistration(email, sender);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
||||
verify(validationService).isEmailFreeForRegistration(email, sender);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCheckPermission() {
|
||||
// given
|
||||
@@ -165,7 +122,7 @@ public class ProcessServiceTest {
|
||||
given(permissionsManager.hasPermission(player, permission)).willReturn(true);
|
||||
|
||||
// when
|
||||
boolean result = processService.hasPermission(player, permission);
|
||||
boolean result = commonService.hasPermission(player, permission);
|
||||
|
||||
// then
|
||||
verify(permissionsManager).hasPermission(player, permission);
|
||||
@@ -180,7 +137,7 @@ public class ProcessServiceTest {
|
||||
given(authGroupHandler.setGroup(player, type)).willReturn(true);
|
||||
|
||||
// when
|
||||
boolean result = processService.setGroup(player, type);
|
||||
boolean result = commonService.setGroup(player, type);
|
||||
|
||||
// then
|
||||
verify(authGroupHandler).setGroup(player, type);
|
||||
@@ -2,22 +2,21 @@ package fr.xephi.authme.service;
|
||||
|
||||
import com.maxmind.geoip.Country;
|
||||
import com.maxmind.geoip.LookupService;
|
||||
import fr.xephi.authme.service.GeoIpService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -21,13 +21,13 @@ import java.util.Arrays;
|
||||
import static fr.xephi.authme.AuthMeMatchers.equalToHash;
|
||||
import static org.hamcrest.Matchers.equalToIgnoringCase;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link MigrationService}.
|
||||
@@ -126,7 +126,7 @@ public class MigrationServiceTest {
|
||||
given(sha256.computeHash(anyString(), anyString())).willAnswer(new Answer<HashedPassword>() {
|
||||
@Override
|
||||
public HashedPassword answer(InvocationOnMock invocation) {
|
||||
String plainPassword = (String) invocation.getArguments()[0];
|
||||
String plainPassword = invocation.getArgument(0);
|
||||
return new HashedPassword(plainPassword.toUpperCase(), null);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.earth2me.essentials.User;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import fr.xephi.authme.service.PluginHookService;
|
||||
import fr.xephi.authme.ReflectionTestUtils;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import org.bukkit.Location;
|
||||
@@ -22,8 +21,8 @@ import java.io.File;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
|
||||
@@ -18,7 +18,7 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -26,9 +26,9 @@ import java.util.Arrays;
|
||||
import static fr.xephi.authme.TestHelper.runSyncDelayedTask;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -127,11 +127,6 @@ public class TeleportationServiceTest {
|
||||
public void shouldNotTeleportNewPlayer() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
given(player.hasPlayedBefore()).willReturn(false);
|
||||
given(player.isOnline()).willReturn(true);
|
||||
given(player.getWorld()).willReturn(mock(World.class));
|
||||
given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(false);
|
||||
given(settings.getProperty(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN)).willReturn(false);
|
||||
given(spawnLoader.getFirstSpawn()).willReturn(null);
|
||||
|
||||
// when
|
||||
@@ -148,7 +143,6 @@ public class TeleportationServiceTest {
|
||||
public void shouldNotTeleportPlayerToFirstSpawnIfNoTeleportEnabled() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
given(player.hasPlayedBefore()).willReturn(false);
|
||||
given(settings.getProperty(RestrictionSettings.NO_TELEPORT)).willReturn(true);
|
||||
|
||||
// when
|
||||
@@ -163,7 +157,6 @@ public class TeleportationServiceTest {
|
||||
public void shouldNotTeleportNotNewPlayerToFirstSpawn() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
given(player.hasPlayedBefore()).willReturn(true);
|
||||
given(settings.getProperty(RestrictionSettings.NO_TELEPORT)).willReturn(false);
|
||||
|
||||
// when
|
||||
@@ -273,9 +266,7 @@ public class TeleportationServiceTest {
|
||||
given(settings.getProperty(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN)).willReturn(true);
|
||||
given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(false);
|
||||
Player player = mock(Player.class);
|
||||
given(player.isOnline()).willReturn(true);
|
||||
Location spawn = mockLocation();
|
||||
given(spawnLoader.getSpawnLocation(player)).willReturn(spawn);
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
LimboPlayer limbo = mock(LimboPlayer.class);
|
||||
Location limboLocation = mockLocation();
|
||||
@@ -293,7 +284,6 @@ public class TeleportationServiceTest {
|
||||
@Test
|
||||
public void shouldTeleportBackToPlayerAuthLocation() {
|
||||
// given
|
||||
given(settings.getProperty(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN)).willReturn(false);
|
||||
given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(true);
|
||||
given(settings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)).willReturn(true);
|
||||
|
||||
@@ -321,7 +311,6 @@ public class TeleportationServiceTest {
|
||||
@Test
|
||||
public void shouldTeleportAccordingToPlayerAuthAndPlayerWorldAsFallback() {
|
||||
// given
|
||||
given(settings.getProperty(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN)).willReturn(false);
|
||||
given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(true);
|
||||
given(settings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)).willReturn(true);
|
||||
|
||||
@@ -350,7 +339,6 @@ public class TeleportationServiceTest {
|
||||
@Test
|
||||
public void shouldTeleportWithLimboPlayerIfAuthYCoordIsNotSet() {
|
||||
// given
|
||||
given(settings.getProperty(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN)).willReturn(false);
|
||||
given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(true);
|
||||
given(settings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)).willReturn(true);
|
||||
|
||||
@@ -359,8 +347,6 @@ public class TeleportationServiceTest {
|
||||
auth.setWorld("authWorld");
|
||||
Player player = mock(Player.class);
|
||||
given(player.isOnline()).willReturn(true);
|
||||
World world = mock(World.class);
|
||||
given(player.getWorld()).willReturn(world);
|
||||
LimboPlayer limbo = mock(LimboPlayer.class);
|
||||
Location location = mockLocation();
|
||||
given(limbo.getLocation()).willReturn(location);
|
||||
@@ -377,15 +363,12 @@ public class TeleportationServiceTest {
|
||||
@Test
|
||||
public void shouldTeleportWithLimboPlayerIfSaveQuitLocIsDisabled() {
|
||||
// given
|
||||
given(settings.getProperty(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN)).willReturn(false);
|
||||
given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(true);
|
||||
given(settings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)).willReturn(false);
|
||||
|
||||
PlayerAuth auth = createAuthWithLocation();
|
||||
Player player = mock(Player.class);
|
||||
given(player.isOnline()).willReturn(true);
|
||||
World world = mock(World.class);
|
||||
given(player.getWorld()).willReturn(world);
|
||||
LimboPlayer limbo = mock(LimboPlayer.class);
|
||||
Location location = mockLocation();
|
||||
given(limbo.getLocation()).willReturn(location);
|
||||
@@ -403,7 +386,6 @@ public class TeleportationServiceTest {
|
||||
// given
|
||||
given(settings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)).willReturn(false);
|
||||
given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(true);
|
||||
given(settings.getProperty(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN)).willReturn(false);
|
||||
|
||||
PlayerAuth auth = PlayerAuth.builder().name("bobby").build();
|
||||
Player player = mock(Player.class);
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import com.github.authme.configme.knownproperties.ConfigurationData;
|
||||
import com.github.authme.configme.properties.Property;
|
||||
import fr.xephi.authme.settings.properties.AuthMeSettingsRetriever;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Tests the consistency of the settings configuration.
|
||||
*/
|
||||
public class SettingsConsistencyTest {
|
||||
|
||||
/**
|
||||
* Maximum characters one comment line may have (prevents horizontal scrolling).
|
||||
*/
|
||||
private static final int MAX_COMMENT_LENGTH = 90;
|
||||
|
||||
private static ConfigurationData configurationData;
|
||||
|
||||
@BeforeClass
|
||||
public static void buildConfigurationData() {
|
||||
configurationData = AuthMeSettingsRetriever.buildConfigurationData();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveCommentOnEachProperty() {
|
||||
// given
|
||||
List<Property<?>> properties = configurationData.getProperties();
|
||||
|
||||
// when / then
|
||||
for (Property<?> property : properties) {
|
||||
if (configurationData.getCommentsForSection(property.getPath()).length == 0) {
|
||||
fail("No comment defined for '" + property + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotHaveVeryLongCommentLines() {
|
||||
// given
|
||||
List<Property<?>> properties = configurationData.getProperties();
|
||||
List<Property<?>> badProperties = new ArrayList<>();
|
||||
|
||||
// when
|
||||
for (Property<?> property : properties) {
|
||||
for (String comment : configurationData.getCommentsForSection(property.getPath())) {
|
||||
if (comment.length() > MAX_COMMENT_LENGTH) {
|
||||
badProperties.add(property);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// then
|
||||
if (!badProperties.isEmpty()) {
|
||||
fail("Comment lines should not be longer than " + MAX_COMMENT_LENGTH + " chars, "
|
||||
+ "but found too long comments for:\n- "
|
||||
+ badProperties.stream().map(Property::getPath).collect(Collectors.joining("\n- ")));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -121,8 +121,7 @@ public class SettingsIntegrationTest {
|
||||
// given
|
||||
File configFile = temporaryFolder.newFile();
|
||||
PropertyResource resource = new YamlFileResource(configFile);
|
||||
Settings settings = new Settings(testPluginFolder, resource,
|
||||
TestSettingsMigrationServices.alwaysFulfilled(), CONFIG_DATA);
|
||||
Settings settings = new Settings(testPluginFolder, resource, null, CONFIG_DATA);
|
||||
|
||||
// when
|
||||
assertThat(settings.getProperty(TestConfiguration.RATIO_ORDER), equalTo(TestEnum.SECOND)); // default value
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import com.github.authme.configme.resource.PropertyResource;
|
||||
import com.github.authme.configme.resource.YamlFileResource;
|
||||
import com.google.common.io.Files;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.output.LogLevel;
|
||||
import fr.xephi.authme.settings.properties.AuthMeSettingsRetriever;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static fr.xephi.authme.TestHelper.getJarFile;
|
||||
import static fr.xephi.authme.settings.properties.PluginSettings.LOG_LEVEL;
|
||||
import static fr.xephi.authme.settings.properties.RegistrationSettings.DELAY_JOIN_MESSAGE;
|
||||
import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOWED_NICKNAME_CHARACTERS;
|
||||
import static fr.xephi.authme.settings.properties.RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN;
|
||||
import static fr.xephi.authme.settings.properties.RestrictionSettings.FORCE_SPAWN_ON_WORLDS;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Test for {@link SettingsMigrationService}.
|
||||
*/
|
||||
public class SettingsMigrationServiceTest {
|
||||
|
||||
private static final String OLD_CONFIG_FILE = TestHelper.PROJECT_ROOT + "settings/config-old.yml";
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPerformMigrations() throws IOException {
|
||||
// given
|
||||
File dataFolder = temporaryFolder.newFolder();
|
||||
File configFile = new File(dataFolder, "config.yml");
|
||||
Files.copy(getJarFile(OLD_CONFIG_FILE), configFile);
|
||||
PropertyResource resource = new YamlFileResource(configFile);
|
||||
SettingsMigrationService migrationService = new SettingsMigrationService(dataFolder);
|
||||
|
||||
// when
|
||||
Settings settings = new Settings(
|
||||
dataFolder, resource, migrationService, AuthMeSettingsRetriever.buildConfigurationData());
|
||||
|
||||
// then
|
||||
assertThat(settings.getProperty(ALLOWED_NICKNAME_CHARACTERS), equalTo(ALLOWED_NICKNAME_CHARACTERS.getDefaultValue()));
|
||||
assertThat(settings.getProperty(DELAY_JOIN_MESSAGE), equalTo(true));
|
||||
assertThat(settings.getProperty(FORCE_SPAWN_LOCATION_AFTER_LOGIN), equalTo(true));
|
||||
assertThat(settings.getProperty(FORCE_SPAWN_ON_WORLDS), contains("survival", "survival_nether", "creative"));
|
||||
assertThat(settings.getProperty(LOG_LEVEL), equalTo(LogLevel.INFO));
|
||||
|
||||
// Check migration of old setting to email.html
|
||||
assertThat(Files.readLines(new File(dataFolder, "email.html"), StandardCharsets.UTF_8),
|
||||
contains("Dear <playername />, <br /><br /> This is your new AuthMe password for the server "
|
||||
+ "<br /><br /> <servername /> : <br /><br /> <generatedpass /><br /><image /><br />Do not forget to "
|
||||
+ "change password after login! <br /> /changepassword <generatedpass /> newPassword"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldKeepOldForceCommandSettings() throws IOException {
|
||||
// given
|
||||
File dataFolder = temporaryFolder.newFolder();
|
||||
File configFile = new File(dataFolder, "config.yml");
|
||||
Files.copy(getJarFile(OLD_CONFIG_FILE), configFile);
|
||||
PropertyResource resource = new YamlFileResource(configFile);
|
||||
SettingsMigrationService migrationService = new SettingsMigrationService(dataFolder);
|
||||
|
||||
// when
|
||||
migrationService.performMigrations(resource, AuthMeSettingsRetriever.buildConfigurationData().getProperties());
|
||||
|
||||
// then
|
||||
assertThat(migrationService.getOnLoginCommands(), contains("spawn"));
|
||||
assertThat(migrationService.getOnLoginConsoleCommands(), contains("sethome %p:lastloc", "msg %p Welcome back"));
|
||||
assertThat(migrationService.getOnRegisterCommands(), contains("me registers", "msg CONSOLE hi"));
|
||||
assertThat(migrationService.getOnRegisterConsoleCommands(), contains("sethome %p:regloc"));
|
||||
}
|
||||
}
|
||||
@@ -55,8 +55,7 @@ public class SettingsTest {
|
||||
|
||||
PropertyResource resource = mock(PropertyResource.class);
|
||||
given(resource.getBoolean(RegistrationSettings.USE_WELCOME_MESSAGE.getPath())).willReturn(true);
|
||||
Settings settings = new Settings(testPluginFolder, resource,
|
||||
TestSettingsMigrationServices.alwaysFulfilled(), CONFIG_DATA);
|
||||
Settings settings = new Settings(testPluginFolder, resource, null, CONFIG_DATA);
|
||||
|
||||
// when
|
||||
String[] result = settings.getWelcomeMessage();
|
||||
@@ -75,8 +74,7 @@ public class SettingsTest {
|
||||
Files.write(emailFile.toPath(), emailMessage.getBytes());
|
||||
|
||||
PropertyResource resource = mock(PropertyResource.class);
|
||||
Settings settings = new Settings(testPluginFolder, resource,
|
||||
TestSettingsMigrationServices.alwaysFulfilled(), CONFIG_DATA);
|
||||
Settings settings = new Settings(testPluginFolder, resource, null, CONFIG_DATA);
|
||||
|
||||
// when
|
||||
String result = settings.getPasswordEmailMessage();
|
||||
@@ -85,6 +83,24 @@ public class SettingsTest {
|
||||
assertThat(result, equalTo(emailMessage));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldLoadRecoveryCodeMessage() throws IOException {
|
||||
// given
|
||||
String emailMessage = "Your recovery code is %code.";
|
||||
File emailFile = new File(testPluginFolder, "recovery_code_email.html");
|
||||
createFile(emailFile);
|
||||
Files.write(emailFile.toPath(), emailMessage.getBytes());
|
||||
|
||||
PropertyResource resource = mock(PropertyResource.class);
|
||||
Settings settings = new Settings(testPluginFolder, resource, null, CONFIG_DATA);
|
||||
|
||||
// when
|
||||
String result = settings.getRecoveryCodeEmailMessage();
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(emailMessage));
|
||||
}
|
||||
|
||||
private static void createFile(File file) {
|
||||
try {
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import com.github.authme.configme.migration.MigrationService;
|
||||
|
||||
/**
|
||||
* Provides {@link MigrationService} implementations for testing.
|
||||
*/
|
||||
public final class TestSettingsMigrationServices {
|
||||
|
||||
private TestSettingsMigrationServices() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a settings migration service which always answers that all data is up-to-date.
|
||||
*
|
||||
* @return test settings migration service
|
||||
*/
|
||||
public static MigrationService alwaysFulfilled() {
|
||||
return (propertyResource, knownProperties) -> false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package fr.xephi.authme.settings.commandconfig;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
|
||||
/**
|
||||
* Helper class for tests around the command configuration.
|
||||
*/
|
||||
final class CommandConfigTestHelper {
|
||||
|
||||
private CommandConfigTestHelper() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a matcher for verifying a {@link Command} object.
|
||||
*
|
||||
* @param cmd the expected command line
|
||||
* @param executor the expected executor
|
||||
* @return the matcher
|
||||
*/
|
||||
static Matcher<Command> isCommand(String cmd, Executor executor) {
|
||||
return new TypeSafeMatcher<Command>() {
|
||||
@Override
|
||||
protected boolean matchesSafely(Command item) {
|
||||
return executor.equals(item.getExecutor()) && cmd.equals(item.getCommand());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("Command '" + cmd + "' run by '" + executor + "'");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package fr.xephi.authme.settings.commandconfig;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import fr.xephi.authme.ReflectionTestUtils;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.settings.SettingsMigrationService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
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.function.BiConsumer;
|
||||
|
||||
import static fr.xephi.authme.settings.commandconfig.CommandConfigTestHelper.isCommand;
|
||||
import static java.lang.String.format;
|
||||
import static org.hamcrest.Matchers.anEmptyMap;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.only;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* Test for {@link CommandManager}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CommandManagerTest {
|
||||
|
||||
private static final String TEST_FILES_FOLDER = "/fr/xephi/authme/settings/commandconfig/";
|
||||
|
||||
private CommandManager manager;
|
||||
@InjectMocks
|
||||
private CommandMigrationService commandMigrationService;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
@Mock
|
||||
private SettingsMigrationService settingsMigrationService;
|
||||
|
||||
private File testFolder;
|
||||
|
||||
@Before
|
||||
public void setup() throws IOException {
|
||||
testFolder = temporaryFolder.newFolder();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void shouldLoadCompleteFile() {
|
||||
// given
|
||||
copyJarFileAsCommandsYml(TEST_FILES_FOLDER + "commands.complete.yml");
|
||||
|
||||
// when
|
||||
initManager();
|
||||
|
||||
// then
|
||||
CommandConfig commandConfig = ReflectionTestUtils.getFieldValue(CommandManager.class, manager, "commandConfig");
|
||||
assertThat(commandConfig.getOnJoin().keySet(), contains("broadcast"));
|
||||
assertThat(commandConfig.getOnJoin().values(), contains(isCommand("broadcast %p has joined", Executor.CONSOLE)));
|
||||
assertThat(commandConfig.getOnRegister().keySet(), contains("announce", "notify"));
|
||||
assertThat(commandConfig.getOnRegister().values(), contains(
|
||||
isCommand("me I just registered", Executor.PLAYER),
|
||||
isCommand("log %p registered", Executor.CONSOLE)));
|
||||
assertThat(commandConfig.getOnLogin().keySet(), contains("welcome", "show_motd", "display_list"));
|
||||
assertThat(commandConfig.getOnLogin().values(), contains(
|
||||
isCommand("msg %p Welcome back", Executor.CONSOLE),
|
||||
isCommand("motd", Executor.PLAYER),
|
||||
isCommand("list", Executor.PLAYER)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldLoadIncompleteFile() {
|
||||
// given
|
||||
copyJarFileAsCommandsYml(TEST_FILES_FOLDER + "commands.incomplete.yml");
|
||||
|
||||
// when
|
||||
initManager();
|
||||
|
||||
// then
|
||||
CommandConfig commandConfig = ReflectionTestUtils.getFieldValue(CommandManager.class, manager, "commandConfig");
|
||||
assertThat(commandConfig.getOnJoin().values(), contains(isCommand("broadcast %p has joined", Executor.CONSOLE)));
|
||||
assertThat(commandConfig.getOnLogin().values(), contains(
|
||||
isCommand("msg %p Welcome back", Executor.CONSOLE),
|
||||
isCommand("list", Executor.PLAYER)));
|
||||
assertThat(commandConfig.getOnRegister(), anEmptyMap());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCommandsOnJoin() {
|
||||
// given
|
||||
String name = "Bobby1";
|
||||
|
||||
// when
|
||||
testCommandExecution(name, CommandManager::runCommandsOnJoin);
|
||||
|
||||
// then
|
||||
verify(bukkitService, only()).dispatchConsoleCommand(format("broadcast %s has joined", name));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCommandsOnRegister() {
|
||||
// given
|
||||
String name = "luis";
|
||||
|
||||
// when
|
||||
testCommandExecution(name, CommandManager::runCommandsOnRegister);
|
||||
|
||||
// then
|
||||
verify(bukkitService).dispatchCommand(any(Player.class), eq("me I just registered"));
|
||||
verify(bukkitService).dispatchConsoleCommand(format("log %s registered", name));
|
||||
verifyNoMoreInteractions(bukkitService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCommandsOnLogin() {
|
||||
// given
|
||||
String name = "plaYer01";
|
||||
|
||||
// when
|
||||
testCommandExecution(name, CommandManager::runCommandsOnLogin);
|
||||
|
||||
// then
|
||||
verify(bukkitService).dispatchConsoleCommand(format("msg %s Welcome back", name));
|
||||
verify(bukkitService).dispatchCommand(any(Player.class), eq("motd"));
|
||||
verify(bukkitService).dispatchCommand(any(Player.class), eq("list"));
|
||||
verifyNoMoreInteractions(bukkitService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveHiddenConstructorInSettingsHolderClass() {
|
||||
// given / when / then
|
||||
TestHelper.validateHasOnlyPrivateEmptyConstructor(CommandSettingsHolder.class);
|
||||
}
|
||||
|
||||
|
||||
private void testCommandExecution(String playerName, BiConsumer<CommandManager, Player> testMethod) {
|
||||
copyJarFileAsCommandsYml(TEST_FILES_FOLDER + "commands.complete.yml");
|
||||
initManager();
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn(playerName);
|
||||
|
||||
testMethod.accept(manager, player);
|
||||
}
|
||||
|
||||
private void initManager() {
|
||||
manager = new CommandManager(testFolder, bukkitService, commandMigrationService);
|
||||
}
|
||||
|
||||
private void copyJarFileAsCommandsYml(String path) {
|
||||
File source = TestHelper.getJarFile(path);
|
||||
File destination = new File(testFolder, "commands.yml");
|
||||
try {
|
||||
Files.copy(source, destination);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
package fr.xephi.authme.settings.commandconfig;
|
||||
|
||||
import com.github.authme.configme.knownproperties.ConfigurationDataBuilder;
|
||||
import com.github.authme.configme.resource.PropertyResource;
|
||||
import com.github.authme.configme.resource.YamlFileResource;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.settings.SettingsMigrationService;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
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.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static fr.xephi.authme.settings.commandconfig.CommandConfigTestHelper.isCommand;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static org.hamcrest.Matchers.anEmptyMap;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
/**
|
||||
* Test for {@link CommandMigrationService}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CommandMigrationServiceTest {
|
||||
|
||||
@InjectMocks
|
||||
private CommandMigrationService commandMigrationService;
|
||||
|
||||
@Mock
|
||||
private SettingsMigrationService settingsMigrationService;
|
||||
|
||||
private CommandConfig commandConfig = new CommandConfig();
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotPerformAnyMigration() {
|
||||
// given
|
||||
given(settingsMigrationService.getOnLoginCommands()).willReturn(emptyList());
|
||||
given(settingsMigrationService.getOnLoginConsoleCommands()).willReturn(emptyList());
|
||||
given(settingsMigrationService.getOnRegisterCommands()).willReturn(emptyList());
|
||||
given(settingsMigrationService.getOnRegisterConsoleCommands()).willReturn(emptyList());
|
||||
commandConfig.getOnRegister().put("existing", new Command("existing cmd", Executor.PLAYER));
|
||||
CommandConfig configSpy = spy(commandConfig);
|
||||
|
||||
// when
|
||||
boolean result = commandMigrationService.transformOldCommands(configSpy);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(false));
|
||||
verifyZeroInteractions(configSpy);
|
||||
assertThat(configSpy.getOnRegister().keySet(), contains("existing"));
|
||||
assertThat(configSpy.getOnLogin(), anEmptyMap());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void shouldPerformMigration() {
|
||||
// given
|
||||
List<String> onLogin = Collections.singletonList("on login command");
|
||||
given(settingsMigrationService.getOnLoginCommands()).willReturn(onLogin);
|
||||
List<String> onLoginConsole = Arrays.asList("cmd1", "cmd2 %p", "cmd3");
|
||||
given(settingsMigrationService.getOnLoginConsoleCommands()).willReturn(onLoginConsole);
|
||||
given(settingsMigrationService.getOnRegisterCommands()).willReturn(emptyList());
|
||||
List<String> onRegisterConsole = Arrays.asList("log %p registered", "whois %p");
|
||||
given(settingsMigrationService.getOnRegisterConsoleCommands()).willReturn(onRegisterConsole);
|
||||
|
||||
Map<String, Command> onLoginCommands = new LinkedHashMap<>();
|
||||
onLoginCommands.put("bcast", new Command("bcast %p returned", Executor.CONSOLE));
|
||||
commandConfig.setOnLogin(onLoginCommands);
|
||||
Map<String, Command> onRegisterCommands = new LinkedHashMap<>();
|
||||
onRegisterCommands.put("ex_cmd", new Command("existing", Executor.CONSOLE));
|
||||
onRegisterCommands.put("ex_cmd2", new Command("existing2", Executor.PLAYER));
|
||||
commandConfig.setOnRegister(onRegisterCommands);
|
||||
|
||||
// when
|
||||
boolean result = commandMigrationService.transformOldCommands(commandConfig);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
||||
assertThat(commandConfig.getOnLogin(), sameInstance(onLoginCommands));
|
||||
Collection<Command> loginCmdList = onLoginCommands.values();
|
||||
assertThat(loginCmdList, contains(
|
||||
equalTo(onLoginCommands.get("bcast")),
|
||||
isCommand("on login command", Executor.PLAYER),
|
||||
isCommand("cmd1", Executor.CONSOLE),
|
||||
isCommand("cmd2 %p", Executor.CONSOLE),
|
||||
isCommand("cmd3", Executor.CONSOLE)));
|
||||
|
||||
assertThat(commandConfig.getOnRegister(), sameInstance(onRegisterCommands));
|
||||
Collection<Command> registerCmdList = onRegisterCommands.values();
|
||||
assertThat(registerCmdList, contains(
|
||||
isCommand("existing", Executor.CONSOLE),
|
||||
isCommand("existing2", Executor.PLAYER),
|
||||
isCommand("log %p registered", Executor.CONSOLE),
|
||||
isCommand("whois %p", Executor.CONSOLE)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // TODO ConfigMe/#29: Create PropertyResource#getKeys
|
||||
public void shouldRewriteForEmptyFile() {
|
||||
// given
|
||||
File commandFile = TestHelper.getJarFile("/fr/xephi/authme/settings/commandconfig/commands.empty.yml");
|
||||
PropertyResource resource = new YamlFileResource(commandFile);
|
||||
|
||||
// when
|
||||
boolean result = commandMigrationService.checkAndMigrate(
|
||||
resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties());
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package fr.xephi.authme.settings.commandconfig;
|
||||
|
||||
import com.github.authme.configme.knownproperties.ConfigurationDataBuilder;
|
||||
import com.github.authme.configme.resource.PropertyResource;
|
||||
import com.github.authme.configme.resource.YamlFileResource;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.settings.SettingsMigrationService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
/**
|
||||
* Tests that commands.yml is well-formed.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CommandYmlConsistencyTest {
|
||||
|
||||
@InjectMocks
|
||||
private CommandMigrationService commandMigrationService;
|
||||
|
||||
@Mock
|
||||
private SettingsMigrationService settingsMigrationService;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Before
|
||||
public void setUpSettingsMigrationService() {
|
||||
given(settingsMigrationService.getOnLoginCommands()).willReturn(Collections.emptyList());
|
||||
given(settingsMigrationService.getOnLoginConsoleCommands()).willReturn(Collections.emptyList());
|
||||
given(settingsMigrationService.getOnRegisterCommands()).willReturn(Collections.emptyList());
|
||||
given(settingsMigrationService.getOnRegisterConsoleCommands()).willReturn(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldLoadWithNoMigrations() {
|
||||
// given
|
||||
File commandFile = TestHelper.getJarFile("/commands.yml");
|
||||
PropertyResource resource = new YamlFileResource(commandFile);
|
||||
|
||||
// when
|
||||
boolean result = commandMigrationService.checkAndMigrate(
|
||||
resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties());
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(false));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package fr.xephi.authme.settings.properties;
|
||||
|
||||
import com.github.authme.configme.knownproperties.ConfigurationData;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.closeTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Test for {@link AuthMeSettingsRetriever}.
|
||||
*/
|
||||
public class AuthMeSettingsRetrieverTest {
|
||||
|
||||
@Test
|
||||
public void shouldReturnAllProperties() {
|
||||
// given / when
|
||||
ConfigurationData configurationData = AuthMeSettingsRetriever.buildConfigurationData();
|
||||
|
||||
// then
|
||||
// Note ljacqu 20161123: Check that the number of properties returned corresponds to what we expect with
|
||||
// an error margin of 10: this prevents us from having to adjust the test every time the config is changed.
|
||||
// If this test fails, replace the first argument in closeTo() with the new number of properties
|
||||
assertThat((double) configurationData.getProperties().size(),
|
||||
closeTo(150, 10));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveHiddenConstructor() {
|
||||
TestHelper.validateHasOnlyPrivateEmptyConstructor(AuthMeSettingsRetriever.class);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@ import fr.xephi.authme.data.limbo.LimboCache;
|
||||
import fr.xephi.authme.data.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.message.Messages;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -17,13 +17,10 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
@@ -174,11 +171,8 @@ public class LimboPlayerTaskManagerTest {
|
||||
@Test
|
||||
public void shouldNotRegisterTimeoutTaskForZeroTimeout() {
|
||||
// given
|
||||
String name = "snail";
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn(name);
|
||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||
given(limboCache.getPlayerData(name)).willReturn(limboPlayer);
|
||||
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(0);
|
||||
|
||||
// when
|
||||
|
||||
@@ -4,9 +4,9 @@ import fr.xephi.authme.ReflectionTestUtils;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.PurgeSettings;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -16,7 +16,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
@@ -32,15 +32,15 @@ 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.anyCollection;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.anyCollectionOf;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link PurgeService}.
|
||||
@@ -100,7 +100,6 @@ public class PurgeServiceTest {
|
||||
given(settings.getProperty(PurgeSettings.DAYS_BEFORE_REMOVE_PLAYER)).willReturn(60);
|
||||
Set<String> playerNames = newHashSet("alpha", "bravo", "charlie", "delta");
|
||||
given(dataSource.getRecordsToPurge(anyLong(), eq(false))).willReturn(playerNames);
|
||||
mockReturnedOfflinePlayers();
|
||||
|
||||
// when
|
||||
purgeService.runAutoPurge();
|
||||
@@ -119,7 +118,7 @@ public class PurgeServiceTest {
|
||||
// given
|
||||
final long delay = 123012301L;
|
||||
final boolean includeLastLoginZeroEntries = true;
|
||||
given(dataSource.getRecordsToPurge(delay, includeLastLoginZeroEntries)).willReturn(Collections.<String>emptySet());
|
||||
given(dataSource.getRecordsToPurge(delay, includeLastLoginZeroEntries)).willReturn(Collections.emptySet());
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
@@ -127,7 +126,7 @@ public class PurgeServiceTest {
|
||||
|
||||
// then
|
||||
verify(dataSource).getRecordsToPurge(delay, includeLastLoginZeroEntries);
|
||||
verify(dataSource, never()).purgeRecords(anyCollectionOf(String.class));
|
||||
verify(dataSource, never()).purgeRecords(anyCollection());
|
||||
verify(sender).sendMessage("No players to purge");
|
||||
verifyZeroInteractions(bukkitService, permissionsManager);
|
||||
}
|
||||
@@ -139,7 +138,6 @@ public class PurgeServiceTest {
|
||||
final boolean includeLastLoginZeroEntries = false;
|
||||
Set<String> playerNames = newHashSet("charlie", "delta", "echo", "foxtrot");
|
||||
given(dataSource.getRecordsToPurge(delay, includeLastLoginZeroEntries)).willReturn(playerNames);
|
||||
mockReturnedOfflinePlayers();
|
||||
Player sender = mock(Player.class);
|
||||
UUID uuid = UUID.randomUUID();
|
||||
given(sender.getUniqueId()).willReturn(uuid);
|
||||
@@ -157,10 +155,10 @@ public class PurgeServiceTest {
|
||||
// given
|
||||
purgeService.setPurging(true);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
OfflinePlayer[] players = mockReturnedOfflinePlayers();
|
||||
OfflinePlayer[] offlinePlayers = new OfflinePlayer[]{mock(OfflinePlayer.class), mock(OfflinePlayer.class)};
|
||||
|
||||
// when
|
||||
purgeService.purgePlayers(sender, newHashSet("test", "names"), players);
|
||||
purgeService.purgePlayers(sender, newHashSet("test", "names"), offlinePlayers);
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString("Purge is already in progress")));
|
||||
@@ -170,32 +168,15 @@ public class PurgeServiceTest {
|
||||
@Test
|
||||
public void shouldExecutePurgeActions() {
|
||||
// given
|
||||
List<OfflinePlayer> players = Arrays.asList(mockReturnedOfflinePlayers());
|
||||
List<String> names = Arrays.asList("alpha", "bravo", "foxtrot");
|
||||
List<OfflinePlayer> offlinePlayers = Arrays.asList(
|
||||
mock(OfflinePlayer.class), mock(OfflinePlayer.class), mock(OfflinePlayer.class));
|
||||
|
||||
// when
|
||||
purgeService.executePurge(players, names);
|
||||
purgeService.executePurge(offlinePlayers, names);
|
||||
|
||||
// then
|
||||
verify(executor).executePurge(players, names);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns mock OfflinePlayer objects with names corresponding to A - G of the NATO phonetic alphabet,
|
||||
* in various casing.
|
||||
*
|
||||
* @return list of offline players BukkitService is mocked to return
|
||||
*/
|
||||
private OfflinePlayer[] mockReturnedOfflinePlayers() {
|
||||
String[] names = { "alfa", "Bravo", "charLIE", "delta", "ECHO", "Foxtrot", "golf" };
|
||||
OfflinePlayer[] players = new OfflinePlayer[names.length];
|
||||
for (int i = 0; i < names.length; ++i) {
|
||||
OfflinePlayer player = mock(OfflinePlayer.class);
|
||||
given(player.getName()).willReturn(names[i]);
|
||||
players[i] = player;
|
||||
}
|
||||
given(bukkitService.getOfflinePlayers()).willReturn(players);
|
||||
return players;
|
||||
verify(executor).executePurge(offlinePlayers, names);
|
||||
}
|
||||
|
||||
private void assertCorrectPurgeTimestamp(long timestamp, int configuredDays) {
|
||||
|
||||
@@ -19,7 +19,7 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -35,16 +35,16 @@ import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link PurgeTask}.
|
||||
@@ -124,6 +124,27 @@ public class PurgeTaskTest {
|
||||
assertRanPurgeWithNames("foxtrot");
|
||||
}
|
||||
|
||||
/**
|
||||
* #1008: OfflinePlayer#getName may return null.
|
||||
*/
|
||||
@Test
|
||||
public void shouldHandleOfflinePlayerWithNullName() {
|
||||
// given
|
||||
Set<String> names = newHashSet("name1", "name2");
|
||||
OfflinePlayer[] players = asArray(
|
||||
mockOfflinePlayer(null, false), mockOfflinePlayer("charlie", false), mockOfflinePlayer("name1", false));
|
||||
reset(purgeService, permissionsManager);
|
||||
setPermissionsBehavior();
|
||||
|
||||
PurgeTask task = new PurgeTask(purgeService, permissionsManager, null, names, players);
|
||||
|
||||
// when
|
||||
task.run();
|
||||
|
||||
// then
|
||||
assertRanPurgeWithPlayers(players[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldStopTaskAndInformSenderUponCompletion() {
|
||||
// given
|
||||
@@ -191,7 +212,7 @@ public class PurgeTaskTest {
|
||||
.willAnswer(new Answer<Boolean>() {
|
||||
@Override
|
||||
public Boolean answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||
OfflinePlayer player = (OfflinePlayer) invocationOnMock.getArguments()[0];
|
||||
OfflinePlayer player = invocationOnMock.getArgument(0);
|
||||
Boolean hasPermission = playerBypassAssignments.get(player);
|
||||
if (hasPermission == null) {
|
||||
throw new IllegalStateException("Unexpected check of '" + BYPASS_NODE
|
||||
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.security;
|
||||
package fr.xephi.authme.util;
|
||||
|
||||
import fr.xephi.authme.util.RandomStringUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user