Merge branch '604-default-permissions-on-nodes' of https://github.com/AuthMe-Team/AuthMeReloaded

This commit is contained in:
ljacqu
2016-05-31 09:15:36 +02:00
13 changed files with 157 additions and 190 deletions
@@ -256,21 +256,16 @@ public class CommandInitializerTest {
BiConsumer adminPermissionChecker = new BiConsumer() {
@Override
public void accept(CommandDescription command, int depth) {
CommandPermissions permissions = command.getCommandPermissions();
if (permissions != null && OP_ONLY.equals(permissions.getDefaultPermission())
&& !hasAdminNode(permissions)) {
PermissionNode permission = command.getPermission();
if (permission != null && OP_ONLY.equals(permission.getDefaultPermission())
&& !hasAdminNode(permission)) {
fail("The command with labels " + command.getLabels() + " has OP_ONLY default "
+ "permission but no permission node on admin level");
}
}
private boolean hasAdminNode(CommandPermissions permissions) {
for (PermissionNode node : permissions.getPermissionNodes()) {
if (node instanceof AdminPermission) {
return true;
}
}
return false;
private boolean hasAdminNode(PermissionNode permission) {
return permission instanceof AdminPermission;
}
};
@@ -1,7 +1,7 @@
package fr.xephi.authme.command;
import fr.xephi.authme.command.executable.HelpCommand;
import fr.xephi.authme.permission.DefaultPermission;
import fr.xephi.authme.permission.AdminPermission;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PlayerPermission;
@@ -43,8 +43,8 @@ public final class TestCommandsUtil {
.description("test").detailedDescription("Test.").withArgument("Query", "", false).build();
// Register /unregister <player>, alias: /unreg
CommandDescription unregisterBase = createCommand(null, null, asList("unregister", "unreg"),
newArgument("player", false));
CommandDescription unregisterBase = createCommand(AdminPermission.UNREGISTER, null,
asList("unregister", "unreg"), newArgument("player", false));
return newHashSet(authMeBase, emailBase, unregisterBase);
}
@@ -84,18 +84,10 @@ public final class TestCommandsUtil {
/** Shortcut command to initialize a new test command. */
private static CommandDescription createCommand(PermissionNode permission, CommandDescription parent,
List<String> labels, CommandArgumentDescription... arguments) {
PermissionNode[] notNullPermission;
if (permission == null) {
notNullPermission = new PermissionNode[0];
} else {
notNullPermission = new PermissionNode[1];
notNullPermission[0] = permission;
}
CommandDescription.CommandBuilder command = CommandDescription.builder()
.labels(labels)
.parent(parent)
.permissions(DefaultPermission.OP_ONLY, notNullPermission)
.permission(permission)
.description(labels.get(0) + " cmd")
.detailedDescription("'" + labels.get(0) + "' test command")
.executableCommand(mock(ExecutableCommand.class));
@@ -4,8 +4,8 @@ import fr.xephi.authme.command.CommandDescription;
import fr.xephi.authme.command.FoundCommandResult;
import fr.xephi.authme.command.FoundResultStatus;
import fr.xephi.authme.command.TestCommandsUtil;
import fr.xephi.authme.permission.AdminPermission;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.properties.PluginSettings;
import org.bukkit.ChatColor;
@@ -126,10 +126,10 @@ public class HelpProviderTest {
@Test
public void shouldShowAndEvaluatePermissions() {
// given
CommandDescription command = getCommandWithLabel(commands, "authme", "login");
FoundCommandResult result = newFoundResult(command, Collections.singletonList("authme"));
CommandDescription command = getCommandWithLabel(commands, "unregister");
FoundCommandResult result = newFoundResult(command, Collections.singletonList("unreg"));
given(sender.isOp()).willReturn(true);
given(permissionsManager.hasPermission(sender, PlayerPermission.LOGIN)).willReturn(true);
given(permissionsManager.hasPermission(sender, AdminPermission.UNREGISTER)).willReturn(true);
given(permissionsManager.hasPermission(sender, command)).willReturn(true);
// when
@@ -139,7 +139,7 @@ public class HelpProviderTest {
assertThat(lines, hasSize(5));
assertThat(removeColors(lines.get(1)), containsString("Permissions:"));
assertThat(removeColors(lines.get(2)),
containsString(PlayerPermission.LOGIN.getNode() + " (You have permission)"));
containsString(AdminPermission.UNREGISTER.getNode() + " (You have permission)"));
assertThat(removeColors(lines.get(3)), containsString("Default: OP's only (You have permission)"));
assertThat(removeColors(lines.get(4)), containsString("Result: You have permission"));
}
@@ -147,10 +147,10 @@ public class HelpProviderTest {
@Test
public void shouldShowAndEvaluateForbiddenPermissions() {
// given
CommandDescription command = getCommandWithLabel(commands, "authme", "login");
FoundCommandResult result = newFoundResult(command, Collections.singletonList("authme"));
CommandDescription command = getCommandWithLabel(commands, "unregister");
FoundCommandResult result = newFoundResult(command, Collections.singletonList("unregister"));
given(sender.isOp()).willReturn(false);
given(permissionsManager.hasPermission(sender, PlayerPermission.LOGIN)).willReturn(false);
given(permissionsManager.hasPermission(sender, AdminPermission.UNREGISTER)).willReturn(false);
given(permissionsManager.hasPermission(sender, command)).willReturn(false);
// when
@@ -160,7 +160,7 @@ public class HelpProviderTest {
assertThat(lines, hasSize(5));
assertThat(removeColors(lines.get(1)), containsString("Permissions:"));
assertThat(removeColors(lines.get(2)),
containsString(PlayerPermission.LOGIN.getNode() + " (No permission)"));
containsString(AdminPermission.UNREGISTER.getNode() + " (No permission)"));
assertThat(removeColors(lines.get(3)), containsString("Default: OP's only (No permission)"));
assertThat(removeColors(lines.get(4)), containsString("Result: No permission"));
}
@@ -182,7 +182,7 @@ public class HelpProviderTest {
public void shouldNotShowAnythingForNullPermissionsOnCommand() {
// given
CommandDescription command = mock(CommandDescription.class);
given(command.getCommandPermissions()).willReturn(null);
given(command.getPermission()).willReturn(null);
given(command.getLabels()).willReturn(Collections.singletonList("test"));
FoundCommandResult result = newFoundResult(command, Collections.singletonList("test"));