Skip to content

Commit 59f184b

Browse files
PM-9003: Fix never lock with logout action error (#724)
1 parent d2c0a47 commit 59f184b

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

BitwardenShared/Core/Auth/Repositories/TestHelpers/MockAuthRepository.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class MockAuthRepository: AuthRepository { // swiftlint:disable:this type_body_l
5757
var unlockVaultResult: Result<Void, Error> = .success(())
5858
var unlockVaultWithBiometricsResult: Result<Void, Error> = .success(())
5959
var unlockVaultWithDeviceKeyResult: Result<Void, Error> = .success(())
60+
var unlockVaultWithNeverlockKeyCalled = false
6061
var unlockVaultWithNeverlockResult: Result<Void, Error> = .success(())
6162
var verifyOtpOpt: String?
6263
var verifyOtpResult: Result<Void, Error> = .success(())
@@ -266,7 +267,8 @@ class MockAuthRepository: AuthRepository { // swiftlint:disable:this type_body_l
266267
}
267268

268269
func unlockVaultWithNeverlockKey() async throws {
269-
try unlockVaultWithNeverlockResult.get()
270+
unlockVaultWithNeverlockKeyCalled = true
271+
return try unlockVaultWithNeverlockResult.get()
270272
}
271273

272274
/// Attempts to convert a possible user id into a known account id.

BitwardenShared/UI/Auth/AuthRouterTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,20 @@ final class AuthRouterTests: BitwardenTestCase { // swiftlint:disable:this type_
711711
)
712712
}
713713

714+
/// `handleAndRoute(_ :)` redirects `.didStart` to `.complete` and unlocks the vault if the
715+
/// account never times out with a logout timeout action.
716+
func test_handleAndRoute_didStart_neverLockLogout() async {
717+
let account = Account.fixtureAccountLogin()
718+
authRepository.activeAccount = account
719+
authRepository.sessionTimeoutAction[account.profile.userId] = .logout
720+
vaultTimeoutService.vaultTimeout[account.profile.userId] = .never
721+
722+
let route = await subject.handleAndRoute(.didStart)
723+
724+
XCTAssertEqual(route, .complete)
725+
XCTAssertTrue(authRepository.unlockVaultWithNeverlockKeyCalled)
726+
}
727+
714728
/// `handleAndRoute(_ :)` redirects `.didStart` to `.landing`
715729
/// when there are no accounts.
716730
func test_handleAndRoute_didStart_noAccounts() async {

BitwardenShared/UI/Auth/Extensions/AuthRouter+Redirects.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ extension AuthRouter {
209209
}
210210

211211
// Check for a `logout` timeout action.
212-
let timeoutAction = try? await services.authRepository
213-
.sessionTimeoutAction(userId: activeAccount.profile.userId)
214-
if timeoutAction == .logout {
212+
let userId = activeAccount.profile.userId
213+
if await (try? services.authRepository.sessionTimeoutAction(userId: userId)) == .logout,
214+
await (try? services.vaultTimeoutService.sessionTimeoutValue(userId: userId)) != .never {
215215
return await handleAndRoute(.didTimeout(userId: activeAccount.profile.userId))
216216
}
217217

BitwardenShared/UI/Platform/Application/Extensions/UITabBarControllerExtensionsTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import XCTest
33

44
@testable import BitwardenShared
55

6-
// MARK: - UITabBarControllerTests
6+
// MARK: - UITabBarControllerExtensionsTests
77

8-
class UITabBarControllerTests: BitwardenTestCase {
8+
class UITabBarControllerExtensionsTests: BitwardenTestCase {
99
var module: MockAppModule!
1010
var coordinator: TabCoordinator!
1111
var rootNavigator: MockRootNavigator!

0 commit comments

Comments
 (0)