use of fr.xephi.authme.settings.Settings in project AuthMeReloaded by AuthMe.
the class TempbanManagerTest method shouldIncreaseAndResetCount.
@Test
public void shouldIncreaseAndResetCount() {
// given
String address = "192.168.1.2";
Settings settings = mockSettings(3, 60);
TempbanManager manager = new TempbanManager(bukkitService, messages, settings);
// when
manager.increaseCount(address, "test");
manager.increaseCount(address, "test");
manager.increaseCount(address, "test");
// then
assertThat(manager.shouldTempban(address), equalTo(true));
assertHasCount(manager, address, "test", 3);
// when 2
manager.resetCount(address, "test");
// then 2
assertThat(manager.shouldTempban(address), equalTo(false));
assertHasNoEntries(manager, address);
}
use of fr.xephi.authme.settings.Settings in project AuthMeReloaded by AuthMe.
the class TempbanManagerTest method mockSettings.
private static Settings mockSettings(int maxTries, int tempbanLength) {
Settings settings = mock(Settings.class);
given(settings.getProperty(SecuritySettings.TEMPBAN_ON_MAX_LOGINS)).willReturn(true);
given(settings.getProperty(SecuritySettings.MAX_LOGIN_TEMPBAN)).willReturn(maxTries);
given(settings.getProperty(SecuritySettings.TEMPBAN_LENGTH)).willReturn(tempbanLength);
given(settings.getProperty(SecuritySettings.TEMPBAN_MINUTES_BEFORE_RESET)).willReturn((int) TEST_EXPIRATION_THRESHOLD / 60_000);
return settings;
}
use of fr.xephi.authme.settings.Settings in project AuthMeReloaded by AuthMe.
the class TempbanManagerTest method shouldNotCheckCountIfTempbanIsDisabled.
@Test
public void shouldNotCheckCountIfTempbanIsDisabled() {
// given
String address = "192.168.1.4";
Settings settings = mockSettings(1, 5);
TempbanManager manager = new TempbanManager(bukkitService, messages, settings);
given(settings.getProperty(SecuritySettings.TEMPBAN_ON_MAX_LOGINS)).willReturn(false);
// when
manager.increaseCount(address, "username");
// assumptions
assertThat(manager.shouldTempban(address), equalTo(true));
assertHasCount(manager, address, "username", 1);
// end assumptions
manager.reload(settings);
boolean result = manager.shouldTempban(address);
// then
assertThat(result, equalTo(false));
}
use of fr.xephi.authme.settings.Settings in project AuthMeReloaded by AuthMe.
the class TempbanManagerTest method shouldNotIssueBanIfDisabled.
@Test
public void shouldNotIssueBanIfDisabled() {
// given
Settings settings = mockSettings(0, 0);
given(settings.getProperty(SecuritySettings.TEMPBAN_ON_MAX_LOGINS)).willReturn(false);
Player player = mock(Player.class);
TempbanManager manager = new TempbanManager(bukkitService, messages, settings);
// when
manager.tempbanPlayer(player);
// then
verifyZeroInteractions(player, bukkitService);
}
use of fr.xephi.authme.settings.Settings in project AuthMeReloaded by AuthMe.
the class TempbanManagerTest method shouldResetCountAfterBan.
@Test
public void shouldResetCountAfterBan() {
// given
Player player = mock(Player.class);
String ip = "22.44.66.88";
TestHelper.mockPlayerIp(player, ip);
String banReason = "kick msg";
given(messages.retrieveSingle(MessageKey.TEMPBAN_MAX_LOGINS)).willReturn(banReason);
Settings settings = mockSettings(10, 60);
TempbanManager manager = new TempbanManager(bukkitService, messages, settings);
manager.increaseCount(ip, "user");
manager.increaseCount(ip, "name2");
manager.increaseCount(ip, "user");
// when
manager.tempbanPlayer(player);
TestHelper.runSyncDelayedTask(bukkitService);
// then
verify(player).kickPlayer(banReason);
assertHasNoEntries(manager, ip);
}
Aggregations