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;
}
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));
}
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();
}
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);
}
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));
}
Aggregations