#761 Restore permission group in sync with limbo players

- Couple AuthGroupHandler closer to the LimboService: whenever a limbo player is restored, the auth group should be restored as well. This fixes some consistency issues.
- Move AuthGroupHandler into limbo package and make it package-private
- Change permission handler to skip any empty groups (prevents odd command output e.g. for BukkitPermissions)
This commit is contained in:
ljacqu
2017-04-29 22:37:34 +02:00
parent d4c1370da6
commit e0e4cd112d
15 changed files with 47 additions and 104 deletions
@@ -61,6 +61,9 @@ public class LimboServiceTest {
@Mock
private LimboPersistence limboPersistence;
@Mock
private AuthGroupHandler authGroupHandler;
@BeforeClass
public static void initLogger() {
TestHelper.setupLogger();
@@ -92,6 +95,7 @@ public class LimboServiceTest {
assertThat(limboService.hasLimboPlayer("Bobby"), equalTo(true));
LimboPlayer limbo = limboService.getLimboPlayer("Bobby");
verify(authGroupHandler).setGroup(player, limbo, AuthGroupType.REGISTERED_UNAUTHENTICATED);
assertThat(limbo, not(nullValue()));
assertThat(limbo.isOperator(), equalTo(true));
assertThat(limbo.getWalkSpeed(), equalTo(0.3f));
@@ -121,6 +125,7 @@ public class LimboServiceTest {
verify(player).setWalkSpeed(0.0f);
LimboPlayer limbo = limboService.getLimboPlayer("charles");
verify(authGroupHandler).setGroup(player, limbo, AuthGroupType.UNREGISTERED);
assertThat(limbo, not(nullValue()));
assertThat(limbo.isOperator(), equalTo(false));
assertThat(limbo.getWalkSpeed(), equalTo(0.1f));
@@ -143,6 +148,7 @@ public class LimboServiceTest {
// then
verify(existingLimbo).clearTasks();
LimboPlayer newLimbo = limboService.getLimboPlayer("Carlos");
verify(authGroupHandler).setGroup(player, newLimbo, AuthGroupType.UNREGISTERED);
assertThat(newLimbo, not(nullValue()));
assertThat(newLimbo, not(sameInstance(existingLimbo)));
}
@@ -168,6 +174,7 @@ public class LimboServiceTest {
verify(player).setAllowFlight(true);
verify(player).setFlySpeed(LimboPlayer.DEFAULT_FLY_SPEED);
verify(limbo).clearTasks();
verify(authGroupHandler).setGroup(player, limbo, AuthGroupType.LOGGED_IN);
assertThat(limboService.hasLimboPlayer("John"), equalTo(false));
}
@@ -181,6 +188,7 @@ public class LimboServiceTest {
// then
verify(player, only()).getName();
verify(authGroupHandler).setGroup(player, null, AuthGroupType.LOGGED_IN);
}
@Test
@@ -197,6 +205,7 @@ public class LimboServiceTest {
// then
verify(taskManager).registerTimeoutTask(player, limbo);
verify(taskManager).registerMessageTask(player, limbo, true);
verify(authGroupHandler).setGroup(player, limbo, AuthGroupType.REGISTERED_UNAUTHENTICATED);
}
@Test
@@ -209,6 +218,7 @@ public class LimboServiceTest {
// then
verifyZeroInteractions(taskManager);
verify(authGroupHandler).setGroup(player, null, AuthGroupType.REGISTERED_UNAUTHENTICATED);
}
private static Player newPlayer(String name) {
@@ -7,8 +7,6 @@ import fr.xephi.authme.data.limbo.LimboService;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.AbstractUnregisterEvent;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.permission.AuthGroupHandler;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.service.BukkitService;
@@ -62,8 +60,6 @@ public class AsynchronousUnregisterTest {
@Mock
private TeleportationService teleportationService;
@Mock
private AuthGroupHandler authGroupHandler;
@Mock
private CommandManager commandManager;
@BeforeClass
@@ -90,7 +86,7 @@ public class AsynchronousUnregisterTest {
// then
verify(service).send(player, MessageKey.WRONG_PASSWORD);
verify(passwordSecurity).comparePassword(userPassword, password, name);
verifyZeroInteractions(dataSource, limboService, authGroupHandler, teleportationService, bukkitService);
verifyZeroInteractions(dataSource, limboService, teleportationService, bukkitService);
verify(player, only()).getName();
}
@@ -119,7 +115,6 @@ public class AsynchronousUnregisterTest {
verify(dataSource).removeAuth(name);
verify(playerCache).removePlayer(name);
verify(teleportationService).teleportOnJoin(player);
verify(authGroupHandler).setGroup(player, AuthGroupType.UNREGISTERED);
verify(bukkitService).scheduleSyncTaskFromOptionallyAsyncTask(any(Runnable.class));
verifyCalledUnregisterEventFor(player);
verify(commandManager).runCommandsOnUnregister(player);
@@ -150,7 +145,6 @@ public class AsynchronousUnregisterTest {
verify(dataSource).removeAuth(name);
verify(playerCache).removePlayer(name);
verify(teleportationService).teleportOnJoin(player);
verify(authGroupHandler).setGroup(player, AuthGroupType.UNREGISTERED);
verify(bukkitService).scheduleSyncTaskFromOptionallyAsyncTask(any(Runnable.class));
verifyCalledUnregisterEventFor(player);
verify(commandManager).runCommandsOnUnregister(player);
@@ -179,7 +173,6 @@ public class AsynchronousUnregisterTest {
verify(passwordSecurity).comparePassword(userPassword, password, name);
verify(dataSource).removeAuth(name);
verify(playerCache).removePlayer(name);
verify(authGroupHandler).setGroup(player, AuthGroupType.UNREGISTERED);
verifyZeroInteractions(teleportationService, limboService);
verify(bukkitService, never()).runTask(any(Runnable.class));
verifyCalledUnregisterEventFor(player);
@@ -207,7 +200,7 @@ public class AsynchronousUnregisterTest {
verify(passwordSecurity).comparePassword(userPassword, password, name);
verify(dataSource).removeAuth(name);
verify(service).send(player, MessageKey.ERROR);
verifyZeroInteractions(teleportationService, authGroupHandler, bukkitService);
verifyZeroInteractions(teleportationService, bukkitService);
}
@Test
@@ -232,7 +225,7 @@ public class AsynchronousUnregisterTest {
verify(passwordSecurity).comparePassword(userPassword, password, name);
verify(dataSource).removeAuth(name);
verify(playerCache).removePlayer(name);
verifyZeroInteractions(teleportationService, authGroupHandler);
verifyZeroInteractions(teleportationService);
verifyCalledUnregisterEventFor(player);
}
@@ -256,7 +249,6 @@ public class AsynchronousUnregisterTest {
verify(dataSource).removeAuth(name);
verify(playerCache).removePlayer(name);
verify(teleportationService).teleportOnJoin(player);
verify(authGroupHandler).setGroup(player, AuthGroupType.UNREGISTERED);
verify(bukkitService).scheduleSyncTaskFromOptionallyAsyncTask(any(Runnable.class));
verifyCalledUnregisterEventFor(player);
verify(commandManager).runCommandsOnUnregister(player);
@@ -274,7 +266,7 @@ public class AsynchronousUnregisterTest {
// then
verify(dataSource).removeAuth(name);
verify(playerCache).removePlayer(name);
verifyZeroInteractions(authGroupHandler, teleportationService);
verifyZeroInteractions(teleportationService);
verifyCalledUnregisterEventFor(null);
}
@@ -291,7 +283,7 @@ public class AsynchronousUnregisterTest {
// then
verify(dataSource).removeAuth(name);
verify(service).send(initiator, MessageKey.ERROR);
verifyZeroInteractions(playerCache, teleportationService, authGroupHandler, bukkitService);
verifyZeroInteractions(playerCache, teleportationService, bukkitService);
}
@SuppressWarnings("unchecked")
@@ -2,8 +2,6 @@ package fr.xephi.authme.service;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.message.Messages;
import fr.xephi.authme.permission.AuthGroupHandler;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PlayerPermission;
@@ -41,9 +39,6 @@ public class CommonServiceTest {
@Mock
private PermissionsManager permissionsManager;
@Mock
private AuthGroupHandler authGroupHandler;
@Test
public void shouldGetProperty() {
// given
@@ -113,17 +108,4 @@ public class CommonServiceTest {
verify(permissionsManager).hasPermission(player, permission);
assertThat(result, equalTo(true));
}
@Test
public void shouldSetPermissionGroup() {
// given
Player player = mock(Player.class);
AuthGroupType type = AuthGroupType.LOGGED_IN;
// when
commonService.setGroup(player, type);
// then
verify(authGroupHandler).setGroup(player, type);
}
}