mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-24 01:27:35 +01:00
Start tests for email commands
- Removed randomStringGenerator from Management as it is unused
This commit is contained in:
parent
2922d04aa0
commit
efb57989ed
@ -14,19 +14,19 @@ public class AddEmailCommand extends ExecutableCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// Get the parameter values
|
|
||||||
String playerMail = commandArguments.get(0);
|
|
||||||
String playerMailVerify = commandArguments.get(1);
|
|
||||||
|
|
||||||
// Make sure the current command executor is a player
|
// Make sure the current command executor is a player
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the parameter values
|
||||||
|
String playerMail = commandArguments.get(0);
|
||||||
|
String playerMailVerify = commandArguments.get(1);
|
||||||
|
|
||||||
// Get the player and perform email addition
|
// Get the player and perform email addition
|
||||||
final AuthMe plugin = AuthMe.getInstance();
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
plugin.management.performAddEmail(player, playerMail, playerMailVerify);
|
plugin.getManagement().performAddEmail(player, playerMail, playerMailVerify);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,19 +13,19 @@ public class ChangeEmailCommand extends ExecutableCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// Get the parameter values
|
|
||||||
String playerMailOld = commandArguments.get(0);
|
|
||||||
String playerMailNew = commandArguments.get(1);
|
|
||||||
|
|
||||||
// Make sure the current command executor is a player
|
// Make sure the current command executor is a player
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the parameter values
|
||||||
|
String playerMailOld = commandArguments.get(0);
|
||||||
|
String playerMailNew = commandArguments.get(1);
|
||||||
|
|
||||||
// Get the player instance and execute action
|
// Get the player instance and execute action
|
||||||
final AuthMe plugin = AuthMe.getInstance();
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
plugin.management.performChangeEmail(player, playerMailOld, playerMailNew);
|
plugin.getManagement().performChangeEmail(player, playerMailOld, playerMailNew);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,14 +22,14 @@ public class RecoverEmailCommand extends ExecutableCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// Get the parameter values
|
|
||||||
String playerMail = commandArguments.get(0);
|
|
||||||
|
|
||||||
// Make sure the current command executor is a player
|
// Make sure the current command executor is a player
|
||||||
if(!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the parameter values
|
||||||
|
String playerMail = commandArguments.get(0);
|
||||||
|
|
||||||
// Get the player instance and name
|
// Get the player instance and name
|
||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
final String playerName = player.getName();
|
final String playerName = player.getName();
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package fr.xephi.authme.process;
|
package fr.xephi.authme.process;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.process.email.AsyncChangeEmail;
|
import fr.xephi.authme.process.email.AsyncChangeEmail;
|
||||||
import fr.xephi.authme.process.join.AsyncronousJoin;
|
import fr.xephi.authme.process.join.AsyncronousJoin;
|
||||||
@ -11,35 +8,21 @@ import fr.xephi.authme.process.logout.AsyncronousLogout;
|
|||||||
import fr.xephi.authme.process.quit.AsyncronousQuit;
|
import fr.xephi.authme.process.quit.AsyncronousQuit;
|
||||||
import fr.xephi.authme.process.register.AsyncRegister;
|
import fr.xephi.authme.process.register.AsyncRegister;
|
||||||
import fr.xephi.authme.process.unregister.AsyncronousUnregister;
|
import fr.xephi.authme.process.unregister.AsyncronousUnregister;
|
||||||
import fr.xephi.authme.security.RandomString;
|
import org.bukkit.entity.Player;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
* @author Gabriele
|
|
||||||
* @version $Revision: 1.0 $
|
|
||||||
*/
|
*/
|
||||||
public class Management {
|
public class Management {
|
||||||
|
|
||||||
private final AuthMe plugin;
|
private final AuthMe plugin;
|
||||||
private final BukkitScheduler sched;
|
private final BukkitScheduler sched;
|
||||||
public static RandomString rdm = new RandomString(Settings.captchaLength);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for Management.
|
|
||||||
* @param plugin AuthMe
|
|
||||||
*/
|
|
||||||
public Management(AuthMe plugin) {
|
public Management(AuthMe plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.sched = this.plugin.getServer().getScheduler();
|
this.sched = this.plugin.getServer().getScheduler();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method performLogin.
|
|
||||||
* @param player Player
|
|
||||||
* @param password String
|
|
||||||
* @param forceLogin boolean
|
|
||||||
*/
|
|
||||||
public void performLogin(final Player player, final String password, final boolean forceLogin) {
|
public void performLogin(final Player player, final String password, final boolean forceLogin) {
|
||||||
sched.runTaskAsynchronously(plugin, new Runnable() {
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
@ -50,10 +33,6 @@ public class Management {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method performLogout.
|
|
||||||
* @param player Player
|
|
||||||
*/
|
|
||||||
public void performLogout(final Player player) {
|
public void performLogout(final Player player) {
|
||||||
sched.runTaskAsynchronously(plugin, new Runnable() {
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
@ -64,12 +43,6 @@ public class Management {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method performRegister.
|
|
||||||
* @param player Player
|
|
||||||
* @param password String
|
|
||||||
* @param email String
|
|
||||||
*/
|
|
||||||
public void performRegister(final Player player, final String password, final String email) {
|
public void performRegister(final Player player, final String password, final String email) {
|
||||||
sched.runTaskAsynchronously(plugin, new Runnable() {
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
@ -80,12 +53,6 @@ public class Management {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method performUnregister.
|
|
||||||
* @param player Player
|
|
||||||
* @param password String
|
|
||||||
* @param force boolean
|
|
||||||
*/
|
|
||||||
public void performUnregister(final Player player, final String password, final boolean force) {
|
public void performUnregister(final Player player, final String password, final boolean force) {
|
||||||
sched.runTaskAsynchronously(plugin, new Runnable() {
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
@ -96,10 +63,6 @@ public class Management {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method performJoin.
|
|
||||||
* @param player Player
|
|
||||||
*/
|
|
||||||
public void performJoin(final Player player) {
|
public void performJoin(final Player player) {
|
||||||
sched.runTaskAsynchronously(plugin, new Runnable() {
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
@ -111,11 +74,6 @@ public class Management {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method performQuit.
|
|
||||||
* @param player Player
|
|
||||||
* @param isKick boolean
|
|
||||||
*/
|
|
||||||
public void performQuit(final Player player, final boolean isKick) {
|
public void performQuit(final Player player, final boolean isKick) {
|
||||||
sched.runTaskAsynchronously(plugin, new Runnable() {
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
@ -127,12 +85,6 @@ public class Management {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method performAddEmail.
|
|
||||||
* @param player Player
|
|
||||||
* @param newEmail String
|
|
||||||
* @param newEmailVerify String
|
|
||||||
*/
|
|
||||||
public void performAddEmail(final Player player, final String newEmail, final String newEmailVerify) {
|
public void performAddEmail(final Player player, final String newEmail, final String newEmailVerify) {
|
||||||
sched.runTaskAsynchronously(plugin, new Runnable() {
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@ -142,12 +94,6 @@ public class Management {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method performChangeEmail.
|
|
||||||
* @param player Player
|
|
||||||
* @param oldEmail String
|
|
||||||
* @param newEmail String
|
|
||||||
*/
|
|
||||||
public void performChangeEmail(final Player player, final String oldEmail, final String newEmail) {
|
public void performChangeEmail(final Player player, final String oldEmail, final String newEmail) {
|
||||||
sched.runTaskAsynchronously(plugin, new Runnable() {
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,63 @@
|
|||||||
|
package fr.xephi.authme.command.executable.email;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.AuthMeMockUtil;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.process.Management;
|
||||||
|
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.mockito.Mockito;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for {@link AddEmailCommand}.
|
||||||
|
*/
|
||||||
|
public class AddEmailCommandTest {
|
||||||
|
|
||||||
|
private AuthMe authMeMock;
|
||||||
|
private Management managementMock;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUpMocks() {
|
||||||
|
AuthMeMockUtil.mockAuthMeInstance();
|
||||||
|
authMeMock = AuthMe.getInstance();
|
||||||
|
managementMock = Mockito.mock(Management.class);
|
||||||
|
when(authMeMock.getManagement()).thenReturn(managementMock);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectNonPlayerSender() {
|
||||||
|
// given
|
||||||
|
CommandSender sender = Mockito.mock(BlockCommandSender.class);
|
||||||
|
AddEmailCommand command = new AddEmailCommand();
|
||||||
|
|
||||||
|
// when
|
||||||
|
command.executeCommand(sender, new CommandParts(), new CommandParts());
|
||||||
|
|
||||||
|
// then
|
||||||
|
verify(authMeMock, never()).getManagement();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldForwardData() {
|
||||||
|
// given
|
||||||
|
Player sender = Mockito.mock(Player.class);
|
||||||
|
AddEmailCommand command = new AddEmailCommand();
|
||||||
|
|
||||||
|
// when
|
||||||
|
command.executeCommand(sender, new CommandParts(),
|
||||||
|
new CommandParts(Arrays.asList("mail@example", "other_example")));
|
||||||
|
|
||||||
|
// then
|
||||||
|
verify(authMeMock).getManagement();
|
||||||
|
verify(managementMock).performAddEmail(sender, "mail@example", "other_example");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package fr.xephi.authme.command.executable.email;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.AuthMeMockUtil;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.process.Management;
|
||||||
|
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.mockito.Mockito;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for {@link ChangeEmailCommand}.
|
||||||
|
*/
|
||||||
|
public class ChangeEmailCommandTest {
|
||||||
|
|
||||||
|
private AuthMe authMeMock;
|
||||||
|
private Management managementMock;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUpMocks() {
|
||||||
|
AuthMeMockUtil.mockAuthMeInstance();
|
||||||
|
authMeMock = AuthMe.getInstance();
|
||||||
|
managementMock = Mockito.mock(Management.class);
|
||||||
|
when(authMeMock.getManagement()).thenReturn(managementMock);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectNonPlayerSender() {
|
||||||
|
// given
|
||||||
|
CommandSender sender = Mockito.mock(BlockCommandSender.class);
|
||||||
|
ChangeEmailCommand command = new ChangeEmailCommand();
|
||||||
|
|
||||||
|
// when
|
||||||
|
command.executeCommand(sender, new CommandParts(), new CommandParts());
|
||||||
|
|
||||||
|
// then
|
||||||
|
verify(authMeMock, never()).getManagement();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldForwardData() {
|
||||||
|
// given
|
||||||
|
Player sender = Mockito.mock(Player.class);
|
||||||
|
ChangeEmailCommand command = new ChangeEmailCommand();
|
||||||
|
|
||||||
|
// when
|
||||||
|
command.executeCommand(sender, new CommandParts(),
|
||||||
|
new CommandParts(Arrays.asList("new.mail@example.org", "old_mail@example.org")));
|
||||||
|
|
||||||
|
// then
|
||||||
|
verify(authMeMock).getManagement();
|
||||||
|
verify(managementMock).performChangeEmail(sender, "new.mail@example.org", "old_mail@example.org");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package fr.xephi.authme.command.executable.email;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.AuthMeMockUtil;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import org.bukkit.command.BlockCommandSender;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for {@link RecoverEmailCommand}.
|
||||||
|
*/
|
||||||
|
public class RecoverEmailCommandTest {
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUpMocks() {
|
||||||
|
AuthMeMockUtil.mockAuthMeInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRejectNonPlayerSender() {
|
||||||
|
// given
|
||||||
|
CommandSender sender = Mockito.mock(BlockCommandSender.class);
|
||||||
|
RecoverEmailCommand command = new RecoverEmailCommand();
|
||||||
|
|
||||||
|
// when
|
||||||
|
command.executeCommand(sender, new CommandParts(), new CommandParts());
|
||||||
|
|
||||||
|
// then
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO ljacqu 20151121: Expand tests. This command doesn't use a scheduler and has all of its
|
||||||
|
// logic inside here.
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user