mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-09 04:02:10 +01:00
#950 Add unregister by name to API
- Add method to API - Ensure that unregistering in datasource is case-insensitive
This commit is contained in:
parent
f804b528e5
commit
405bd563d8
@ -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)
|
||||
*
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user