Fix #316 Ordinary player can use /authme unregister
- Change wrong player permissions to admin permissions - Rename command class names that were the same for the ordinary vs. admin task - Create test to ensure that commands with OP_ONLY default require an admin permission node
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.permission.AdminPermission;
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import fr.xephi.authme.util.WrapperMock;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -8,6 +10,7 @@ import org.junit.Test;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static fr.xephi.authme.command.CommandPermissions.DefaultPermission.OP_ONLY;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
@@ -223,6 +226,42 @@ public class CommandInitializerTest {
|
||||
walkThroughCommands(commands, noArgumentForParentChecker);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that commands defined with the OP_ONLY default permission have at least one admin permission node.
|
||||
*/
|
||||
@Test
|
||||
public void shouldNotHavePlayerPermissionIfDefaultsToOpOnly() {
|
||||
// given
|
||||
BiConsumer adminPermissionChecker = new BiConsumer() {
|
||||
// The only exception to this check is the force login command, which should default to OP_ONLY
|
||||
// but semantically it is a player permission
|
||||
final List<String> forceLoginLabels = Arrays.asList("forcelogin", "login");
|
||||
|
||||
@Override
|
||||
public void accept(CommandDescription command, int depth) {
|
||||
CommandPermissions permissions = command.getCommandPermissions();
|
||||
if (permissions != null && OP_ONLY.equals(permissions.getDefaultPermission())) {
|
||||
if (!hasAdminNode(permissions) && !command.getLabels().equals(forceLoginLabels)) {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
// when/then
|
||||
walkThroughCommands(commands, adminPermissionChecker);
|
||||
}
|
||||
|
||||
|
||||
// ------------
|
||||
// Helper methods
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ import static org.mockito.Mockito.verify;
|
||||
/**
|
||||
* Test for {@link RegisterCommand}.
|
||||
*/
|
||||
public class RegisterCommandTest {
|
||||
public class RegisterAdminCommandTest {
|
||||
|
||||
private static Management managementMock;
|
||||
private static Messages messagesMock;
|
||||
@@ -3,7 +3,7 @@ package fr.xephi.authme.command.help;
|
||||
import fr.xephi.authme.command.CommandDescription;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.command.executable.authme.RegisterCommand;
|
||||
import fr.xephi.authme.command.executable.authme.RegisterAdminCommand;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
@@ -122,7 +122,7 @@ public class HelpSyntaxHelperTest {
|
||||
.build();
|
||||
|
||||
return CommandDescription.builder()
|
||||
.executableCommand(Mockito.mock(RegisterCommand.class))
|
||||
.executableCommand(Mockito.mock(RegisterAdminCommand.class))
|
||||
.labels("register", "r")
|
||||
.description("Register a player")
|
||||
.detailedDescription("Register the specified player with the specified password.")
|
||||
|
||||
Reference in New Issue
Block a user