app: migrate XkPasswd users to Diceware

This commit is contained in:
Harsh Shandilya 2021-12-21 01:42:42 +05:30
parent a0a8200393
commit 17860407f9
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
2 changed files with 39 additions and 0 deletions

View file

@ -25,6 +25,7 @@ fun runMigrations(filesDirPath: String, sharedPrefs: SharedPreferences, gitSetti
migrateToHideAll(sharedPrefs) migrateToHideAll(sharedPrefs)
migrateToSshKey(filesDirPath, sharedPrefs) migrateToSshKey(filesDirPath, sharedPrefs)
migrateToClipboardHistory(sharedPrefs) migrateToClipboardHistory(sharedPrefs)
migrateToDiceware(sharedPrefs)
} }
private fun migrateToGitUrlBasedConfig(sharedPrefs: SharedPreferences, gitSettings: GitSettings) { private fun migrateToGitUrlBasedConfig(sharedPrefs: SharedPreferences, gitSettings: GitSettings) {
@ -121,3 +122,13 @@ private fun migrateToClipboardHistory(sharedPrefs: SharedPreferences) {
} }
} }
} }
private fun migrateToDiceware(sharedPrefs: SharedPreferences) {
if (sharedPrefs.contains(PreferenceKeys.PREF_KEY_PWGEN_TYPE)) {
sharedPrefs.edit {
if (sharedPrefs.getString(PreferenceKeys.PREF_KEY_PWGEN_TYPE) == "xkpasswd") {
putString(PreferenceKeys.PREF_KEY_PWGEN_TYPE, "diceware")
}
}
}
}

View file

@ -155,4 +155,32 @@ class MigrationsTest {
assertEquals(true, sharedPrefs.getBoolean(PreferenceKeys.CLEAR_CLIPBOARD_HISTORY, false)) assertEquals(true, sharedPrefs.getBoolean(PreferenceKeys.CLEAR_CLIPBOARD_HISTORY, false))
assertFalse(sharedPrefs.contains(PreferenceKeys.CLEAR_CLIPBOARD_20X)) assertFalse(sharedPrefs.contains(PreferenceKeys.CLEAR_CLIPBOARD_20X))
} }
@Test
fun verifyClassicPasswordGeneratorMigration() {
sharedPrefs.edit {
clear()
putString(PreferenceKeys.PREF_KEY_PWGEN_TYPE, "classic")
}
runMigrations(
filesDir,
sharedPrefs,
GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir),
)
assertEquals("classic", sharedPrefs.getString(PreferenceKeys.PREF_KEY_PWGEN_TYPE))
}
@Test
fun verifyXkPasswdPasswordGeneratorMigration() {
sharedPrefs.edit {
clear()
putString(PreferenceKeys.PREF_KEY_PWGEN_TYPE, "xkpasswd")
}
runMigrations(
filesDir,
sharedPrefs,
GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir),
)
assertEquals("diceware", sharedPrefs.getString(PreferenceKeys.PREF_KEY_PWGEN_TYPE))
}
} }