#950 Add unregister by name to API

- Add method to API
- Ensure that unregistering in datasource is case-insensitive
This commit is contained in:
ljacqu 2016-09-18 14:46:02 +02:00
parent f804b528e5
commit 405bd563d8
5 changed files with 42 additions and 3 deletions

View File

@ -221,6 +221,15 @@ public class NewAPI {
management.performUnregisterByAdmin(null, player.getName(), player);
}
/**
* Unregister a player from AuthMe by name.
*
* @param name the name of the player (case-insensitive)
*/
public void forceUnregister(String name) {
management.performUnregisterByAdmin(null, name, Bukkit.getPlayer(name));
}
/**
* Get all the registered names (lowercase)
*

View File

@ -612,7 +612,7 @@ public class MySQL implements DataSource {
}
}
}
pst.setString(1, user);
pst.setString(1, user.toLowerCase());
pst.executeUpdate();
return true;
} catch (SQLException ex) {

View File

@ -335,7 +335,7 @@ public class SQLite implements DataSource {
PreparedStatement pst = null;
try {
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;");
pst.setString(1, user);
pst.setString(1, user.toLowerCase());
pst.executeUpdate();
return true;
} catch (SQLException ex) {

View File

@ -212,6 +212,36 @@ public class NewAPITest {
assertThat(result, contains(names));
}
@Test
public void shouldUnregisterPlayer() {
// given
Player player = mock(Player.class);
String name = "Donald";
given(player.getName()).willReturn(name);
// when
api.forceUnregister(player);
// then
verify(management).performUnregisterByAdmin(null, name, player);
}
@Test
public void shouldUnregisterPlayerByName() {
// given
Server server = mock(Server.class);
ReflectionTestUtils.setField(Bukkit.class, null, "server", server);
String name = "tristan";
Player player = mock(Player.class);
given(server.getPlayer(name)).willReturn(player);
// when
api.forceUnregister(name);
// then
verify(management).performUnregisterByAdmin(null, name, player);
}
private static Player mockPlayerWithName(String name) {
Player player = mock(Player.class);
given(player.getName()).willReturn(name);

View File

@ -195,7 +195,7 @@ public abstract class AbstractDataSourceIntegrationTest {
DataSource dataSource = getDataSource();
// when
boolean response1 = dataSource.removeAuth("bobby");
boolean response1 = dataSource.removeAuth("Bobby");
boolean response2 = dataSource.removeAuth("does-not-exist");
// then