diff --git a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java index 8a392207d..d8bc53377 100644 --- a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java +++ b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java @@ -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; diff --git a/src/test/java/fr/xephi/authme/command/CommandMapperTest.java b/src/test/java/fr/xephi/authme/command/CommandMapperTest.java index ecf43f726..96eab841f 100644 --- a/src/test/java/fr/xephi/authme/command/CommandMapperTest.java +++ b/src/test/java/fr/xephi/authme/command/CommandMapperTest.java @@ -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 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 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 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 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 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 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 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 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 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 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 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 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 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); diff --git a/src/test/java/fr/xephi/authme/command/help/HelpProviderTest.java b/src/test/java/fr/xephi/authme/command/help/HelpProviderTest.java index b6f3c88ae..f40350e7a 100644 --- a/src/test/java/fr/xephi/authme/command/help/HelpProviderTest.java +++ b/src/test/java/fr/xephi/authme/command/help/HelpProviderTest.java @@ -255,7 +255,7 @@ public class HelpProviderTest { public void shouldHandleUnboundFoundCommandResult() { // given FoundCommandResult result = new FoundCommandResult(null, Arrays.asList("authme", "test"), - Collections. emptyList(), 0.0, FoundResultStatus.UNKNOWN_LABEL); + Collections.emptyList(), 0.0, FoundResultStatus.UNKNOWN_LABEL); // when List 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 labels) { - return new FoundCommandResult(command, labels, Collections. emptyList(), 0.0, FoundResultStatus.SUCCESS); + return new FoundCommandResult(command, labels, Collections.emptyList(), 0.0, FoundResultStatus.SUCCESS); } private static String removeColors(String str) { diff --git a/src/test/java/fr/xephi/authme/permission/PermissionsManagerTest.java b/src/test/java/fr/xephi/authme/permission/PermissionsManagerTest.java index 225fc899e..8ede82b63 100644 --- a/src/test/java/fr/xephi/authme/permission/PermissionsManagerTest.java +++ b/src/test/java/fr/xephi/authme/permission/PermissionsManagerTest.java @@ -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;