mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-02-15 19:32:05 +01:00
Merge branch '5.5.0' of https://github.com/AuthMe/AuthMeReloaded
This commit is contained in:
commit
c27a8d359c
@ -59,49 +59,11 @@ final class MySqlMigrater {
|
|||||||
columnType = rs.getInt("DATA_TYPE");
|
columnType = rs.getInt("DATA_TYPE");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (columnType == Types.TIMESTAMP) {
|
if (columnType == Types.INTEGER) {
|
||||||
migrateLastLoginColumnFromTimestamp(st, tableName, col);
|
|
||||||
} else if (columnType == Types.INTEGER) {
|
|
||||||
migrateLastLoginColumnFromInt(st, tableName, col);
|
migrateLastLoginColumnFromInt(st, tableName, col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs conversion of lastlogin column from timestamp type to bigint.
|
|
||||||
*
|
|
||||||
* @param st Statement object to the database
|
|
||||||
* @param tableName the table name
|
|
||||||
* @param col the column names configuration
|
|
||||||
* @see <a href="https://github.com/AuthMe/AuthMeReloaded/issues/477">#477</a>
|
|
||||||
*/
|
|
||||||
private static void migrateLastLoginColumnFromTimestamp(Statement st, String tableName,
|
|
||||||
Columns col) throws SQLException {
|
|
||||||
ConsoleLogger.info("Migrating lastlogin column from timestamp to bigint");
|
|
||||||
final String lastLoginOld = col.LAST_LOGIN + "_old";
|
|
||||||
|
|
||||||
// Rename lastlogin to lastlogin_old
|
|
||||||
String sql = String.format("ALTER TABLE %s CHANGE COLUMN %s %s BIGINT",
|
|
||||||
tableName, col.LAST_LOGIN, lastLoginOld);
|
|
||||||
st.execute(sql);
|
|
||||||
|
|
||||||
// Create lastlogin column
|
|
||||||
sql = String.format("ALTER TABLE %s ADD COLUMN %s "
|
|
||||||
+ "BIGINT NOT NULL DEFAULT 0 AFTER %s",
|
|
||||||
tableName, col.LAST_LOGIN, col.LAST_IP);
|
|
||||||
st.execute(sql);
|
|
||||||
|
|
||||||
// Set values of lastlogin based on lastlogin_old
|
|
||||||
sql = String.format("UPDATE %s SET %s = UNIX_TIMESTAMP(%s) * 1000",
|
|
||||||
tableName, col.LAST_LOGIN, lastLoginOld);
|
|
||||||
st.execute(sql);
|
|
||||||
|
|
||||||
// Drop lastlogin_old
|
|
||||||
sql = String.format("ALTER TABLE %s DROP COLUMN %s",
|
|
||||||
tableName, lastLoginOld);
|
|
||||||
st.execute(sql);
|
|
||||||
ConsoleLogger.info("Finished migration of lastlogin (timestamp to bigint)");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs conversion of lastlogin column from int to bigint.
|
* Performs conversion of lastlogin column from int to bigint.
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package fr.xephi.authme.permission.handlers;
|
package fr.xephi.authme.permission.handlers;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import fr.xephi.authme.permission.PermissionNode;
|
import fr.xephi.authme.permission.PermissionNode;
|
||||||
import fr.xephi.authme.permission.PermissionsSystemType;
|
import fr.xephi.authme.permission.PermissionsSystemType;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
@ -8,6 +9,7 @@ import org.bukkit.Server;
|
|||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,7 +26,15 @@ public class VaultHandler implements PermissionHandler {
|
|||||||
this.vaultProvider = getVaultPermission(server);
|
this.vaultProvider = getVaultPermission(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Permission getVaultPermission(Server server) throws PermissionHandlerException {
|
/**
|
||||||
|
* Returns the Vault Permission interface.
|
||||||
|
*
|
||||||
|
* @param server the bukkit server instance
|
||||||
|
* @return the vault permission instance
|
||||||
|
* @throws PermissionHandlerException if the vault permission instance cannot be retrieved
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
Permission getVaultPermission(Server server) throws PermissionHandlerException {
|
||||||
// Get the permissions provider service
|
// Get the permissions provider service
|
||||||
RegisteredServiceProvider<Permission> permissionProvider = server
|
RegisteredServiceProvider<Permission> permissionProvider = server
|
||||||
.getServicesManager().getRegistration(Permission.class);
|
.getServicesManager().getRegistration(Permission.class);
|
||||||
@ -76,7 +86,8 @@ public class VaultHandler implements PermissionHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getGroups(OfflinePlayer player) {
|
public List<String> getGroups(OfflinePlayer player) {
|
||||||
return Arrays.asList(vaultProvider.getPlayerGroups(null, player));
|
String[] groups = vaultProvider.getPlayerGroups(null, player);
|
||||||
|
return groups == null ? Collections.emptyList() : Arrays.asList(groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -38,6 +38,7 @@ import static fr.xephi.authme.permission.PermissionsSystemType.LUCK_PERMS;
|
|||||||
import static fr.xephi.authme.permission.PermissionsSystemType.PERMISSIONS_EX;
|
import static fr.xephi.authme.permission.PermissionsSystemType.PERMISSIONS_EX;
|
||||||
import static fr.xephi.authme.permission.PermissionsSystemType.VAULT;
|
import static fr.xephi.authme.permission.PermissionsSystemType.VAULT;
|
||||||
import static fr.xephi.authme.permission.PermissionsSystemType.Z_PERMISSIONS;
|
import static fr.xephi.authme.permission.PermissionsSystemType.Z_PERMISSIONS;
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.hamcrest.Matchers.nullValue;
|
import static org.hamcrest.Matchers.nullValue;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
@ -89,6 +90,7 @@ public class PermissionsManagerInitializationTest {
|
|||||||
// then
|
// then
|
||||||
PermissionHandler handler = getHandlerFieldValue();
|
PermissionHandler handler = getHandlerFieldValue();
|
||||||
assertThat(handler, instanceOf(expectedHandlerType));
|
assertThat(handler, instanceOf(expectedHandlerType));
|
||||||
|
assertThat(handler.getPermissionSystem(), equalTo(permissionsSystemType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -0,0 +1,80 @@
|
|||||||
|
package fr.xephi.authme.permission.handlers;
|
||||||
|
|
||||||
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.contains;
|
||||||
|
import static org.hamcrest.Matchers.empty;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.mockito.BDDMockito.given;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for {@link VaultHandler}.
|
||||||
|
*/
|
||||||
|
public class VaultHandlerTest {
|
||||||
|
|
||||||
|
private VaultHandlerTestImpl vaultHandlerTest = VaultHandlerTestImpl.create();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnGroups() {
|
||||||
|
// given
|
||||||
|
Permission permissionMock = vaultHandlerTest.permissionMock;
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
given(permissionMock.getPlayerGroups(null, player)).willReturn(new String[]{"abc", "test"});
|
||||||
|
|
||||||
|
// when
|
||||||
|
List<String> result = vaultHandlerTest.getGroups(player);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(result, contains("abc", "test"));
|
||||||
|
verify(permissionMock).getPlayerGroups(null, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bug #1702: VaultHandler may return null for groups list.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void shouldHandleNullAsGroups() {
|
||||||
|
// given
|
||||||
|
Permission permissionMock = vaultHandlerTest.permissionMock;
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
given(permissionMock.getPlayerGroups(null, player)).willReturn(null);
|
||||||
|
|
||||||
|
// when
|
||||||
|
List<String> result = vaultHandlerTest.getGroups(player);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(result, empty());
|
||||||
|
verify(permissionMock).getPlayerGroups(null, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Test implementation using a mock Vault Permission instance. */
|
||||||
|
private static final class VaultHandlerTestImpl extends VaultHandler {
|
||||||
|
|
||||||
|
private Permission permissionMock;
|
||||||
|
|
||||||
|
VaultHandlerTestImpl() throws PermissionHandlerException {
|
||||||
|
super(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VaultHandlerTestImpl create() {
|
||||||
|
try {
|
||||||
|
return new VaultHandlerTestImpl();
|
||||||
|
} catch (PermissionHandlerException e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
Permission getVaultPermission(Server server) {
|
||||||
|
permissionMock = mock(Permission.class);
|
||||||
|
return permissionMock;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user