mirror of
https://github.com/bitwarden/android.git
synced 2024-11-21 17:05:44 +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].
|
||||
*/
|
||||
@Suppress("TooManyFunctions")
|
||||
@Singleton
|
||||
class AuthRequestManagerImpl(
|
||||
private val clock: Clock,
|
||||
|
@ -106,6 +107,7 @@ class AuthRequestManagerImpl(
|
|||
onSuccess = { updateAuthRequest ->
|
||||
when {
|
||||
updateAuthRequest.requestApproved -> {
|
||||
clearPendingAuthRequest()
|
||||
isComplete = true
|
||||
emit(
|
||||
CreateAuthRequestResult.Success(
|
||||
|
@ -117,6 +119,7 @@ class AuthRequestManagerImpl(
|
|||
|
||||
!updateAuthRequest.requestApproved &&
|
||||
updateAuthRequest.responseDate != null -> {
|
||||
clearPendingAuthRequest()
|
||||
isComplete = true
|
||||
emit(CreateAuthRequestResult.Declined)
|
||||
}
|
||||
|
@ -126,6 +129,7 @@ class AuthRequestManagerImpl(
|
|||
.toInstant()
|
||||
.plusMillis(PASSWORDLESS_NOTIFICATION_TIMEOUT_MILLIS)
|
||||
.isBefore(clock.instant()) -> {
|
||||
clearPendingAuthRequest()
|
||||
isComplete = true
|
||||
emit(CreateAuthRequestResult.Expired)
|
||||
}
|
||||
|
@ -140,6 +144,15 @@ class AuthRequestManagerImpl(
|
|||
}
|
||||
}
|
||||
|
||||
private fun clearPendingAuthRequest() {
|
||||
activeUserId?.let {
|
||||
authDiskSource.storePendingAuthRequest(
|
||||
userId = it,
|
||||
pendingAuthRequest = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAuthRequest(
|
||||
initialRequest: suspend () -> AuthRequestUpdatesResult,
|
||||
): Flow<AuthRequestUpdatesResult> = flow {
|
||||
|
|
|
@ -300,16 +300,20 @@ class AuthRequestManagerTest {
|
|||
)
|
||||
.test {
|
||||
assertEquals(CreateAuthRequestResult.Update(authRequest), awaitItem())
|
||||
fakeAuthDiskSource.assertPendingAuthRequest(
|
||||
userId = USER_ID,
|
||||
pendingAuthRequest = PendingAuthRequestJson(
|
||||
requestId = authRequestResponseJson.id,
|
||||
requestPrivateKey = authRequestResponse.privateKey,
|
||||
),
|
||||
)
|
||||
assertEquals(CreateAuthRequestResult.Expired, awaitItem())
|
||||
fakeAuthDiskSource.assertPendingAuthRequest(
|
||||
userId = USER_ID,
|
||||
pendingAuthRequest = null,
|
||||
)
|
||||
awaitComplete()
|
||||
}
|
||||
fakeAuthDiskSource.assertPendingAuthRequest(
|
||||
userId = USER_ID,
|
||||
pendingAuthRequest = PendingAuthRequestJson(
|
||||
requestId = authRequestResponseJson.id,
|
||||
requestPrivateKey = authRequestResponse.privateKey,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
|
|
Loading…
Reference in a new issue