Skip to content

Commit

Permalink
address feedback, added test for coordinator, and updated app process…
Browse files Browse the repository at this point in the history
…or to have better doc and improved code
  • Loading branch information
ezimet-livefront committed Nov 22, 2024
1 parent eb63475 commit 552ac90
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
18 changes: 18 additions & 0 deletions BitwardenShared/UI/Platform/Application/AppCoordinatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,24 @@ class AppCoordinatorTests: BitwardenTestCase { // swiftlint:disable:this type_bo
)
}

/// `handleEvent(_:)` with `.accountBecameActive` has the router handle account activation.
@MainActor
func test_handleEvent_accountBecameActive() async {
let account = Account.fixtureAccountLogin()
await subject.handleEvent(
.accountBecameActive(account, attemptAutomaticBiometricUnlock: true, didSwitchAccountAutomatically: true)
)
XCTAssertEqual(
router.events,
[.accountBecameActive(
account,
animated: true,
attemptAutomaticBiometricUnlock: true,
didSwitchAccountAutomatically: true
)]
)
}

/// `navigate(to:)` with `.onboarding` starts the auth coordinator and navigates to the proper auth route.
@MainActor
func test_navigateTo_auth() throws {
Expand Down
24 changes: 9 additions & 15 deletions BitwardenShared/UI/Platform/Application/AppProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -355,23 +355,17 @@ extension AppProcessor {
}
}

/// Handles the case where an session never timeout account becomes active.
/// Handles unlocking the vault for a manually locked account that uses never lock
/// and was previously unlocked in an extension.
///
private func handleNeverTimeOutAccountBecameActive() async {
// we should be safe to unlock the vault:
// - If not in the extension
// - If vault is locked
// - If the user uses never lock
// - If the user hasn't manually locked their vault (because it was unlocked in the extension).
guard appExtensionDelegate?.isInAppExtension != true else { return }
guard let account = try? await services.stateService.getActiveAccount() else { return }
guard services.vaultTimeoutService.isLocked(userId: account.profile.userId) else { return }
guard let sessionTimeout = try? await services.vaultTimeoutService.sessionTimeoutValue(
userId: account.profile.userId
), sessionTimeout == .never else { return }
guard let manuallyLocked = try? await services.stateService.getManuallyLockedAccount(
userId: account.profile.userId
), !manuallyLocked else { return }
guard
appExtensionDelegate?.isInAppExtension != true,
await (try? services.authRepository.isLocked()) == true,
await (try? services.authRepository.sessionTimeoutValue()) == .never,
await (try? services.stateService.getManuallyLockedAccount(userId: nil)) == false,
let account = try? await services.stateService.getActiveAccount()
else { return }

await coordinator?.handleEvent(
.accountBecameActive(
Expand Down

0 comments on commit 552ac90

Please sign in to comment.