mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-25 18:17:34 +01:00
Make AuthMe.management private; create test for CaptchaCommand
This commit is contained in:
parent
f698c9241b
commit
1ca6bcffe1
@ -73,7 +73,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
private static Server server;
|
private static Server server;
|
||||||
private static Wrapper wrapper = Wrapper.getInstance();
|
private static Wrapper wrapper = Wrapper.getInstance();
|
||||||
|
|
||||||
public Management management;
|
private Management management;
|
||||||
public NewAPI api;
|
public NewAPI api;
|
||||||
public SendMailSSL mail;
|
public SendMailSSL mail;
|
||||||
public DataManager dataManager;
|
public DataManager dataManager;
|
||||||
|
@ -170,7 +170,7 @@ public class API {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static void forceLogin(Player player) {
|
public static void forceLogin(Player player) {
|
||||||
instance.management.performLogin(player, "dontneed", true);
|
instance.getManagement().performLogin(player, "dontneed", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -170,7 +170,7 @@ public class NewAPI {
|
|||||||
* @param player * player
|
* @param player * player
|
||||||
*/
|
*/
|
||||||
public void forceLogin(Player player) {
|
public void forceLogin(Player player) {
|
||||||
plugin.management.performLogin(player, "dontneed", true);
|
plugin.getManagement().performLogin(player, "dontneed", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -179,7 +179,7 @@ public class NewAPI {
|
|||||||
* @param player * player
|
* @param player * player
|
||||||
*/
|
*/
|
||||||
public void forceLogout(Player player) {
|
public void forceLogout(Player player) {
|
||||||
plugin.management.performLogout(player);
|
plugin.getManagement().performLogout(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -189,7 +189,7 @@ public class NewAPI {
|
|||||||
* @param password String
|
* @param password String
|
||||||
*/
|
*/
|
||||||
public void forceRegister(Player player, String password) {
|
public void forceRegister(Player player, String password) {
|
||||||
plugin.management.performRegister(player, password, null);
|
plugin.getManagement().performRegister(player, password, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -198,6 +198,6 @@ public class NewAPI {
|
|||||||
* @param player * player
|
* @param player * player
|
||||||
*/
|
*/
|
||||||
public void forceUnregister(Player player) {
|
public void forceUnregister(Player player) {
|
||||||
plugin.management.performUnregister(player, "", true);
|
plugin.getManagement().performUnregister(player, "", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ public class ForceLoginCommand extends ExecutableCommand {
|
|||||||
sender.sendMessage("You cannot force login for the player " + playerName + "!");
|
sender.sendMessage("You cannot force login for the player " + playerName + "!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
plugin.management.performLogin(player, "dontneed", true);
|
plugin.getManagement().performLogin(player, "dontneed", true);
|
||||||
sender.sendMessage("Force Login for " + playerName + " performed!");
|
sender.sendMessage("Force Login for " + playerName + " performed!");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
sender.sendMessage("An error occurred while trying to get that player!");
|
sender.sendMessage("An error occurred while trying to get that player!");
|
||||||
|
@ -8,6 +8,7 @@ import fr.xephi.authme.security.RandomString;
|
|||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.output.Messages;
|
import fr.xephi.authme.output.Messages;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.util.Wrapper;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -30,10 +31,11 @@ public class CaptchaCommand extends ExecutableCommand {
|
|||||||
String captcha = commandArguments.get(0);
|
String captcha = commandArguments.get(0);
|
||||||
|
|
||||||
// AuthMe plugin instance
|
// AuthMe plugin instance
|
||||||
final AuthMe plugin = AuthMe.getInstance();
|
final Wrapper wrapper = Wrapper.getInstance();
|
||||||
|
final AuthMe plugin = wrapper.getAuthMe();
|
||||||
|
|
||||||
// Messages instance
|
// Messages instance
|
||||||
final Messages m = plugin.getMessages();
|
final Messages m = wrapper.getMessages();
|
||||||
|
|
||||||
// Command logic
|
// Command logic
|
||||||
if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
|
if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
|
||||||
|
@ -49,7 +49,7 @@ public class UnregisterCommand extends ExecutableCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unregister the player
|
// Unregister the player
|
||||||
plugin.management.performUnregister(player, playerPass, false);
|
plugin.getManagement().performUnregister(player, playerPass, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -333,7 +333,7 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
event.setQuitMessage(null);
|
event.setQuitMessage(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.management.performQuit(player, false);
|
plugin.getManagement().performQuit(player, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
@ -349,7 +349,7 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
plugin.management.performQuit(player, true);
|
plugin.getManagement().performQuit(player, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
|
@ -238,7 +238,7 @@ public class AsynchronousJoin {
|
|||||||
PlayerCache.getInstance().removePlayer(name);
|
PlayerCache.getInstance().removePlayer(name);
|
||||||
if (auth != null && auth.getIp().equals(ip)) {
|
if (auth != null && auth.getIp().equals(ip)) {
|
||||||
m.send(player, MessageKey.SESSION_RECONNECTION);
|
m.send(player, MessageKey.SESSION_RECONNECTION);
|
||||||
plugin.management.performLogin(player, "dontneed", true);
|
plugin.getManagement().performLogin(player, "dontneed", true);
|
||||||
return;
|
return;
|
||||||
} else if (Settings.sessionExpireOnIpChange) {
|
} else if (Settings.sessionExpireOnIpChange) {
|
||||||
m.send(player, MessageKey.SESSION_EXPIRED);
|
m.send(player, MessageKey.SESSION_EXPIRED);
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
package fr.xephi.authme.command.executable.captcha;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.output.MessageKey;
|
||||||
|
import fr.xephi.authme.output.Messages;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.util.WrapperMock;
|
||||||
|
import org.bukkit.command.BlockCommandSender;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for {@link CaptchaCommand}.
|
||||||
|
*/
|
||||||
|
public class CaptchaCommandTest {
|
||||||
|
|
||||||
|
private WrapperMock wrapperMock;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUpWrapperMock() {
|
||||||
|
wrapperMock = WrapperMock.createInstance();
|
||||||
|
Settings.useCaptcha = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectNonPlayerSender() {
|
||||||
|
// given
|
||||||
|
CommandSender sender = Mockito.mock(BlockCommandSender.class);
|
||||||
|
ExecutableCommand command = new CaptchaCommand();
|
||||||
|
|
||||||
|
// when
|
||||||
|
boolean result = command.executeCommand(sender, new CommandParts(), new CommandParts());
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(result, equalTo(true));
|
||||||
|
assertThat(wrapperMock.wasMockCalled(AuthMe.class), equalTo(false));
|
||||||
|
assertThat(wrapperMock.wasMockCalled(Messages.class), equalTo(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void shouldRejectIfCaptchaIsNotUsed() {
|
||||||
|
// given
|
||||||
|
Player player = mockPlayerWithName("testplayer");
|
||||||
|
ExecutableCommand command = new CaptchaCommand();
|
||||||
|
|
||||||
|
// when
|
||||||
|
boolean result = command.executeCommand(player, new CommandParts(), new CommandParts());
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(result, equalTo(true));
|
||||||
|
verify(wrapperMock.getMessages()).send(player, MessageKey.USAGE_LOGIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Player mockPlayerWithName(String name) {
|
||||||
|
Player player = Mockito.mock(Player.class);
|
||||||
|
when(player.getName()).thenReturn(name);
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user