Search in sources :

Example 31 with Settings

use of fr.xephi.authme.settings.Settings in project AuthMeReloaded by AuthMe.

the class SessionManagerTest method shouldNotAddSessionBecauseTimeoutIsZero.

@Test
public void shouldNotAddSessionBecauseTimeoutIsZero() {
    // given
    Settings settings = mockSettings(true, 0);
    SessionManager manager = new SessionManager(settings);
    String player = "playah";
    // when
    manager.addSession(player);
    // then
    assertThat(manager.hasSession(player), equalTo(false));
}
Also used : Settings(fr.xephi.authme.settings.Settings) PluginSettings(fr.xephi.authme.settings.properties.PluginSettings) Test(org.junit.Test)

Example 32 with Settings

use of fr.xephi.authme.settings.Settings in project AuthMeReloaded by AuthMe.

the class SessionManagerTest method shouldNotHaveSession.

@Test
public void shouldNotHaveSession() {
    // given
    Settings settings = mockSettings(true, 10);
    SessionManager manager = new SessionManager(settings);
    String player = "playah";
    // when/then
    assertThat(manager.hasSession(player), equalTo(false));
}
Also used : Settings(fr.xephi.authme.settings.Settings) PluginSettings(fr.xephi.authme.settings.properties.PluginSettings) Test(org.junit.Test)

Example 33 with Settings

use of fr.xephi.authme.settings.Settings in project AuthMeReloaded by AuthMe.

the class CaptchaManagerTest method shouldAddCounts.

@Test
public void shouldAddCounts() {
    // given
    Settings settings = mockSettings(3, 4);
    CaptchaManager manager = new CaptchaManager(settings);
    String player = "tester";
    // when
    for (int i = 0; i < 2; ++i) {
        manager.increaseCount(player);
    }
    // then
    assertThat(manager.isCaptchaRequired(player), equalTo(false));
    manager.increaseCount(player);
    assertThat(manager.isCaptchaRequired(player.toUpperCase()), equalTo(true));
    assertThat(manager.isCaptchaRequired("otherPlayer"), equalTo(false));
}
Also used : SecuritySettings(fr.xephi.authme.settings.properties.SecuritySettings) Settings(fr.xephi.authme.settings.Settings) Test(org.junit.Test)

Example 34 with Settings

use of fr.xephi.authme.settings.Settings in project AuthMeReloaded by AuthMe.

the class CaptchaManagerTest method shouldNotIncreaseCountForDisabledCaptcha.

@Test
public void shouldNotIncreaseCountForDisabledCaptcha() {
    // given
    String player = "someone_";
    Settings settings = mockSettings(1, 3);
    given(settings.getProperty(SecuritySettings.USE_CAPTCHA)).willReturn(false);
    CaptchaManager manager = new CaptchaManager(settings);
    // when
    manager.increaseCount(player);
    // then
    assertThat(manager.isCaptchaRequired(player), equalTo(false));
    assertHasCount(manager, player, 0);
}
Also used : SecuritySettings(fr.xephi.authme.settings.properties.SecuritySettings) Settings(fr.xephi.authme.settings.Settings) Test(org.junit.Test)

Example 35 with Settings

use of fr.xephi.authme.settings.Settings in project AuthMeReloaded by AuthMe.

the class CaptchaManagerTest method mockSettings.

private static Settings mockSettings(int maxTries, int captchaLength) {
    Settings settings = mock(Settings.class);
    given(settings.getProperty(SecuritySettings.USE_CAPTCHA)).willReturn(true);
    given(settings.getProperty(SecuritySettings.MAX_LOGIN_TRIES_BEFORE_CAPTCHA)).willReturn(maxTries);
    given(settings.getProperty(SecuritySettings.CAPTCHA_LENGTH)).willReturn(captchaLength);
    given(settings.getProperty(SecuritySettings.CAPTCHA_COUNT_MINUTES_BEFORE_RESET)).willReturn(30);
    return settings;
}
Also used : SecuritySettings(fr.xephi.authme.settings.properties.SecuritySettings) Settings(fr.xephi.authme.settings.Settings)

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