1
0
Fork 0

Add override for Core val in test

master
ekager 2019-11-14 08:23:15 -08:00 committed by Emily Kager
parent 6e907b1106
commit d85ed27a3d
3 changed files with 7 additions and 7 deletions

View File

@ -21,7 +21,7 @@ class Components(private val context: Context) {
core.historyStorage,
core.bookmarksStorage,
core.passwordsStorage,
core.secureAbove22Preferences
core.getSecureAbove22Preferences()
)
}
val services by lazy { Services(context, backgroundServices.accountManager) }

View File

@ -191,19 +191,17 @@ class Core(private val context: Context) {
* Shared Preferences that encrypt/decrypt using Android KeyStore and lib-dataprotect for 23+
* otherwise simply stored
*/
val secureAbove22Preferences by lazy {
SecureAbove22Preferences(context, KEY_STORAGE_NAME)
}
fun getSecureAbove22Preferences() = SecureAbove22Preferences(context, KEY_STORAGE_NAME)
private val passwordsEncryptionKey =
secureAbove22Preferences.getString(PASSWORDS_KEY)
private val passwordsEncryptionKey: String =
getSecureAbove22Preferences().getString(PASSWORDS_KEY)
?: generateEncryptionKey(KEY_STRENGTH).also {
if (context.settings().passwordsEncryptionKeyGenerated) {
// We already had previously generated an encryption key, but we have lost it
Sentry.capture("Passwords encryption key for passwords storage was lost and we generated a new one")
}
context.settings().recordPasswordsEncryptionKeyGenerated()
secureAbove22Preferences.putString(PASSWORDS_KEY, it)
getSecureAbove22Preferences().putString(PASSWORDS_KEY, it)
}
/**

View File

@ -10,6 +10,7 @@ import mozilla.components.browser.engine.gecko.GeckoEngine
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.feature.pwa.WebAppShortcutManager
import mozilla.components.lib.dataprotect.SecureAbove22Preferences
class TestCore(context: Context) : Core(context) {
@ -17,4 +18,5 @@ class TestCore(context: Context) : Core(context) {
override val sessionManager = SessionManager(engine)
override val store = mockk<BrowserStore>()
override val webAppShortcutManager = mockk<WebAppShortcutManager>()
override fun getSecureAbove22Preferences() = mockk<SecureAbove22Preferences>(relaxed = true)
}