BIT-2256: Clear pending admin request when request is completed (#1284)

This commit is contained in:
David Perez 2024-04-17 16:58:57 -05:00 committed by Álison Fernandes
parent e69ef60f53
commit 4ac9d05036
2 changed files with 24 additions and 7 deletions

View file

@ -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 {

View file

@ -300,9 +300,6 @@ class AuthRequestManagerTest {
)
.test {
assertEquals(CreateAuthRequestResult.Update(authRequest), awaitItem())
assertEquals(CreateAuthRequestResult.Expired, awaitItem())
awaitComplete()
}
fakeAuthDiskSource.assertPendingAuthRequest(
userId = USER_ID,
pendingAuthRequest = PendingAuthRequestJson(
@ -310,6 +307,13 @@ class AuthRequestManagerTest {
requestPrivateKey = authRequestResponse.privateKey,
),
)
assertEquals(CreateAuthRequestResult.Expired, awaitItem())
fakeAuthDiskSource.assertPendingAuthRequest(
userId = USER_ID,
pendingAuthRequest = null,
)
awaitComplete()
}
}
@Suppress("MaxLineLength")