diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceImpl.kt b/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceImpl.kt index 27375bf45c..621b79070d 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceImpl.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceImpl.kt @@ -373,7 +373,10 @@ class AuthDiskSourceImpl( inMemoryOnly: Boolean, ) { inMemoryPinProtectedUserKeyEnvelopes[userId] = pinProtectedUserKeyEnvelope - if (inMemoryOnly) return + if (inMemoryOnly) { + getMutablePinProtectedUserKeyEnvelopeFlow(userId).tryEmit(pinProtectedUserKeyEnvelope) + return + } putString( key = PIN_PROTECTED_USER_KEY_KEY_ENVELOPE.appendIdentifier(userId), value = pinProtectedUserKeyEnvelope, diff --git a/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceTest.kt b/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceTest.kt index 52a0c91a44..45209dc0ae 100644 --- a/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceTest.kt +++ b/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceTest.kt @@ -865,6 +865,31 @@ class AuthDiskSourceTest { } } + @Test + @Suppress("MaxLineLength") + fun `storePinProtectedUserKeyEnvelope with inMemoryOnly true emits flow and stores only in memory`() = + runTest { + val userId = "mockUserId" + val envelope = "topSecretEnvelope" + + authDiskSource.getPinProtectedUserKeyEnvelopeFlow(userId).test { + assertNull(awaitItem()) + authDiskSource.storePinProtectedUserKeyEnvelope( + userId = userId, + pinProtectedUserKeyEnvelope = envelope, + inMemoryOnly = true, + ) + assertEquals(envelope, awaitItem()) + assertEquals(envelope, authDiskSource.getPinProtectedUserKeyEnvelope(userId)) + assertNull( + fakeSharedPreferences.getString( + "pinKeyEncryptedUserKeyEnvelope_$userId", + null, + ), + ) + } + } + @Test fun `getPinProtectedUserKeyEnvelope should pull from SharedPreferences`() { val pinProtectedUserKeyEnvelopeBaseKey =