Add test for set of deprecated algorithms

This commit is contained in:
ljacqu 2019-02-25 21:28:15 +01:00
parent 72411d884c
commit 001a782a19
3 changed files with 27 additions and 5 deletions

View File

@ -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 // 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 // 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) { if (limbo != null && limbo.getState() == LimboPlayerState.NEW_PASSWORD_FOR_TWO_FACTOR_MIGRATION_REQUIRED) {
handleNewPasswordInMigration(player, arguments); handleNewPasswordFromTwoFactorMigration(player, arguments);
return; return;
} }
@ -208,13 +208,13 @@ public class RegisterCommand extends PlayerCommand {
} }
/** /**
* Handles the input arguments for a forced password migration. Two arguments are expected, password * Handles the input arguments for a forced password migration from the old two factor hash.
* and password confirmation. * Two arguments are expected, password and password confirmation.
* *
* @param player the player * @param player the player
* @param arguments the arguments supplied to the command * @param arguments the arguments supplied to the command
*/ */
private void handleNewPasswordInMigration(Player player, List<String> arguments) { private void handleNewPasswordFromTwoFactorMigration(Player player, List<String> arguments) {
if (arguments.size() != 2) { if (arguments.size() != 2) {
player.sendMessage("Expected two arguments! /register <password> <confirmPassword>"); player.sendMessage("Expected two arguments! /register <password> <confirmPassword>");
} else if (!arguments.get(0).equals(arguments.get(1))) { } else if (!arguments.get(0).equals(arguments.get(1))) {

View File

@ -4,6 +4,7 @@ import ch.jalu.configme.configurationdata.ConfigurationData;
import ch.jalu.configme.migration.PlainMigrationService; import ch.jalu.configme.migration.PlainMigrationService;
import ch.jalu.configme.properties.Property; import ch.jalu.configme.properties.Property;
import ch.jalu.configme.resource.PropertyReader; import ch.jalu.configme.resource.PropertyReader;
import com.google.common.annotations.VisibleForTesting;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.initialization.DataFolder;
import fr.xephi.authme.output.LogLevel; 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. * 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). * Note: do not add PLAINTEXT to this set as it is handled elsewhere (force-migration).
*/ */
private static final EnumSet<HashAlgorithm> DEPRECATED_ARGUMENTS = @VisibleForTesting
static final Set<HashAlgorithm> DEPRECATED_ARGUMENTS =
EnumSet.of(DOUBLEMD5, MD5, SHA1, SHA512, TWO_FACTOR, WHIRLPOOL); EnumSet.of(DOUBLEMD5, MD5, SHA1, SHA512, TWO_FACTOR, WHIRLPOOL);
private final File pluginFolder; private final File pluginFolder;

View File

@ -19,9 +19,12 @@ import org.junit.rules.TemporaryFolder;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Set;
import static fr.xephi.authme.TestHelper.getJarFile; import static fr.xephi.authme.TestHelper.getJarFile;
import static fr.xephi.authme.settings.properties.DatabaseSettings.MYSQL_COL_SALT; import static fr.xephi.authme.settings.properties.DatabaseSettings.MYSQL_COL_SALT;
@ -116,6 +119,23 @@ public class SettingsMigrationServiceTest {
assertThat(migrationService.getOldOtherAccountsCommandThreshold(), equalTo(5)); assertThat(migrationService.getOldOtherAccountsCommandThreshold(), equalTo(5));
} }
@Test
public void shouldHaveDeprecatedEnumEntries() throws NoSuchFieldException {
// given
Set<HashAlgorithm> 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 { private void verifyHasUpToDateSettings(Settings settings, File dataFolder) throws IOException {
assertThat(settings.getProperty(ALLOWED_NICKNAME_CHARACTERS), equalTo(ALLOWED_NICKNAME_CHARACTERS.getDefaultValue())); assertThat(settings.getProperty(ALLOWED_NICKNAME_CHARACTERS), equalTo(ALLOWED_NICKNAME_CHARACTERS.getDefaultValue()));
assertThat(settings.getProperty(DELAY_JOIN_MESSAGE), equalTo(true)); assertThat(settings.getProperty(DELAY_JOIN_MESSAGE), equalTo(true));