mirror of
https://github.com/bitwarden/android.git
synced 2026-08-25 17:09:55 -05:00
[PM-32011] Add cookie callback flow to AuthRepository (#6510)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
31d480d6b4
commit
3be5bead89
@@ -34,6 +34,7 @@ import com.x8bit.bitwarden.data.auth.repository.model.ValidatePasswordResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.ValidatePinResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.VerifiedOrganizationDomainSsoDetailsResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.VerifyOtpResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.CookieCallbackResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.DuoCallbackTokenResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.SsoCallbackResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.WebAuthResult
|
||||
@@ -70,6 +71,12 @@ interface AuthRepository :
|
||||
*/
|
||||
val ssoCallbackResultFlow: Flow<SsoCallbackResult>
|
||||
|
||||
/**
|
||||
* Flow of the current [CookieCallbackResult]. Subscribers should listen to the flow in order
|
||||
* to receive updates whenever [setCookieCallbackResult] is called.
|
||||
*/
|
||||
val cookieCallbackResultFlow: Flow<CookieCallbackResult>
|
||||
|
||||
/**
|
||||
* Flow of the current [YubiKeyResult]. Subscribers should listen to the flow in order to
|
||||
* receive updates whenever [setYubiKeyResult] is called.
|
||||
@@ -342,6 +349,11 @@ interface AuthRepository :
|
||||
*/
|
||||
fun setSsoCallbackResult(result: SsoCallbackResult)
|
||||
|
||||
/**
|
||||
* Set the value of [cookieCallbackResultFlow].
|
||||
*/
|
||||
fun setCookieCallbackResult(result: CookieCallbackResult)
|
||||
|
||||
/**
|
||||
* Get a [Boolean] indicating whether this is a known device.
|
||||
*/
|
||||
|
||||
@@ -95,6 +95,7 @@ import com.x8bit.bitwarden.data.auth.repository.model.ValidatePinResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.VerifiedOrganizationDomainSsoDetailsResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.VerifyOtpResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.toLoginErrorResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.CookieCallbackResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.DuoCallbackTokenResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.SsoCallbackResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.WebAuthResult
|
||||
@@ -269,6 +270,10 @@ class AuthRepositoryImpl(
|
||||
override val ssoCallbackResultFlow: Flow<SsoCallbackResult> =
|
||||
mutableSsoCallbackResultFlow.asSharedFlow()
|
||||
|
||||
private val mutableCookieCallbackResultFlow = bufferedMutableSharedFlow<CookieCallbackResult>()
|
||||
override val cookieCallbackResultFlow: Flow<CookieCallbackResult> =
|
||||
mutableCookieCallbackResultFlow.asSharedFlow()
|
||||
|
||||
override var rememberedEmailAddress: String? by authDiskSource::rememberedEmailAddress
|
||||
|
||||
override var rememberedOrgIdentifier: String? by authDiskSource::rememberedOrgIdentifier
|
||||
@@ -1249,6 +1254,10 @@ class AuthRepositoryImpl(
|
||||
mutableSsoCallbackResultFlow.tryEmit(result)
|
||||
}
|
||||
|
||||
override fun setCookieCallbackResult(result: CookieCallbackResult) {
|
||||
mutableCookieCallbackResultFlow.tryEmit(result)
|
||||
}
|
||||
|
||||
override suspend fun getIsKnownDevice(emailAddress: String): KnownDeviceResult =
|
||||
devicesService
|
||||
.getIsKnownDevice(
|
||||
|
||||
@@ -119,6 +119,7 @@ import com.x8bit.bitwarden.data.auth.repository.model.ValidatePinResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.VerifiedOrganizationDomainSsoDetailsResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.VerifyOtpResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.createMockOrganization
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.CookieCallbackResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.DuoCallbackTokenResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.SsoCallbackResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.WebAuthResult
|
||||
@@ -6213,6 +6214,19 @@ class AuthRepositoryTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `setCookieCallbackResult should change the value of cookieCallbackResultFlow`() = runTest {
|
||||
repository.cookieCallbackResultFlow.test {
|
||||
repository.setCookieCallbackResult(
|
||||
CookieCallbackResult.Success(cookies = mapOf("test_cookie" to "test_value")),
|
||||
)
|
||||
assertEquals(
|
||||
CookieCallbackResult.Success(cookies = mapOf("test_cookie" to "test_value")),
|
||||
awaitItem(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `setYubiKeyResult should change the value of yubiKeyResultFlow`() = runTest {
|
||||
val yubiKeyResult = YubiKeyResult("mockk")
|
||||
|
||||
Reference in New Issue
Block a user