mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-23 18:55:11 +01:00
Merge branch 'master' into 674-purge-process-refactor
This commit is contained in:
commit
fde634e054
@ -723,15 +723,6 @@ public class AuthMe extends JavaPlugin {
|
||||
// Service getters (deprecated)
|
||||
// Use @Inject fields instead
|
||||
// -------------
|
||||
/**
|
||||
* @return Plugin's messages.
|
||||
* @deprecated should be used in API classes only (temporarily)
|
||||
*/
|
||||
@Deprecated
|
||||
public Messages getMessages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return NewSetting
|
||||
* @deprecated should be used in API classes only (temporarily)
|
||||
|
@ -93,13 +93,12 @@ public class UnregisterAdminCommand implements ExecutableCommand {
|
||||
* @param target the player that was unregistered
|
||||
*/
|
||||
private void applyUnregisteredEffectsAndTasks(Player target) {
|
||||
// TODO ljacqu 20160612: Remove use of Utils method and behave according to settings
|
||||
// TODO #765: Remove use of Utils method and behave according to settings
|
||||
Utils.teleportToSpawn(target);
|
||||
|
||||
limboCache.addLimboPlayer(target);
|
||||
limboPlayerTaskManager.registerTimeoutTask(target);
|
||||
limboPlayerTaskManager.registerMessageTask(target.getName(),
|
||||
MessageKey.REGISTER_MESSAGE);
|
||||
limboPlayerTaskManager.registerMessageTask(target.getName(), false);
|
||||
|
||||
final int timeout = commandService.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||
if (commandService.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
|
||||
|
@ -1,13 +1,10 @@
|
||||
package fr.xephi.authme.command.executable.changepassword;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.task.ChangePasswordTask;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.util.ValidationService;
|
||||
import fr.xephi.authme.util.ValidationService.ValidationResult;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -26,15 +23,11 @@ public class ChangePasswordCommand extends PlayerCommand {
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Inject
|
||||
private ValidationService validationService;
|
||||
|
||||
@Inject
|
||||
// TODO ljacqu 20160531: Remove this once change password task runs as a process (via Management)
|
||||
private PasswordSecurity passwordSecurity;
|
||||
private Management management;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
@ -54,9 +47,6 @@ public class ChangePasswordCommand extends PlayerCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
AuthMe plugin = AuthMe.getInstance();
|
||||
// TODO ljacqu 20160117: Call async task via Management
|
||||
bukkitService.runTaskAsynchronously(
|
||||
new ChangePasswordTask(plugin, player, oldPassword, newPassword, passwordSecurity));
|
||||
management.performPasswordChange(player, oldPassword, newPassword);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package fr.xephi.authme.process;
|
||||
|
||||
import fr.xephi.authme.process.changepassword.AsyncChangePassword;
|
||||
import fr.xephi.authme.process.email.AsyncAddEmail;
|
||||
import fr.xephi.authme.process.email.AsyncChangeEmail;
|
||||
import fr.xephi.authme.process.join.AsynchronousJoin;
|
||||
@ -36,9 +37,12 @@ public class Management {
|
||||
private AsynchronousLogin asynchronousLogin;
|
||||
@Inject
|
||||
private AsynchronousUnregister asynchronousUnregister;
|
||||
@Inject
|
||||
private AsyncChangePassword asyncChangePassword;
|
||||
|
||||
Management() { }
|
||||
|
||||
|
||||
public void performLogin(final Player player, final String password, final boolean forceLogin) {
|
||||
runTask(new Runnable() {
|
||||
@Override
|
||||
@ -111,6 +115,15 @@ public class Management {
|
||||
});
|
||||
}
|
||||
|
||||
public void performPasswordChange(final Player player, final String oldPassword, final String newPassword) {
|
||||
runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
asyncChangePassword.changePassword(player, oldPassword, newPassword);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void runTask(Runnable runnable) {
|
||||
bukkitService.runTaskAsynchronously(runnable);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package fr.xephi.authme.task;
|
||||
package fr.xephi.authme.process.changepassword;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
@ -6,52 +6,60 @@ import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.process.AsynchronousProcess;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ChangePasswordTask implements Runnable {
|
||||
import javax.inject.Inject;
|
||||
|
||||
private final AuthMe plugin;
|
||||
private final Player player;
|
||||
private final String oldPassword;
|
||||
private final String newPassword;
|
||||
private final PasswordSecurity passwordSecurity;
|
||||
public class AsyncChangePassword implements AsynchronousProcess {
|
||||
|
||||
public ChangePasswordTask(AuthMe plugin, Player player, String oldPassword, String newPassword,
|
||||
PasswordSecurity passwordSecurity) {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
this.oldPassword = oldPassword;
|
||||
this.newPassword = newPassword;
|
||||
this.passwordSecurity = passwordSecurity;
|
||||
}
|
||||
@Inject
|
||||
private AuthMe plugin;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Messages m = plugin.getMessages();
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private ProcessService processService;
|
||||
|
||||
@Inject
|
||||
private PasswordSecurity passwordSecurity;
|
||||
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
AsyncChangePassword() { }
|
||||
|
||||
|
||||
public void changePassword(final Player player, String oldPassword, String newPassword) {
|
||||
final String name = player.getName().toLowerCase();
|
||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
|
||||
PlayerAuth auth = playerCache.getAuth(name);
|
||||
if (passwordSecurity.comparePassword(oldPassword, auth.getPassword(), player.getName())) {
|
||||
HashedPassword hashedPassword = passwordSecurity.computeHash(newPassword, name);
|
||||
auth.setPassword(hashedPassword);
|
||||
|
||||
if (!plugin.getDataSource().updatePassword(auth)) {
|
||||
m.send(player, MessageKey.ERROR);
|
||||
if (!dataSource.updatePassword(auth)) {
|
||||
processService.send(player, MessageKey.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerCache.getInstance().updatePlayer(auth);
|
||||
m.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
||||
playerCache.updatePlayer(auth);
|
||||
processService.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
||||
ConsoleLogger.info(player.getName() + " changed his password");
|
||||
if (Settings.bungee) {
|
||||
if (processService.getProperty(HooksSettings.BUNGEECORD)) {
|
||||
final String hash = hashedPassword.getHash();
|
||||
final String salt = hashedPassword.getSalt();
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
|
||||
|
||||
bukkitService.scheduleSyncDelayedTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
@ -64,7 +72,7 @@ public class ChangePasswordTask implements Runnable {
|
||||
});
|
||||
}
|
||||
} else {
|
||||
m.send(player, MessageKey.WRONG_PASSWORD);
|
||||
processService.send(player, MessageKey.WRONG_PASSWORD);
|
||||
}
|
||||
}
|
||||
}
|
@ -195,16 +195,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
|
||||
// Timeout and message task
|
||||
limboPlayerTaskManager.registerTimeoutTask(player);
|
||||
|
||||
MessageKey msg;
|
||||
if (isAuthAvailable) {
|
||||
msg = MessageKey.LOGIN_MESSAGE;
|
||||
} else {
|
||||
msg = service.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)
|
||||
? MessageKey.REGISTER_EMAIL_MESSAGE
|
||||
: MessageKey.REGISTER_MESSAGE;
|
||||
}
|
||||
limboPlayerTaskManager.registerMessageTask(name, msg);
|
||||
limboPlayerTaskManager.registerMessageTask(name, isAuthAvailable);
|
||||
}
|
||||
|
||||
private boolean isPlayerUnrestricted(String name) {
|
||||
|
@ -21,7 +21,6 @@ import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.task.LimboPlayerTaskManager;
|
||||
@ -33,7 +32,6 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -108,10 +106,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
||||
service.send(player, MessageKey.USER_NOT_REGISTERED);
|
||||
|
||||
// TODO ljacqu 20160612: Why is the message task being canceled and added again here?
|
||||
MessageKey key = service.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)
|
||||
? MessageKey.REGISTER_EMAIL_MESSAGE
|
||||
: MessageKey.REGISTER_MESSAGE;
|
||||
limboPlayerTaskManager.registerMessageTask(name, key);
|
||||
limboPlayerTaskManager.registerMessageTask(name, false);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
|
||||
}
|
||||
|
||||
limboPlayerTaskManager.registerTimeoutTask(player);
|
||||
limboPlayerTaskManager.registerMessageTask(name, MessageKey.LOGIN_MESSAGE);
|
||||
limboPlayerTaskManager.registerMessageTask(name, true);
|
||||
|
||||
if (player.isInsideVehicle() && player.getVehicle() != null) {
|
||||
player.getVehicle().eject();
|
||||
|
@ -33,7 +33,7 @@ public class ProcessSyncEmailRegister implements SynchronousProcess {
|
||||
service.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
|
||||
|
||||
limboPlayerTaskManager.registerTimeoutTask(player);
|
||||
limboPlayerTaskManager.registerMessageTask(name, MessageKey.LOGIN_MESSAGE);
|
||||
limboPlayerTaskManager.registerMessageTask(name, true);
|
||||
|
||||
player.saveData();
|
||||
if (!service.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) {
|
||||
|
@ -81,7 +81,7 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
|
||||
|
||||
limboCache.updateLimboPlayer(player);
|
||||
limboPlayerTaskManager.registerTimeoutTask(player);
|
||||
limboPlayerTaskManager.registerMessageTask(name, MessageKey.LOGIN_MESSAGE);
|
||||
limboPlayerTaskManager.registerMessageTask(name, true);
|
||||
|
||||
if (player.isInsideVehicle() && player.getVehicle() != null) {
|
||||
player.getVehicle().eject();
|
||||
|
@ -64,7 +64,7 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
||||
}
|
||||
limboCache.addLimboPlayer(player);
|
||||
limboPlayerTaskManager.registerTimeoutTask(player);
|
||||
limboPlayerTaskManager.registerMessageTask(name, MessageKey.REGISTER_MESSAGE);
|
||||
limboPlayerTaskManager.registerMessageTask(name, false);
|
||||
|
||||
service.send(player, MessageKey.UNREGISTERED_SUCCESS);
|
||||
ConsoleLogger.info(player.getDisplayName() + " unregistered himself");
|
||||
|
@ -2,7 +2,6 @@ package fr.xephi.authme.settings;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.settings.domain.Property;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
@ -26,7 +25,6 @@ public final class Settings {
|
||||
public static boolean protectInventoryBeforeLogInEnabled;
|
||||
public static boolean isStopEnabled;
|
||||
public static boolean reloadSupport;
|
||||
public static boolean bungee;
|
||||
public static boolean forceRegLogin;
|
||||
public static boolean noTeleport;
|
||||
public static boolean isRemoveSpeedEnabled;
|
||||
@ -65,7 +63,6 @@ public final class Settings {
|
||||
protectInventoryBeforeLogInEnabled = load(RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN);
|
||||
isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true);
|
||||
reloadSupport = configFile.getBoolean("Security.ReloadCommand.useReloadCommandSupport", true);
|
||||
bungee = load(HooksSettings.BUNGEECORD);
|
||||
defaultWorld = configFile.getString("Purge.defaultWorld", "world");
|
||||
forceRegLogin = load(RegistrationSettings.FORCE_LOGIN_AFTER_REGISTER);
|
||||
noTeleport = load(RestrictionSettings.NO_TELEPORT);
|
||||
|
@ -44,10 +44,12 @@ public class LimboPlayerTaskManager {
|
||||
* Registers a {@link MessageTask} for the given player name.
|
||||
*
|
||||
* @param name the name of the player to schedule a repeating message task for
|
||||
* @param key the key of the message to display
|
||||
* @param isRegistered whether the name is registered or not
|
||||
* (false shows "please register", true shows "please log in")
|
||||
*/
|
||||
public void registerMessageTask(String name, MessageKey key) {
|
||||
public void registerMessageTask(String name, boolean isRegistered) {
|
||||
final int interval = settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
final MessageKey key = getMessageKey(isRegistered);
|
||||
if (interval > 0) {
|
||||
final LimboPlayer limboPlayer = limboCache.getLimboPlayer(name);
|
||||
if (limboPlayer == null) {
|
||||
@ -81,6 +83,22 @@ public class LimboPlayerTaskManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the appropriate message key according to the registration status and settings.
|
||||
*
|
||||
* @param isRegistered whether or not the username is registered
|
||||
* @return the message key to display to the user
|
||||
*/
|
||||
private MessageKey getMessageKey(boolean isRegistered) {
|
||||
if (isRegistered) {
|
||||
return MessageKey.LOGIN_MESSAGE;
|
||||
} else {
|
||||
return settings.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)
|
||||
? MessageKey.REGISTER_EMAIL_MESSAGE
|
||||
: MessageKey.REGISTER_MESSAGE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Null-safe method to cancel a potentially existing task.
|
||||
*
|
||||
|
@ -1,4 +1,7 @@
|
||||
# Lingua Italiana creata da Maxetto e sgdc3.
|
||||
denied_command: '&cPer poter usare questo comando devi essere autenticato!'
|
||||
same_ip_online: 'Un giocatore con il tuo stesso IP è già connesso sul server!'
|
||||
denied_chat: '&cPer poter scrivere messaggi in chat devi essere autenticato!'
|
||||
kick_antibot: 'Il servizio di AntiBot è attualmente attivo! Devi aspettare qualche minuto prima di poter entrare nel server.'
|
||||
unknown_user: '&cL''utente non è presente nel database.'
|
||||
unsafe_spawn: '&cIl tuo punto di disconnessione risulta ostruito o insicuro, sei stato teletrasportato al punto di rigenerazione!'
|
||||
@ -30,7 +33,7 @@ invalid_session: '&cIl tuo indirizzo IP è cambiato e la tua sessione è stata t
|
||||
reg_only: '&4Puoi giocare in questo server solo dopo aver effettuato la registrazione attraverso il sito web! Per favore, vai su http://esempio.it per procedere!'
|
||||
logged_in: '&cHai già eseguito l''autenticazione, non è necessario eseguirla nuovamente!'
|
||||
logout: '&2Disconnessione avvenuta correttamente!'
|
||||
same_nick: '&4Questo stesso nome utente è già online sul server!'
|
||||
same_nick: '&4Un giocatore con il tuo stesso nome utente è già connesso sul server!'
|
||||
registered: '&2Registrato correttamente!'
|
||||
pass_len: '&cLa password che hai inserito è troppo corta o troppo lunga, per favore scegline un''altra...'
|
||||
reload: '&2La configurazione e il database sono stati ricaricati correttamente!'
|
||||
@ -63,6 +66,6 @@ email_already_used: '&4L''indirizzo email inserito è già in uso'
|
||||
two_factor_create: '&2Il tuo codice segreto è: &f%code&n&2Puoi anche scannerizzare il codice QR da qui: &f%url'
|
||||
not_owner_error: 'Non sei il proprietario di questo account. Per favore scegli un altro nome!'
|
||||
invalid_name_case: 'Dovresti entrare con questo nome utente: "%valid", al posto di: "%invalid".'
|
||||
# TODO denied_command: '&cIn order to use this command you must be authenticated!'
|
||||
# TODO same_ip_online: 'A player with the same IP is already in game!'
|
||||
# TODO denied_chat: '&cIn order to chat you must be authenticated!'
|
||||
tempban_max_logins: '&cSei stato temporaneamente bandito per aver fallito l''autenticazione troppe volte.'
|
||||
accounts_owned_self: 'Possiedi %count account:'
|
||||
accounts_owned_other: 'Il giocatore %name possiede %count account:'
|
||||
|
@ -56,8 +56,6 @@ public class CommandHandlerTest {
|
||||
@Mock
|
||||
private AuthMeServiceInitializer initializer;
|
||||
@Mock
|
||||
private CommandInitializer commandInitializer;
|
||||
@Mock
|
||||
private CommandMapper commandMapper;
|
||||
@Mock
|
||||
private PermissionsManager permissionsManager;
|
||||
|
@ -36,8 +36,6 @@ public class AccountsCommandTest {
|
||||
@InjectMocks
|
||||
private AccountsCommand command;
|
||||
@Mock
|
||||
private CommandSender sender;
|
||||
@Mock
|
||||
private CommandService service;
|
||||
@Mock
|
||||
private DataSource dataSource;
|
||||
@ -47,6 +45,7 @@ public class AccountsCommandTest {
|
||||
@Test
|
||||
public void shouldGetAccountsOfCurrentUser() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(sender.getName()).willReturn("Tester");
|
||||
List<String> arguments = Collections.emptyList();
|
||||
given(dataSource.getAuth("tester")).willReturn(authWithIp("123.45.67.89"));
|
||||
@ -65,6 +64,7 @@ public class AccountsCommandTest {
|
||||
@Test
|
||||
public void shouldReturnUnknownUserForNullAuth() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
List<String> arguments = Collections.singletonList("SomeUser");
|
||||
given(dataSource.getAuth("someuser")).willReturn(null);
|
||||
|
||||
@ -80,6 +80,7 @@ public class AccountsCommandTest {
|
||||
@Test
|
||||
public void shouldReturnUnregisteredMessageForEmptyAuthList() {
|
||||
// given
|
||||
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());
|
||||
@ -96,6 +97,7 @@ public class AccountsCommandTest {
|
||||
@Test
|
||||
public void shouldReturnSingleAccountMessage() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
List<String> arguments = Collections.singletonList("SomeUser");
|
||||
given(dataSource.getAuth("someuser")).willReturn(authWithIp("56.78.90.123"));
|
||||
given(dataSource.getAllAuthsByIp("56.78.90.123")).willReturn(Collections.singletonList("SomeUser"));
|
||||
@ -115,6 +117,7 @@ public class AccountsCommandTest {
|
||||
@Test
|
||||
public void shouldReturnIpUnknown() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
List<String> arguments = Collections.singletonList("123.45.67.89");
|
||||
given(dataSource.getAllAuthsByIp("123.45.67.89")).willReturn(Collections.<String>emptyList());
|
||||
|
||||
@ -130,6 +133,7 @@ public class AccountsCommandTest {
|
||||
@Test
|
||||
public void shouldReturnSingleAccountForIpQuery() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
List<String> arguments = Collections.singletonList("24.24.48.48");
|
||||
given(dataSource.getAllAuthsByIp("24.24.48.48")).willReturn(Collections.singletonList("SomeUser"));
|
||||
|
||||
@ -145,6 +149,7 @@ public class AccountsCommandTest {
|
||||
@Test
|
||||
public void shouldReturnAccountListForIpQuery() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
List<String> arguments = Collections.singletonList("98.76.41.122");
|
||||
given(dataSource.getAllAuthsByIp("98.76.41.122")).willReturn(Arrays.asList("Tester", "Lester", "Taster"));
|
||||
|
||||
|
@ -1,13 +1,11 @@
|
||||
package fr.xephi.authme.command.executable.changepassword;
|
||||
|
||||
import fr.xephi.authme.ReflectionTestUtils;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.output.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.task.ChangePasswordTask;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.util.ValidationService;
|
||||
import fr.xephi.authme.util.ValidationService.ValidationResult;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
@ -16,7 +14,6 @@ import org.bukkit.entity.Player;
|
||||
import org.junit.Before;
|
||||
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;
|
||||
@ -26,8 +23,6 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
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.any;
|
||||
@ -46,18 +41,18 @@ public class ChangePasswordCommandTest {
|
||||
@InjectMocks
|
||||
private ChangePasswordCommand command;
|
||||
|
||||
@Mock
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@Mock
|
||||
private ValidationService validationService;
|
||||
|
||||
@Mock
|
||||
private Management management;
|
||||
|
||||
@Before
|
||||
public void setSettings() {
|
||||
when(commandService.getProperty(SecuritySettings.MIN_PASSWORD_LENGTH)).thenReturn(2);
|
||||
@ -110,20 +105,18 @@ public class ChangePasswordCommandTest {
|
||||
@Test
|
||||
public void shouldForwardTheDataForValidPassword() {
|
||||
// given
|
||||
CommandSender sender = initPlayerWithName("parker", true);
|
||||
String oldPass = "oldpass";
|
||||
String newPass = "abc123";
|
||||
Player player = initPlayerWithName("parker", true);
|
||||
given(validationService.validatePassword("abc123", "parker")).willReturn(new ValidationResult());
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList("abc123", "abc123"));
|
||||
command.executeCommand(player, Arrays.asList(oldPass, newPass));
|
||||
|
||||
// then
|
||||
verify(validationService).validatePassword("abc123", "parker");
|
||||
verify(commandService, never()).send(eq(sender), any(MessageKey.class));
|
||||
ArgumentCaptor<ChangePasswordTask> taskCaptor = ArgumentCaptor.forClass(ChangePasswordTask.class);
|
||||
verify(bukkitService).runTaskAsynchronously(taskCaptor.capture());
|
||||
ChangePasswordTask task = taskCaptor.getValue();
|
||||
assertThat((String) ReflectionTestUtils.getFieldValue(ChangePasswordTask.class, task, "newPassword"),
|
||||
equalTo("abc123"));
|
||||
verify(validationService).validatePassword(newPass, "parker");
|
||||
verify(commandService, never()).send(eq(player), any(MessageKey.class));
|
||||
verify(management).performPasswordChange(player, oldPass, newPass);
|
||||
}
|
||||
|
||||
private Player initPlayerWithName(String name, boolean loggedIn) {
|
||||
|
@ -316,6 +316,22 @@ public class AuthMeServiceInitializerTest {
|
||||
initializer.performReloadOnServices();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRetrieveExistingInstancesOnly() {
|
||||
// given
|
||||
initializer.get(GammaService.class);
|
||||
|
||||
// when
|
||||
AlphaService alphaService = initializer.getIfAvailable(AlphaService.class);
|
||||
BetaManager betaManager = initializer.getIfAvailable(BetaManager.class);
|
||||
|
||||
// then
|
||||
// was initialized because is dependency of GammaService
|
||||
assertThat(alphaService, not(nullValue()));
|
||||
// nothing caused this to be initialized
|
||||
assertThat(betaManager, nullValue());
|
||||
}
|
||||
|
||||
private void expectRuntimeExceptionWith(String message) {
|
||||
expectedException.expect(RuntimeException.class);
|
||||
expectedException.expectMessage(containsString(message));
|
||||
|
@ -2,6 +2,8 @@ package fr.xephi.authme.process;
|
||||
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.AuthGroupHandler;
|
||||
import fr.xephi.authme.permission.AuthGroupType;
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
@ -43,6 +45,9 @@ public class ProcessServiceTest {
|
||||
@Mock
|
||||
private PermissionsManager permissionsManager;
|
||||
|
||||
@Mock
|
||||
private AuthGroupHandler authGroupHandler;
|
||||
|
||||
@Test
|
||||
public void shouldGetProperty() {
|
||||
// given
|
||||
@ -166,4 +171,19 @@ public class ProcessServiceTest {
|
||||
verify(permissionsManager).hasPermission(player, permission);
|
||||
assertThat(result, equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSetPermissionGroup() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
AuthGroupType type = AuthGroupType.LOGGED_IN;
|
||||
given(authGroupHandler.setGroup(player, type)).willReturn(true);
|
||||
|
||||
// when
|
||||
boolean result = processService.setGroup(player, type);
|
||||
|
||||
// then
|
||||
verify(authGroupHandler).setGroup(player, type);
|
||||
assertThat(result, equalTo(true));
|
||||
}
|
||||
}
|
||||
|
@ -67,9 +67,10 @@ public class LimboPlayerTaskManagerTest {
|
||||
BukkitTask bukkiTask = mock(BukkitTask.class);
|
||||
given(bukkitService.runTask(any(MessageTask.class))).willReturn(bukkiTask);
|
||||
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(12);
|
||||
given(settings.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||
|
||||
// when
|
||||
limboPlayerTaskManager.registerMessageTask(name, key);
|
||||
limboPlayerTaskManager.registerMessageTask(name, false);
|
||||
|
||||
// then
|
||||
verify(limboPlayer).setMessageTask(bukkiTask);
|
||||
@ -81,12 +82,10 @@ public class LimboPlayerTaskManagerTest {
|
||||
// given
|
||||
String name = "ghost";
|
||||
given(limboCache.getLimboPlayer(name)).willReturn(null);
|
||||
MessageKey key = MessageKey.REGISTER_MESSAGE;
|
||||
given(messages.retrieve(key)).willReturn(new String[]{"Please register!"});
|
||||
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(5);
|
||||
|
||||
// when
|
||||
limboPlayerTaskManager.registerMessageTask(name, key);
|
||||
limboPlayerTaskManager.registerMessageTask(name, true);
|
||||
|
||||
// then
|
||||
verify(limboCache).getLimboPlayer(name);
|
||||
@ -100,14 +99,12 @@ public class LimboPlayerTaskManagerTest {
|
||||
String name = "Tester1";
|
||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||
given(limboCache.getLimboPlayer(name)).willReturn(limboPlayer);
|
||||
MessageKey key = MessageKey.REGISTER_EMAIL_MESSAGE;
|
||||
given(messages.retrieve(key)).willReturn(new String[]{"Please register!"});
|
||||
BukkitTask bukkiTask = mock(BukkitTask.class);
|
||||
given(bukkitService.runTask(any(MessageTask.class))).willReturn(bukkiTask);
|
||||
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(0);
|
||||
|
||||
// when
|
||||
limboPlayerTaskManager.registerMessageTask(name, key);
|
||||
limboPlayerTaskManager.registerMessageTask(name, true);
|
||||
|
||||
// then
|
||||
verifyZeroInteractions(limboPlayer, bukkitService);
|
||||
@ -122,19 +119,20 @@ public class LimboPlayerTaskManagerTest {
|
||||
|
||||
String name = "bobby";
|
||||
given(limboCache.getLimboPlayer(name)).willReturn(limboPlayer);
|
||||
MessageKey key = MessageKey.REGISTER_EMAIL_MESSAGE;
|
||||
given(messages.retrieve(key)).willReturn(new String[]{"Please register", "Use /register"});
|
||||
given(messages.retrieve(MessageKey.REGISTER_EMAIL_MESSAGE))
|
||||
.willReturn(new String[]{"Please register", "Use /register"});
|
||||
|
||||
BukkitTask bukkiTask = mock(BukkitTask.class);
|
||||
given(bukkitService.runTask(any(MessageTask.class))).willReturn(bukkiTask);
|
||||
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(8);
|
||||
given(settings.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||
|
||||
// when
|
||||
limboPlayerTaskManager.registerMessageTask(name, key);
|
||||
limboPlayerTaskManager.registerMessageTask(name, false);
|
||||
|
||||
// then
|
||||
verify(limboPlayer).setMessageTask(bukkiTask);
|
||||
verify(messages).retrieve(key);
|
||||
verify(messages).retrieve(MessageKey.REGISTER_EMAIL_MESSAGE);
|
||||
verify(existingMessageTask).cancel();
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package fr.xephi.authme.util;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
@ -145,4 +146,9 @@ public class StringUtilsTest {
|
||||
// then
|
||||
assertThat(result, equalTo("path" + File.separator + "to" + File.separator + "test-file.txt"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveHiddenConstructor() {
|
||||
TestHelper.validateHasOnlyPrivateEmptyConstructor(StringUtils.class);
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.events.FirstSpawnTeleportEvent;
|
||||
import fr.xephi.authme.events.SpawnTeleportEvent;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
@ -48,9 +47,6 @@ public class TeleportationServiceTest {
|
||||
@Mock
|
||||
private NewSetting settings;
|
||||
|
||||
@Mock
|
||||
private Messages messages;
|
||||
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user