From 17860407f9451b3ac90caa1fc20a10cfd4c44489 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Tue, 21 Dec 2021 01:42:42 +0530 Subject: app: migrate XkPasswd users to Diceware --- .../dev/msfjarvis/aps/util/settings/Migrations.kt | 11 +++++++++ .../msfjarvis/aps/util/settings/MigrationsTest.kt | 28 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/app/src/main/java/dev/msfjarvis/aps/util/settings/Migrations.kt b/app/src/main/java/dev/msfjarvis/aps/util/settings/Migrations.kt index c001091d..5d61e75b 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/settings/Migrations.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/settings/Migrations.kt @@ -25,6 +25,7 @@ fun runMigrations(filesDirPath: String, sharedPrefs: SharedPreferences, gitSetti migrateToHideAll(sharedPrefs) migrateToSshKey(filesDirPath, sharedPrefs) migrateToClipboardHistory(sharedPrefs) + migrateToDiceware(sharedPrefs) } 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") + } + } + } +} diff --git a/app/src/test/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt b/app/src/test/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt index c37eb626..d279ab03 100644 --- a/app/src/test/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt +++ b/app/src/test/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt @@ -155,4 +155,32 @@ class MigrationsTest { assertEquals(true, sharedPrefs.getBoolean(PreferenceKeys.CLEAR_CLIPBOARD_HISTORY, false)) 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)) + } } -- cgit v1.2.3