Search in sources :

Example 16 with Settings

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

the class Pbkdf2Test method mockSettings.

private static Settings mockSettings() {
    Settings settings = mock(Settings.class);
    given(settings.getProperty(SecuritySettings.PBKDF2_NUMBER_OF_ROUNDS)).willReturn(4128);
    return settings;
}
Also used : SecuritySettings(fr.xephi.authme.settings.properties.SecuritySettings) Settings(fr.xephi.authme.settings.Settings)

Example 17 with Settings

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

the class MySqlIntegrationTest method initializeSettings.

/**
     * Set up the settings mock to return specific values for database settings and load {@link #sqlInitialize}.
     */
@SuppressWarnings({ "unchecked", "rawtypes" })
@BeforeClass
public static void initializeSettings() throws IOException, ClassNotFoundException {
    // Check that we have an H2 driver
    Class.forName("org.h2.jdbcx.JdbcDataSource");
    settings = mock(Settings.class);
    when(settings.getProperty(any(Property.class))).thenAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return ((Property) invocation.getArguments()[0]).getDefaultValue();
        }
    });
    set(DatabaseSettings.MYSQL_DATABASE, "h2_test");
    set(DatabaseSettings.MYSQL_TABLE, "authme");
    TestHelper.setRealLogger();
    Path sqlInitFile = TestHelper.getJarPath(TestHelper.PROJECT_ROOT + "datasource/sql-initialize.sql");
    sqlInitialize = new String(Files.readAllBytes(sqlInitFile));
}
Also used : Path(java.nio.file.Path) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Property(ch.jalu.configme.properties.Property) Settings(fr.xephi.authme.settings.Settings) DatabaseSettings(fr.xephi.authme.settings.properties.DatabaseSettings) BeforeClass(org.junit.BeforeClass)

Example 18 with Settings

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

the class AuthMe method initialize.

/**
     * Initialize the plugin and all the services.
     */
private void initialize() {
    // Set the Logger instance and log file path
    ConsoleLogger.setLogger(getLogger());
    ConsoleLogger.setLogFile(new File(getDataFolder(), LOG_FILENAME));
    // Check java version
    if (!SystemUtils.isJavaVersionAtLeast(1.8f)) {
        throw new IllegalStateException("You need Java 1.8 or above to run this plugin!");
    }
    OnStartupTasks.verifyIfLegacyJarIsNeeded();
    // Create plugin folder
    getDataFolder().mkdir();
    // Create injector, provide elements from the Bukkit environment and register providers
    injector = new InjectorBuilder().addHandlers(new FactoryDependencyHandler(), new SingletonStoreDependencyHandler()).addDefaultHandlers("fr.xephi.authme").create();
    injector.register(AuthMe.class, this);
    injector.register(Server.class, getServer());
    injector.register(PluginManager.class, getServer().getPluginManager());
    injector.register(BukkitScheduler.class, getServer().getScheduler());
    injector.provide(DataFolder.class, getDataFolder());
    injector.registerProvider(Settings.class, SettingsProvider.class);
    injector.registerProvider(DataSource.class, DataSourceProvider.class);
    // Get settings and set up logger
    settings = injector.getSingleton(Settings.class);
    ConsoleLogger.setLoggingOptions(settings);
    OnStartupTasks.setupConsoleFilter(settings, getLogger());
    // Set all service fields on the AuthMe class
    instantiateServices(injector);
    // Convert deprecated PLAINTEXT hash entries
    MigrationService.changePlainTextToSha256(settings, database, new Sha256());
    // If the server is empty (fresh start) just set all the players as unlogged
    if (bukkitService.getOnlinePlayers().isEmpty()) {
        database.purgeLogged();
    }
    // Register event listeners
    registerEventListeners(injector);
    // Start Email recall task if needed
    OnStartupTasks onStartupTasks = injector.newInstance(OnStartupTasks.class);
    onStartupTasks.scheduleRecallEmailTask();
}
Also used : OnStartupTasks(fr.xephi.authme.initialization.OnStartupTasks) SingletonStoreDependencyHandler(fr.xephi.authme.initialization.factory.SingletonStoreDependencyHandler) FactoryDependencyHandler(fr.xephi.authme.initialization.factory.FactoryDependencyHandler) InjectorBuilder(ch.jalu.injector.InjectorBuilder) File(java.io.File) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) SecuritySettings(fr.xephi.authme.settings.properties.SecuritySettings) RestrictionSettings(fr.xephi.authme.settings.properties.RestrictionSettings) PluginSettings(fr.xephi.authme.settings.properties.PluginSettings) Settings(fr.xephi.authme.settings.Settings) EmailSettings(fr.xephi.authme.settings.properties.EmailSettings) Sha256(fr.xephi.authme.security.crypts.Sha256)

Example 19 with Settings

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

the class TempbanManagerTest method shouldNotIncreaseCountForDisabledTempban.

@Test
public void shouldNotIncreaseCountForDisabledTempban() {
    // given
    String address = "192.168.1.3";
    Settings settings = mockSettings(1, 5);
    given(settings.getProperty(SecuritySettings.TEMPBAN_ON_MAX_LOGINS)).willReturn(false);
    TempbanManager manager = new TempbanManager(bukkitService, messages, settings);
    // when
    manager.increaseCount(address, "username");
    // then
    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 20 with Settings

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

the class TempbanManagerTest method shouldBanPlayerIp.

@Test
public void shouldBanPlayerIp() {
    // given
    Player player = mock(Player.class);
    String ip = "123.45.67.89";
    TestHelper.mockPlayerIp(player, ip);
    String banReason = "IP ban too many logins";
    given(messages.retrieveSingle(MessageKey.TEMPBAN_MAX_LOGINS)).willReturn(banReason);
    Settings settings = mockSettings(2, 100);
    TempbanManager manager = new TempbanManager(bukkitService, messages, settings);
    // when
    manager.tempbanPlayer(player);
    TestHelper.runSyncDelayedTask(bukkitService);
    // then
    verify(player).kickPlayer(banReason);
    ArgumentCaptor<Date> captor = ArgumentCaptor.forClass(Date.class);
    verify(bukkitService).banIp(eq(ip), eq(banReason), captor.capture(), eq("AuthMe"));
    // Compute the expected expiration date and check that the actual date is within the difference tolerance
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MINUTE, 100);
    long expectedExpiration = cal.getTime().getTime();
    assertThat(Math.abs(captor.getValue().getTime() - expectedExpiration), lessThan(DATE_TOLERANCE_MILLISECONDS));
}
Also used : Player(org.bukkit.entity.Player) Calendar(java.util.Calendar) SecuritySettings(fr.xephi.authme.settings.properties.SecuritySettings) Settings(fr.xephi.authme.settings.Settings) Date(java.util.Date) 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