Search in sources :

Example 26 with Settings

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

the class CaptchaManagerTest method shouldCreateAndCheckCaptcha.

@Test
public void shouldCreateAndCheckCaptcha() {
    // given
    String player = "Miner";
    Settings settings = mockSettings(1, 4);
    CaptchaManager manager = new CaptchaManager(settings);
    String captchaCode = manager.getCaptchaCodeOrGenerateNew(player);
    // when
    boolean badResult = manager.checkCode(player, "wrong_code");
    boolean goodResult = manager.checkCode(player, captchaCode);
    // then
    assertThat(captchaCode.length(), equalTo(4));
    assertThat(badResult, equalTo(false));
    assertThat(goodResult, equalTo(true));
    // Supplying correct code should clear the entry, and any code should be valid if no entry is present
    assertThat(manager.checkCode(player, "bogus"), equalTo(true));
}
Also used : SecuritySettings(fr.xephi.authme.settings.properties.SecuritySettings) Settings(fr.xephi.authme.settings.Settings) Test(org.junit.Test)

Example 27 with Settings

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

the class SessionManagerTest method shouldClearAllSessionsAfterDisable.

@Test
public void shouldClearAllSessionsAfterDisable() {
    // given
    Settings settings = mockSettings(true, 10);
    SessionManager manager = new SessionManager(settings);
    manager.addSession("player01");
    manager.addSession("player02");
    // when
    manager.reload(mockSettings(false, 20));
    // then
    assertThat(getSessionsMap(manager).isEmpty(), equalTo(true));
}
Also used : Settings(fr.xephi.authme.settings.Settings) PluginSettings(fr.xephi.authme.settings.properties.PluginSettings) Test(org.junit.Test)

Example 28 with Settings

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

the class SessionManagerTest method shouldPerformCleanup.

@Test
public void shouldPerformCleanup() {
    // given
    Settings settings = mockSettings(true, 1);
    SessionManager manager = new SessionManager(settings);
    ExpiringSet<String> expiringSet = mockExpiringSet();
    setSessionsMap(manager, expiringSet);
    // when
    manager.performCleanup();
    // then
    verify(expiringSet).removeExpiredEntries();
}
Also used : Settings(fr.xephi.authme.settings.Settings) PluginSettings(fr.xephi.authme.settings.properties.PluginSettings) Test(org.junit.Test)

Example 29 with Settings

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

the class SessionManagerTest method mockSettings.

private static Settings mockSettings(boolean isEnabled, int sessionTimeout) {
    Settings settings = mock(Settings.class);
    given(settings.getProperty(PluginSettings.SESSIONS_ENABLED)).willReturn(isEnabled);
    given(settings.getProperty(PluginSettings.SESSIONS_TIMEOUT)).willReturn(sessionTimeout);
    return settings;
}
Also used : Settings(fr.xephi.authme.settings.Settings) PluginSettings(fr.xephi.authme.settings.properties.PluginSettings)

Example 30 with Settings

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

the class SessionManagerTest method shouldHaveSession.

@Test
public void shouldHaveSession() {
    // given
    Settings settings = mockSettings(true, 10);
    SessionManager manager = new SessionManager(settings);
    String player = "playah";
    // when
    manager.addSession(player);
    // then
    assertThat(manager.hasSession(player), equalTo(true));
}
Also used : Settings(fr.xephi.authme.settings.Settings) PluginSettings(fr.xephi.authme.settings.properties.PluginSettings) 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