mirror of
https://github.com/bitwarden/android.git
synced 2025-03-15 18:58:59 +03:00
Ensure user/private key storage is backwards compatible (#368)
This commit is contained in:
parent
e3a0832777
commit
436c567b3f
2 changed files with 10 additions and 6 deletions
|
@ -14,8 +14,8 @@ import java.util.UUID
|
|||
private const val UNIQUE_APP_ID_KEY = "$BASE_KEY:appId"
|
||||
private const val REMEMBERED_EMAIL_ADDRESS_KEY = "$BASE_KEY:rememberedEmail"
|
||||
private const val STATE_KEY = "$BASE_KEY:state"
|
||||
private const val MASTER_KEY_ENCRYPTION_USER_KEY = "masterKeyEncryptedUserKey"
|
||||
private const val MASTER_KEY_ENCRYPTION_PRIVATE_KEY = "encPrivateKey"
|
||||
private const val MASTER_KEY_ENCRYPTION_USER_KEY = "$BASE_KEY:masterKeyEncryptedUserKey"
|
||||
private const val MASTER_KEY_ENCRYPTION_PRIVATE_KEY = "$BASE_KEY:encPrivateKey"
|
||||
|
||||
/**
|
||||
* Primary implementation of [AuthDiskSource].
|
||||
|
|
|
@ -118,12 +118,13 @@ class AuthDiskSourceTest {
|
|||
|
||||
@Test
|
||||
fun `getUserKey should pull from SharedPreferences`() {
|
||||
val userKeyBaseKey = "bwPreferencesStorage:masterKeyEncryptedUserKey"
|
||||
val mockUserId = "mockUserId"
|
||||
val mockUserKey = "mockUserKey"
|
||||
fakeSharedPreferences
|
||||
.edit()
|
||||
.putString(
|
||||
"masterKeyEncryptedUserKey_$mockUserId",
|
||||
"${userKeyBaseKey}_$mockUserId",
|
||||
mockUserKey,
|
||||
)
|
||||
.apply()
|
||||
|
@ -136,6 +137,7 @@ class AuthDiskSourceTest {
|
|||
|
||||
@Test
|
||||
fun `storeUserKey should update SharedPreferences`() {
|
||||
val userKeyBaseKey = "bwPreferencesStorage:masterKeyEncryptedUserKey"
|
||||
val mockUserId = "mockUserId"
|
||||
val mockUserKey = "mockUserKey"
|
||||
authDiskSource.storeUserKey(
|
||||
|
@ -144,7 +146,7 @@ class AuthDiskSourceTest {
|
|||
)
|
||||
val actual = fakeSharedPreferences
|
||||
.getString(
|
||||
"masterKeyEncryptedUserKey_$mockUserId",
|
||||
"${userKeyBaseKey}_$mockUserId",
|
||||
null,
|
||||
)
|
||||
assertEquals(
|
||||
|
@ -155,12 +157,13 @@ class AuthDiskSourceTest {
|
|||
|
||||
@Test
|
||||
fun `getPrivateKey should pull from SharedPreferences`() {
|
||||
val privateKeyBaseKey = "bwPreferencesStorage:encPrivateKey"
|
||||
val mockUserId = "mockUserId"
|
||||
val mockPrivateKey = "mockPrivateKey"
|
||||
fakeSharedPreferences
|
||||
.edit()
|
||||
.putString(
|
||||
"encPrivateKey_$mockUserId",
|
||||
"${privateKeyBaseKey}_$mockUserId",
|
||||
mockPrivateKey,
|
||||
)
|
||||
.apply()
|
||||
|
@ -173,6 +176,7 @@ class AuthDiskSourceTest {
|
|||
|
||||
@Test
|
||||
fun `storePrivateKey should update SharedPreferences`() {
|
||||
val privateKeyBaseKey = "bwPreferencesStorage:encPrivateKey"
|
||||
val mockUserId = "mockUserId"
|
||||
val mockPrivateKey = "mockPrivateKey"
|
||||
authDiskSource.storePrivateKey(
|
||||
|
@ -180,7 +184,7 @@ class AuthDiskSourceTest {
|
|||
privateKey = mockPrivateKey,
|
||||
)
|
||||
val actual = fakeSharedPreferences.getString(
|
||||
"encPrivateKey_$mockUserId",
|
||||
"${privateKeyBaseKey}_$mockUserId",
|
||||
null,
|
||||
)
|
||||
assertEquals(
|
||||
|
|
Loading…
Add table
Reference in a new issue