From 001a782a1991d072f1c3b6f6bc8a33806d8e3ea8 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Mon, 25 Feb 2019 21:28:15 +0100 Subject: [PATCH] Add test for set of deprecated algorithms --- .../executable/register/RegisterCommand.java | 8 ++++---- .../settings/SettingsMigrationService.java | 4 +++- .../SettingsMigrationServiceTest.java | 20 +++++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java b/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java index 1ce9ad740..56a1f62f8 100644 --- a/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java @@ -59,7 +59,7 @@ public class RegisterCommand extends PlayerCommand { // Check if we are migrating from old 2FA -> we reuse this method for simplicity but in reality if we match // this condition the user is already registered and we override the password with the given one if (limbo != null && limbo.getState() == LimboPlayerState.NEW_PASSWORD_FOR_TWO_FACTOR_MIGRATION_REQUIRED) { - handleNewPasswordInMigration(player, arguments); + handleNewPasswordFromTwoFactorMigration(player, arguments); return; } @@ -208,13 +208,13 @@ public class RegisterCommand extends PlayerCommand { } /** - * Handles the input arguments for a forced password migration. Two arguments are expected, password - * and password confirmation. + * Handles the input arguments for a forced password migration from the old two factor hash. + * Two arguments are expected, password and password confirmation. * * @param player the player * @param arguments the arguments supplied to the command */ - private void handleNewPasswordInMigration(Player player, List arguments) { + private void handleNewPasswordFromTwoFactorMigration(Player player, List arguments) { if (arguments.size() != 2) { player.sendMessage("Expected two arguments! /register "); } else if (!arguments.get(0).equals(arguments.get(1))) { diff --git a/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java b/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java index fc12534fb..59d4260eb 100644 --- a/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java +++ b/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java @@ -4,6 +4,7 @@ import ch.jalu.configme.configurationdata.ConfigurationData; import ch.jalu.configme.migration.PlainMigrationService; import ch.jalu.configme.properties.Property; import ch.jalu.configme.resource.PropertyReader; +import com.google.common.annotations.VisibleForTesting; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.output.LogLevel; @@ -51,7 +52,8 @@ public class SettingsMigrationService extends PlainMigrationService { * it will be moved into the "legacy hashes" property and the default will be used instead. * Note: do not add PLAINTEXT to this set as it is handled elsewhere (force-migration). */ - private static final EnumSet DEPRECATED_ARGUMENTS = + @VisibleForTesting + static final Set DEPRECATED_ARGUMENTS = EnumSet.of(DOUBLEMD5, MD5, SHA1, SHA512, TWO_FACTOR, WHIRLPOOL); private final File pluginFolder; diff --git a/src/test/java/fr/xephi/authme/settings/SettingsMigrationServiceTest.java b/src/test/java/fr/xephi/authme/settings/SettingsMigrationServiceTest.java index 021bfb93b..783df62da 100644 --- a/src/test/java/fr/xephi/authme/settings/SettingsMigrationServiceTest.java +++ b/src/test/java/fr/xephi/authme/settings/SettingsMigrationServiceTest.java @@ -19,9 +19,12 @@ import org.junit.rules.TemporaryFolder; import java.io.File; import java.io.IOException; +import java.lang.reflect.Field; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; +import java.util.Set; import static fr.xephi.authme.TestHelper.getJarFile; import static fr.xephi.authme.settings.properties.DatabaseSettings.MYSQL_COL_SALT; @@ -116,6 +119,23 @@ public class SettingsMigrationServiceTest { assertThat(migrationService.getOldOtherAccountsCommandThreshold(), equalTo(5)); } + @Test + public void shouldHaveDeprecatedEnumEntries() throws NoSuchFieldException { + // given + Set deprecatedEntries = EnumSet.noneOf(HashAlgorithm.class); + for (HashAlgorithm algorithm : HashAlgorithm.values()) { + if (algorithm != HashAlgorithm.PLAINTEXT) { + Field algorithmField = HashAlgorithm.class.getDeclaredField(algorithm.name()); + if (algorithmField.isAnnotationPresent(Deprecated.class)) { + deprecatedEntries.add(algorithm); + } + } + } + + // when / then + assertThat(SettingsMigrationService.DEPRECATED_ARGUMENTS, equalTo(deprecatedEntries)); + } + private void verifyHasUpToDateSettings(Settings settings, File dataFolder) throws IOException { assertThat(settings.getProperty(ALLOWED_NICKNAME_CHARACTERS), equalTo(ALLOWED_NICKNAME_CHARACTERS.getDefaultValue())); assertThat(settings.getProperty(DELAY_JOIN_MESSAGE), equalTo(true));