mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-06 16:37:38 +01:00
Null verifier wildcard fix (#1849)
* fix hasPermission(String, PermissionVerifier) Behavior * add test cases
This commit is contained in:
parent
1d6ff874f8
commit
2c3e38b178
@ -112,15 +112,17 @@ public interface PermissionHandler {
|
||||
* @return true if the handler has the permission, false otherwise
|
||||
*/
|
||||
default boolean hasPermission(@NotNull String permissionName, @Nullable PermissionVerifier permissionVerifier) {
|
||||
final Permission permission = getPermission(permissionName);
|
||||
Permission permission = getPermission(permissionName);
|
||||
|
||||
if (permission != null) {
|
||||
// If no permission verifier, hand off to no-verifier hasPermission for wildcard support
|
||||
if(permissionVerifier == null) { return hasPermission(permission); }
|
||||
// Verify using the permission verifier
|
||||
return permissionVerifier == null || permissionVerifier.isValid(permission.getNBTData());
|
||||
if (permission == null && permissionVerifier == null) {
|
||||
permission = new Permission(permissionName, null);
|
||||
} else if (permission == null) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
// If no permission verifier, hand off to no-verifier hasPermission for wildcard support
|
||||
if(permissionVerifier == null) { return hasPermission(permission); }
|
||||
// Verify using the permission verifier
|
||||
return permissionVerifier.isValid(permission.getNBTData());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -85,6 +85,8 @@ public class TestPermissions {
|
||||
Permission permission = new Permission("foo.b*r.baz");
|
||||
Permission match = new Permission("foo.baaar.baz");
|
||||
Permission match2 = new Permission("foo.br.baz");
|
||||
String match3 = "foo.br.baz";
|
||||
String match4 = "foo.baaar.baz";
|
||||
Permission nomatch = new Permission("foo.br.bz");
|
||||
Permission nomatch2 = new Permission("foo.b.baz");
|
||||
assertFalse(player.hasPermission(match));
|
||||
@ -96,6 +98,8 @@ public class TestPermissions {
|
||||
|
||||
assertTrue(player.hasPermission(match));
|
||||
assertTrue(player.hasPermission(match2));
|
||||
assertTrue(player.hasPermission(match3));
|
||||
assertTrue(player.hasPermission(match4));
|
||||
assertFalse(player.hasPermission(nomatch));
|
||||
assertFalse(player.hasPermission(nomatch2));
|
||||
}
|
||||
@ -105,6 +109,8 @@ public class TestPermissions {
|
||||
Permission permission = new Permission("foo.b*");
|
||||
Permission match = new Permission("foo.baaar.baz");
|
||||
Permission match2 = new Permission("foo.b");
|
||||
String match3 = "foo.b";
|
||||
String match4 = "foo.baaar.baz";
|
||||
Permission nomatch = new Permission("foo.");
|
||||
Permission nomatch2 = new Permission("foo/b");
|
||||
assertFalse(player.hasPermission(match));
|
||||
@ -116,6 +122,8 @@ public class TestPermissions {
|
||||
|
||||
assertTrue(player.hasPermission(match));
|
||||
assertTrue(player.hasPermission(match2));
|
||||
assertTrue(player.hasPermission(match3));
|
||||
assertTrue(player.hasPermission(match4));
|
||||
assertFalse(player.hasPermission(nomatch));
|
||||
assertFalse(player.hasPermission(nomatch2));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user