Fix AuthMe thinking config needs a migration

- Old, deprecated property now exists again -> stop checking for its presence as a reason for migration
- Create test for SettingsMigrationService to detect such issues in the future
This commit is contained in:
ljacqu 2016-02-13 12:35:33 +01:00
parent 84741e2882
commit 432ed4620c
2 changed files with 68 additions and 5 deletions

View File

@ -49,11 +49,9 @@ public final class SettingsMigrationService {
// Note ljacqu 20160211: Concatenating migration methods with | instead of the usual ||
// ensures that all migrations will be performed
changes = changes
return changes
| performMailTextToFileMigration(configuration, pluginFolder)
| migrateJoinLeaveMessages(configuration);
return changes;
}
@VisibleForTesting
@ -69,8 +67,7 @@ public final class SettingsMigrationService {
private static boolean hasDeprecatedProperties(FileConfiguration configuration) {
String[] deprecatedProperties = {
"Converter.Rakamak.newPasswordHash", "Hooks.chestshop", "Hooks.legacyChestshop", "Hooks.notifications",
"Passpartu", "Performances", "settings.delayJoinMessage", "settings.restrictions.enablePasswordVerifier",
"Xenoforo.predefinedSalt"};
"Passpartu", "Performances", "settings.restrictions.enablePasswordVerifier", "Xenoforo.predefinedSalt"};
for (String deprecatedPath : deprecatedProperties) {
if (configuration.contains(deprecatedPath)) {
return true;

View File

@ -0,0 +1,66 @@
package fr.xephi.authme.settings;
import com.google.common.io.Files;
import fr.xephi.authme.TestHelper;
import fr.xephi.authme.settings.properties.SettingsFieldRetriever;
import fr.xephi.authme.settings.propertymap.PropertyMap;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.IOException;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assume.assumeThat;
/**
* Test for {@link SettingsMigrationService}.
*/
public class SettingsMigrationServiceTest {
@Rule
public TemporaryFolder testFolderHandler = new TemporaryFolder();
private File testFolder;
private File configTestFile;
/**
* Ensure that AuthMe regards the JAR's own config.yml as complete.
* If something legitimately needs migrating, a test from {@link ConfigFileConsistencyTest} should fail.
* If none fails in that class, it means something is wrong with the migration service
* as it wants to perform a migration on our up-to-date config.yml.
*/
@Test
public void shouldNotRewriteJarConfig() throws IOException {
// given
copyConfigToTestFolder();
FileConfiguration configuration = YamlConfiguration.loadConfiguration(configTestFile);
PropertyMap propertyMap = SettingsFieldRetriever.getAllPropertyFields();
assumeThat(testFolder.listFiles(), arrayWithSize(1));
// when
boolean result = SettingsMigrationService.checkAndMigrate(configuration, propertyMap, testFolder);
// then
assertThat(result, equalTo(false));
assertThat(testFolder.listFiles(), arrayWithSize(1));
}
private void copyConfigToTestFolder() throws IOException {
testFolder = testFolderHandler.newFolder("migrationtest");
final File testConfig = testFolderHandler.newFile("migrationtest/config.yml");
final File realConfig = TestHelper.getJarFile("/config.yml");
Files.copy(realConfig, testConfig);
if (!testConfig.exists()) {
throw new IOException("Could not copy project's config.yml to test folder");
}
configTestFile = testConfig;
}
}