mirror of
https://github.com/bitwarden/android.git
synced 2025-02-17 20:40:00 +03:00
BIT-2256: Clear pending admin request when request is completed (#1284)
This commit is contained in:
parent
e69ef60f53
commit
4ac9d05036
2 changed files with 24 additions and 7 deletions
|
@ -35,6 +35,7 @@ private const val PASSWORDLESS_APPROVER_INTERVAL_MILLIS: Long = 5L * 60L * 1_000
|
||||||
/**
|
/**
|
||||||
* Default implementation of [AuthRequestManager].
|
* Default implementation of [AuthRequestManager].
|
||||||
*/
|
*/
|
||||||
|
@Suppress("TooManyFunctions")
|
||||||
@Singleton
|
@Singleton
|
||||||
class AuthRequestManagerImpl(
|
class AuthRequestManagerImpl(
|
||||||
private val clock: Clock,
|
private val clock: Clock,
|
||||||
|
@ -106,6 +107,7 @@ class AuthRequestManagerImpl(
|
||||||
onSuccess = { updateAuthRequest ->
|
onSuccess = { updateAuthRequest ->
|
||||||
when {
|
when {
|
||||||
updateAuthRequest.requestApproved -> {
|
updateAuthRequest.requestApproved -> {
|
||||||
|
clearPendingAuthRequest()
|
||||||
isComplete = true
|
isComplete = true
|
||||||
emit(
|
emit(
|
||||||
CreateAuthRequestResult.Success(
|
CreateAuthRequestResult.Success(
|
||||||
|
@ -117,6 +119,7 @@ class AuthRequestManagerImpl(
|
||||||
|
|
||||||
!updateAuthRequest.requestApproved &&
|
!updateAuthRequest.requestApproved &&
|
||||||
updateAuthRequest.responseDate != null -> {
|
updateAuthRequest.responseDate != null -> {
|
||||||
|
clearPendingAuthRequest()
|
||||||
isComplete = true
|
isComplete = true
|
||||||
emit(CreateAuthRequestResult.Declined)
|
emit(CreateAuthRequestResult.Declined)
|
||||||
}
|
}
|
||||||
|
@ -126,6 +129,7 @@ class AuthRequestManagerImpl(
|
||||||
.toInstant()
|
.toInstant()
|
||||||
.plusMillis(PASSWORDLESS_NOTIFICATION_TIMEOUT_MILLIS)
|
.plusMillis(PASSWORDLESS_NOTIFICATION_TIMEOUT_MILLIS)
|
||||||
.isBefore(clock.instant()) -> {
|
.isBefore(clock.instant()) -> {
|
||||||
|
clearPendingAuthRequest()
|
||||||
isComplete = true
|
isComplete = true
|
||||||
emit(CreateAuthRequestResult.Expired)
|
emit(CreateAuthRequestResult.Expired)
|
||||||
}
|
}
|
||||||
|
@ -140,6 +144,15 @@ class AuthRequestManagerImpl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun clearPendingAuthRequest() {
|
||||||
|
activeUserId?.let {
|
||||||
|
authDiskSource.storePendingAuthRequest(
|
||||||
|
userId = it,
|
||||||
|
pendingAuthRequest = null,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getAuthRequest(
|
private fun getAuthRequest(
|
||||||
initialRequest: suspend () -> AuthRequestUpdatesResult,
|
initialRequest: suspend () -> AuthRequestUpdatesResult,
|
||||||
): Flow<AuthRequestUpdatesResult> = flow {
|
): Flow<AuthRequestUpdatesResult> = flow {
|
||||||
|
|
|
@ -300,9 +300,6 @@ class AuthRequestManagerTest {
|
||||||
)
|
)
|
||||||
.test {
|
.test {
|
||||||
assertEquals(CreateAuthRequestResult.Update(authRequest), awaitItem())
|
assertEquals(CreateAuthRequestResult.Update(authRequest), awaitItem())
|
||||||
assertEquals(CreateAuthRequestResult.Expired, awaitItem())
|
|
||||||
awaitComplete()
|
|
||||||
}
|
|
||||||
fakeAuthDiskSource.assertPendingAuthRequest(
|
fakeAuthDiskSource.assertPendingAuthRequest(
|
||||||
userId = USER_ID,
|
userId = USER_ID,
|
||||||
pendingAuthRequest = PendingAuthRequestJson(
|
pendingAuthRequest = PendingAuthRequestJson(
|
||||||
|
@ -310,6 +307,13 @@ class AuthRequestManagerTest {
|
||||||
requestPrivateKey = authRequestResponse.privateKey,
|
requestPrivateKey = authRequestResponse.privateKey,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
assertEquals(CreateAuthRequestResult.Expired, awaitItem())
|
||||||
|
fakeAuthDiskSource.assertPendingAuthRequest(
|
||||||
|
userId = USER_ID,
|
||||||
|
pendingAuthRequest = null,
|
||||||
|
)
|
||||||
|
awaitComplete()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
@Suppress("MaxLineLength")
|
||||||
|
|
Loading…
Add table
Reference in a new issue