From 1c46c92b4ecb086a0df0f2779f29046a4bdafc09 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sun, 21 May 2017 12:28:35 +0200 Subject: [PATCH] #1146 List available converter, reference converters Wiki page in config.yml --- docs/config.md | 21 +++++++++++++--- .../authme/command/CommandInitializer.java | 2 +- .../executable/authme/ConverterCommand.java | 23 +++++++++-------- .../properties/ConverterSettings.java | 9 +++++++ .../authme/ConverterCommandTest.java | 25 ++++++++++++++----- 5 files changed, 58 insertions(+), 22 deletions(-) diff --git a/docs/config.md b/docs/config.md index 1200fe2ed..a087e1ae0 100644 --- a/docs/config.md +++ b/docs/config.md @@ -1,5 +1,5 @@ - + ## AuthMe Configuration The first time you run AuthMe it will create a config.yml file in the plugins/AuthMe folder, @@ -219,14 +219,14 @@ settings: # PBKDF2DJANGO, WORDPRESS, ROYALAUTH, CUSTOM (for developers only). See full list at # https://github.com/AuthMe/AuthMeReloaded/blob/master/docs/hash_algorithms.md passwordHash: 'SHA256' - # Salt length for the SALTED2MD5 MD5(MD5(password)+salt) - doubleMD5SaltLength: 8 # If a password check fails, AuthMe will also try to check with the following hash methods. # Use this setting when you change from one hash method to another. # AuthMe will update the password to the new hash. Example: # legacyHashes: # - 'SHA1' legacyHashes: [] + # Salt length for the SALTED2MD5 MD5(MD5(password)+salt) + doubleMD5SaltLength: 8 # Number of rounds to use if passwordHash is set to PBKDF2. Default is 10000 pbkdf2Rounds: 10000 # Prevent unsafe passwords from being used; put them in lowercase! @@ -493,6 +493,7 @@ BackupSystem: OnServerStop: true # Windows only: MySQL installation path MysqlWindowsPath: 'C:\Program Files\MySQL\MySQL Server 5.1\' +# Converter settings: see https://github.com/AuthMe/AuthMeReloaded/wiki/Converters Converter: Rakamak: # Rakamak file name @@ -504,6 +505,18 @@ Converter: CrazyLogin: # CrazyLogin database file name fileName: 'accounts.db' + loginSecurity: + # LoginSecurity: convert from SQLite; if false we use MySQL + useSqlite: true + mySql: + # LoginSecurity MySQL: database host + host: '' + # LoginSecurity MySQL: database name + database: '' + # LoginSecurity MySQL: database user + user: '' + # LoginSecurity MySQL: password for database user + password: '' ``` To change settings on a running server, save your changes to config.yml and use @@ -511,4 +524,4 @@ To change settings on a running server, save your changes to config.yml and use --- -This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sat Apr 29 18:27:38 CEST 2017 +This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sun May 21 12:23:19 CEST 2017 diff --git a/src/main/java/fr/xephi/authme/command/CommandInitializer.java b/src/main/java/fr/xephi/authme/command/CommandInitializer.java index 1c1240a26..2e18cb1a0 100644 --- a/src/main/java/fr/xephi/authme/command/CommandInitializer.java +++ b/src/main/java/fr/xephi/authme/command/CommandInitializer.java @@ -316,7 +316,7 @@ public class CommandInitializer { .description("Converter command") .detailedDescription("Converter command for AuthMeReloaded.") .withArgument("job", "Conversion job: xauth / crazylogin / rakamak / " - + "royalauth / vauth / sqliteToSql / mysqlToSqlite / loginsecurity", false) + + "royalauth / vauth / sqliteToSql / mysqlToSqlite / loginsecurity", true) .permission(AdminPermission.CONVERTER) .executableCommand(ConverterCommand.class) .register(); diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ConverterCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ConverterCommand.java index ac542c733..b0d1c7faf 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/ConverterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/ConverterCommand.java @@ -1,7 +1,7 @@ package fr.xephi.authme.command.executable.authme; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSortedMap; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.datasource.converter.Converter; @@ -41,14 +41,10 @@ public class ConverterCommand implements ExecutableCommand { private Factory converterFactory; @Override - public void executeCommand(final CommandSender sender, List arguments) { - // Get the conversion job - String job = arguments.get(0); - - // Determine the job type - Class converterClass = CONVERTERS.get(job.toLowerCase()); + public void executeCommand(CommandSender sender, List arguments) { + Class converterClass = getConverterClassFromArgs(arguments); if (converterClass == null) { - sender.sendMessage("[AuthMe] Converter does not exist!"); + sender.sendMessage("Converters: " + String.join(", ", CONVERTERS.keySet())); return; } @@ -69,7 +65,13 @@ public class ConverterCommand implements ExecutableCommand { }); // Show a status message - sender.sendMessage("[AuthMe] Successfully started " + job); + sender.sendMessage("[AuthMe] Successfully started " + arguments.get(0)); + } + + private static Class getConverterClassFromArgs(List arguments) { + return arguments.isEmpty() + ? null + : CONVERTERS.get(arguments.get(0).toLowerCase()); } /** @@ -78,7 +80,7 @@ public class ConverterCommand implements ExecutableCommand { * @return map with all available converters */ private static Map> getConverters() { - return ImmutableMap.>builder() + return ImmutableSortedMap.>naturalOrder() .put("xauth", XAuthConverter.class) .put("crazylogin", CrazyLoginConverter.class) .put("rakamak", RakamakConverter.class) @@ -89,5 +91,4 @@ public class ConverterCommand implements ExecutableCommand { .put("loginsecurity", LoginSecurityConverter.class) .build(); } - } diff --git a/src/main/java/fr/xephi/authme/settings/properties/ConverterSettings.java b/src/main/java/fr/xephi/authme/settings/properties/ConverterSettings.java index c845b3bfc..d1c426d6b 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/ConverterSettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/ConverterSettings.java @@ -1,8 +1,12 @@ package fr.xephi.authme.settings.properties; import ch.jalu.configme.Comment; +import ch.jalu.configme.SectionComments; import ch.jalu.configme.SettingsHolder; import ch.jalu.configme.properties.Property; +import com.google.common.collect.ImmutableMap; + +import java.util.Map; import static ch.jalu.configme.properties.PropertyInitializer.newProperty; @@ -47,4 +51,9 @@ public final class ConverterSettings implements SettingsHolder { private ConverterSettings() { } + @SectionComments + public static Map buildSectionComments() { + return ImmutableMap.of("Converter", + new String[]{"Converter settings: see https://github.com/AuthMe/AuthMeReloaded/wiki/Converters"}); + } } diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/ConverterCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/ConverterCommandTest.java index 0474eac1a..bf19d7610 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/ConverterCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/ConverterCommandTest.java @@ -42,7 +42,7 @@ public class ConverterCommandTest { private ConverterCommand command; @Mock - private CommonService commandService; + private CommonService commonService; @Mock private BukkitService bukkitService; @@ -64,10 +64,23 @@ public class ConverterCommandTest { command.executeCommand(sender, Collections.singletonList("invalid")); // then - verify(sender).sendMessage(argThat(containsString("Converter does not exist"))); - verifyNoMoreInteractions(commandService); - verifyZeroInteractions(converterFactory); - verifyZeroInteractions(bukkitService); + String converters = String.join(", ", ConverterCommand.CONVERTERS.keySet()); + verify(sender).sendMessage(argThat(containsString(converters))); + verifyZeroInteractions(commonService, converterFactory, bukkitService); + } + + @Test + public void shouldHandleCommandWithNoArgs() { + // given + CommandSender sender = mock(CommandSender.class); + + // when + command.executeCommand(sender, Collections.emptyList()); + + // then + String converters = String.join(", ", ConverterCommand.CONVERTERS.keySet()); + verify(sender).sendMessage(argThat(containsString(converters))); + verifyZeroInteractions(commonService, converterFactory, bukkitService); } @Test @@ -122,7 +135,7 @@ public class ConverterCommandTest { verifyNoMoreInteractions(converter); verify(converterFactory).newInstance(converterClass); verifyNoMoreInteractions(converterFactory); - verify(commandService).send(sender, MessageKey.ERROR); + verify(commonService).send(sender, MessageKey.ERROR); } private T createMockReturnedByInjector(Class clazz) {