From acc3e24d65eaa61736381d1e6428f9271dd088d9 Mon Sep 17 00:00:00 2001 From: Shamim Shahrier Emon Date: Thu, 22 Jan 2026 00:42:02 +0600 Subject: [PATCH] =?UTF-8?q?[PM-30664]=20Unlock=20with=20PIN=20doesn?= =?UTF-8?q?=E2=80=99t=20appear=20as=20enabled=20after=20enabling=20?= =?UTF-8?q?=E2=80=98Require=20master=20password=20on=20app=20restart?= =?UTF-8?q?=E2=80=99=20(#6344)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datasource/disk/AuthDiskSourceImpl.kt | 5 +++- .../datasource/disk/AuthDiskSourceTest.kt | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) 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 =