mirror of
https://github.com/bitwarden/android.git
synced 2025-12-10 09:56:45 -06:00
PM-20593: sync-org-keys notification should allow token to be refreshed on next request (#5988)
This commit is contained in:
parent
10a92dd2a3
commit
bebf94796c
@ -302,9 +302,14 @@ class AuthRepositoryImpl(
|
|||||||
pushManager
|
pushManager
|
||||||
.syncOrgKeysFlow
|
.syncOrgKeysFlow
|
||||||
.onEach { userId ->
|
.onEach { userId ->
|
||||||
|
// This will force the next authenticated request to refresh the auth token.
|
||||||
|
authDiskSource.storeAccountTokens(
|
||||||
|
userId = userId,
|
||||||
|
accountTokens = authDiskSource
|
||||||
|
.getAccountTokens(userId = userId)
|
||||||
|
?.copy(expiresAtSec = 0L),
|
||||||
|
)
|
||||||
if (userId == activeUserId) {
|
if (userId == activeUserId) {
|
||||||
// TODO: [PM-20593] Investigate why tokens are explicitly refreshed.
|
|
||||||
refreshAccessTokenSynchronously(userId = userId)
|
|
||||||
// We just sync now to get the latest data
|
// We just sync now to get the latest data
|
||||||
vaultRepository.sync(forced = true)
|
vaultRepository.sync(forced = true)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -6439,34 +6439,39 @@ class AuthRepositoryTest {
|
|||||||
fun `syncOrgKeysFlow emissions for active user should refresh access token and force sync`() {
|
fun `syncOrgKeysFlow emissions for active user should refresh access token and force sync`() {
|
||||||
fakeAuthDiskSource.userState = MULTI_USER_STATE
|
fakeAuthDiskSource.userState = MULTI_USER_STATE
|
||||||
fakeAuthDiskSource.storeAccountTokens(userId = USER_ID_1, accountTokens = ACCOUNT_TOKENS_1)
|
fakeAuthDiskSource.storeAccountTokens(userId = USER_ID_1, accountTokens = ACCOUNT_TOKENS_1)
|
||||||
coEvery {
|
every { vaultRepository.sync(forced = true) } just runs
|
||||||
identityService.refreshTokenSynchronously(REFRESH_TOKEN)
|
|
||||||
} returns REFRESH_TOKEN_RESPONSE_JSON.asSuccess()
|
|
||||||
coEvery { vaultRepository.sync(forced = true) } just runs
|
|
||||||
|
|
||||||
mutableSyncOrgKeysFlow.tryEmit(USER_ID_1)
|
mutableSyncOrgKeysFlow.tryEmit(USER_ID_1)
|
||||||
|
|
||||||
coVerify(exactly = 1) {
|
verify(exactly = 1) {
|
||||||
identityService.refreshTokenSynchronously(REFRESH_TOKEN)
|
|
||||||
vaultRepository.sync(forced = true)
|
vaultRepository.sync(forced = true)
|
||||||
}
|
}
|
||||||
|
fakeAuthDiskSource.assertAccountTokens(
|
||||||
|
userId = USER_ID_1,
|
||||||
|
accountTokens = ACCOUNT_TOKENS_1.copy(expiresAtSec = 0L),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `syncOrgKeysFlow emissions for inactive user should clear the last sync time`() {
|
fun `syncOrgKeysFlow emissions for inactive user should clear the last sync time`() {
|
||||||
fakeAuthDiskSource.userState = MULTI_USER_STATE
|
fakeAuthDiskSource.userState = MULTI_USER_STATE
|
||||||
|
fakeAuthDiskSource.storeAccountTokens(userId = USER_ID_2, accountTokens = ACCOUNT_TOKENS_2)
|
||||||
fakeSettingsDiskSource.storeLastSyncTime(
|
fakeSettingsDiskSource.storeLastSyncTime(
|
||||||
userId = USER_ID_2,
|
userId = USER_ID_2,
|
||||||
lastSyncTime = FIXED_CLOCK.instant(),
|
lastSyncTime = FIXED_CLOCK.instant(),
|
||||||
)
|
)
|
||||||
|
every { vaultRepository.sync(forced = true) } just runs
|
||||||
|
|
||||||
mutableSyncOrgKeysFlow.tryEmit(USER_ID_2)
|
mutableSyncOrgKeysFlow.tryEmit(USER_ID_2)
|
||||||
|
|
||||||
coVerify(exactly = 0) {
|
verify(exactly = 0) {
|
||||||
identityService.refreshTokenSynchronously(REFRESH_TOKEN)
|
|
||||||
vaultRepository.sync(forced = true)
|
vaultRepository.sync(forced = true)
|
||||||
}
|
}
|
||||||
fakeSettingsDiskSource.assertLastSyncTime(userId = USER_ID_2, null)
|
fakeSettingsDiskSource.assertLastSyncTime(userId = USER_ID_2, null)
|
||||||
|
fakeAuthDiskSource.assertAccountTokens(
|
||||||
|
userId = USER_ID_2,
|
||||||
|
accountTokens = ACCOUNT_TOKENS_2.copy(expiresAtSec = 0L),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user