mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-09-07 12:48:03 +02:00
#739 Fix command unit tests; adjust default handling
(cherry picked from commit 61c119b)
This commit is contained in:
parent
73272b5931
commit
6d2597a980
@ -1,7 +1,6 @@
|
||||
package fr.xephi.authme.permission;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.command.CommandDescription;
|
||||
import fr.xephi.authme.permission.handlers.BPermissionsHandler;
|
||||
import fr.xephi.authme.permission.handlers.GroupManagerHandler;
|
||||
import fr.xephi.authme.permission.handlers.PermissionHandler;
|
||||
@ -15,8 +14,6 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
@ -186,8 +183,6 @@ public class PermissionsManager {
|
||||
|
||||
/**
|
||||
* Reload the permissions manager, and re-hook all permission plugins.
|
||||
*
|
||||
* @return True on success, false on failure.
|
||||
*/
|
||||
public void reload() {
|
||||
// Unhook all permission plugins
|
||||
@ -246,7 +241,7 @@ public class PermissionsManager {
|
||||
|
||||
// Return if the player is an Op if sender is console or no permission system in use
|
||||
if (!(sender instanceof Player) || !isEnabled()) {
|
||||
return sender.isOp();
|
||||
return permissionNode.getDefaultPermission().evaluate(sender);
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
@ -1,10 +1,10 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
@ -27,13 +27,11 @@ import static org.mockito.Mockito.mock;
|
||||
/**
|
||||
* Test for {@link CommandMapper}.
|
||||
*/
|
||||
@Ignore
|
||||
// TODO Gnat008 20160602: Adjust matcher for null permission
|
||||
public class CommandMapperTest {
|
||||
|
||||
private static Set<CommandDescription> commands;
|
||||
private static CommandMapper mapper;
|
||||
private static PermissionsManager permissionsManager;
|
||||
private CommandMapper mapper;
|
||||
private PermissionsManager permissionsManager;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpCommandHandler() {
|
||||
@ -56,7 +54,7 @@ public class CommandMapperTest {
|
||||
// given
|
||||
List<String> parts = asList("authme", "login", "test1");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(CommandDescription.class).getPermission())).willReturn(true);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
@ -75,7 +73,7 @@ public class CommandMapperTest {
|
||||
// given
|
||||
List<String> parts = asList("Authme", "REG", "arg1", "arg2");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(CommandDescription.class).getPermission())).willReturn(true);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
@ -93,7 +91,7 @@ public class CommandMapperTest {
|
||||
// given
|
||||
List<String> parts = asList("authme", "register", "pass123", "pass123", "pass123");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(CommandDescription.class).getPermission())).willReturn(true);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
@ -111,7 +109,7 @@ public class CommandMapperTest {
|
||||
// given
|
||||
List<String> parts = asList("authme", "Reg");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(CommandDescription.class).getPermission())).willReturn(true);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
@ -129,7 +127,7 @@ public class CommandMapperTest {
|
||||
// given
|
||||
List<String> parts = asList("authme", "reh", "pass123", "pass123");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(CommandDescription.class).getPermission())).willReturn(true);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
@ -148,7 +146,7 @@ public class CommandMapperTest {
|
||||
// given
|
||||
List<String> parts = asList("authme", "asdfawetawty4asdca");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(CommandDescription.class).getPermission())).willReturn(true);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
@ -166,7 +164,7 @@ public class CommandMapperTest {
|
||||
// given
|
||||
List<String> parts = singletonList("unregister");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(CommandDescription.class).getPermission())).willReturn(true);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
@ -184,7 +182,7 @@ public class CommandMapperTest {
|
||||
// given
|
||||
List<String> parts = asList("bogus", "label1", "arg1");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(CommandDescription.class).getPermission())).willReturn(true);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
@ -209,7 +207,7 @@ public class CommandMapperTest {
|
||||
// given
|
||||
List<String> parts = asList("Unreg", "player1");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(CommandDescription.class).getPermission())).willReturn(true);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
@ -227,7 +225,7 @@ public class CommandMapperTest {
|
||||
// given
|
||||
List<String> parts = asList("unregistER", "player1", "wrongArg");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(CommandDescription.class).getPermission())).willReturn(true);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
@ -245,7 +243,7 @@ public class CommandMapperTest {
|
||||
// given
|
||||
List<String> parts = asList("email", "helptest", "arg1");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(CommandDescription.class).getPermission())).willReturn(true);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
@ -263,7 +261,7 @@ public class CommandMapperTest {
|
||||
// given
|
||||
List<String> parts = asList("authme", "login", "test1");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(CommandDescription.class).getPermission())).willReturn(false);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(false);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
|
@ -255,7 +255,7 @@ public class HelpProviderTest {
|
||||
public void shouldHandleUnboundFoundCommandResult() {
|
||||
// given
|
||||
FoundCommandResult result = new FoundCommandResult(null, Arrays.asList("authme", "test"),
|
||||
Collections.<String> emptyList(), 0.0, FoundResultStatus.UNKNOWN_LABEL);
|
||||
Collections.<String>emptyList(), 0.0, FoundResultStatus.UNKNOWN_LABEL);
|
||||
|
||||
// when
|
||||
List<String> lines = helpProvider.printHelp(sender, result, ALL_OPTIONS);
|
||||
@ -319,7 +319,7 @@ public class HelpProviderTest {
|
||||
* @return The generated FoundCommandResult object
|
||||
*/
|
||||
private static FoundCommandResult newFoundResult(CommandDescription command, List<String> labels) {
|
||||
return new FoundCommandResult(command, labels, Collections.<String> emptyList(), 0.0, FoundResultStatus.SUCCESS);
|
||||
return new FoundCommandResult(command, labels, Collections.<String>emptyList(), 0.0, FoundResultStatus.SUCCESS);
|
||||
}
|
||||
|
||||
private static String removeColors(String str) {
|
||||
|
@ -4,7 +4,6 @@ import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@ -19,7 +18,6 @@ import static org.mockito.Mockito.mock;
|
||||
/**
|
||||
* Test for {@link PermissionsManager}.
|
||||
*/
|
||||
// TODO #739: Unignore tests after they pass
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PermissionsManagerTest {
|
||||
|
||||
@ -42,7 +40,7 @@ public class PermissionsManagerTest {
|
||||
boolean result = permissionsManager.hasPermission(sender, node);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(false));
|
||||
assertThat(result, equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -60,8 +58,6 @@ public class PermissionsManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
// TODO ljacqu 20160601: This test should pass - tested permission node has DefaultPermission.NOT_ALLOWED
|
||||
public void shouldDenyPermissionEvenForOpCommandSender() {
|
||||
// given
|
||||
PermissionNode node = TestPermissions.WORLD_DOMINATION;
|
||||
@ -76,8 +72,6 @@ public class PermissionsManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
// TODO ljacqu 20160601: This test MUST pass! -> tested node has DefaultPermission.ALLOW
|
||||
public void shouldAllowForNonOpPlayer() {
|
||||
// given
|
||||
PermissionNode node = TestPermissions.LOGIN;
|
||||
@ -118,8 +112,6 @@ public class PermissionsManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
// TODO ljacqu 20160601: This should pass -> tested node has DefaultPermission.NOT_ALLOWED so result should be false
|
||||
public void shouldDenyEvenForOpPlayer() {
|
||||
// given
|
||||
PermissionNode node = TestPermissions.WORLD_DOMINATION;
|
||||
@ -134,8 +126,6 @@ public class PermissionsManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
// TODO ljacqu 20160601: This must pass. null permission => true
|
||||
public void shouldHandleNullPermissionForCommandSender() {
|
||||
// given
|
||||
PermissionNode node = null;
|
||||
@ -149,8 +139,6 @@ public class PermissionsManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
// TODO ljacqu 20160601: This must pass. null permission => true
|
||||
public void shouldHandleNullPermissionForPlayer() {
|
||||
// given
|
||||
PermissionNode node = null;
|
||||
|
Loading…
Reference in New Issue
Block a user