Search in sources :

Example 21 with Settings

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);
}
Also used : SecuritySettings(fr.xephi.authme.settings.properties.SecuritySettings) Settings(fr.xephi.authme.settings.Settings) Test(org.junit.Test)

Example 22 with Settings

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;
}
Also used : SecuritySettings(fr.xephi.authme.settings.properties.SecuritySettings) Settings(fr.xephi.authme.settings.Settings)

Example 23 with 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));
}
Also used : SecuritySettings(fr.xephi.authme.settings.properties.SecuritySettings) Settings(fr.xephi.authme.settings.Settings) Test(org.junit.Test)

Example 24 with Settings

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);
}
Also used : Player(org.bukkit.entity.Player) SecuritySettings(fr.xephi.authme.settings.properties.SecuritySettings) Settings(fr.xephi.authme.settings.Settings) Test(org.junit.Test)

Example 25 with Settings

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);
}
Also used : Player(org.bukkit.entity.Player) SecuritySettings(fr.xephi.authme.settings.properties.SecuritySettings) Settings(fr.xephi.authme.settings.Settings) Test(org.junit.Test)

Aggregations

Settings (fr.xephi.authme.settings.Settings)37 Test (org.junit.Test)23 SecuritySettings (fr.xephi.authme.settings.properties.SecuritySettings)21 PluginSettings (fr.xephi.authme.settings.properties.PluginSettings)12 BeforeClass (org.junit.BeforeClass)5 Property (ch.jalu.configme.properties.Property)4 InjectorBuilder (ch.jalu.injector.InjectorBuilder)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 File (java.io.File)3 Player (org.bukkit.entity.Player)3 Answer (org.mockito.stubbing.Answer)3 PropertyResource (ch.jalu.configme.resource.PropertyResource)2 Injector (ch.jalu.injector.Injector)2 FactoryDependencyHandler (fr.xephi.authme.initialization.factory.FactoryDependencyHandler)2 SingletonStoreDependencyHandler (fr.xephi.authme.initialization.factory.SingletonStoreDependencyHandler)2 DatabaseSettings (fr.xephi.authme.settings.properties.DatabaseSettings)2 HooksSettings (fr.xephi.authme.settings.properties.HooksSettings)2 Path (java.nio.file.Path)2 ConfigurationData (ch.jalu.configme.configurationdata.ConfigurationData)1 YamlFileResource (ch.jalu.configme.resource.YamlFileResource)1