From 759d524bef512052b12775bcc7d2419e0b252267 Mon Sep 17 00:00:00 2001 From: Phil Cappelli <150719757+phil-livefront@users.noreply.github.com> Date: Thu, 24 Oct 2024 13:28:01 -0400 Subject: [PATCH] PM-13856 - After enabling Autofill in Device Settings, user is stuck in a loop/does not see the all set screen (#1074) --- BitwardenShared/UI/Auth/AuthRouterTests.swift | 34 +++++++++++++++++++ .../Extensions/AuthRouter+Redirects.swift | 19 +++++++---- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/BitwardenShared/UI/Auth/AuthRouterTests.swift b/BitwardenShared/UI/Auth/AuthRouterTests.swift index 2dd403c82..22cbdc9fa 100644 --- a/BitwardenShared/UI/Auth/AuthRouterTests.swift +++ b/BitwardenShared/UI/Auth/AuthRouterTests.swift @@ -196,6 +196,23 @@ final class AuthRouterTests: BitwardenTestCase { // swiftlint:disable:this type_ XCTAssertEqual(route, .autofillSetup) } + /// `handleAndRoute(_:)` redirects `.didCompleteAuth` to `.complete` if the user still + /// needs to set up autofill but is within the app extension. + @MainActor + func test_handleAndRoute_didCompleteAuth_incompleteAutofill_withinAppExtension() async { + subject = AuthRouter( + isInAppExtension: true, + services: ServiceContainer.withMocks( + authRepository: authRepository + ) + ) + authRepository.activeAccount = .fixture() + stateService.activeAccount = .fixture() + stateService.accountSetupAutofill["1"] = .incomplete + let route = await subject.handleAndRoute(.didCompleteAuth) + XCTAssertEqual(route, .complete) + } + /// `handleAndRoute(_:)` redirects `.didCompleteAuth` to `.vaultUnlockSetup` if the user still /// needs to set up a vault unlock method. func test_handleAndRoute_didCompleteAuth_incompleteVaultSetup() async { @@ -206,6 +223,23 @@ final class AuthRouterTests: BitwardenTestCase { // swiftlint:disable:this type_ XCTAssertEqual(route, .vaultUnlockSetup(.createAccount)) } + /// `handleAndRoute(_:)` redirects `.didCompleteAuth` to `.complete` if the user still + /// needs to set up a vault unlock method but is within the app extension. + @MainActor + func test_handleAndRoute_didCompleteAuth_incomplete_withinAppExtension() async { + subject = AuthRouter( + isInAppExtension: true, + services: ServiceContainer.withMocks( + authRepository: authRepository + ) + ) + authRepository.activeAccount = .fixture() + stateService.activeAccount = .fixture() + stateService.accountSetupVaultUnlock["1"] = .incomplete + let route = await subject.handleAndRoute(.didCompleteAuth) + XCTAssertEqual(route, .complete) + } + /// `handleAndRoute(_ :)` redirects `.didCompleteAuth` to `.landing` when there are no accounts. func test_handleAndRoute_didCompleteAuth_noAccounts() async { let route = await subject.handleAndRoute(.didCompleteAuth) diff --git a/BitwardenShared/UI/Auth/Extensions/AuthRouter+Redirects.swift b/BitwardenShared/UI/Auth/Extensions/AuthRouter+Redirects.swift index 8d946ba36..ffac6ae7f 100644 --- a/BitwardenShared/UI/Auth/Extensions/AuthRouter+Redirects.swift +++ b/BitwardenShared/UI/Auth/Extensions/AuthRouter+Redirects.swift @@ -28,16 +28,21 @@ extension AuthRouter { guard let account = try? await services.authRepository.getAccount() else { return .landing } + if account.profile.forcePasswordResetReason != nil { return .updateMasterPassword - } else if await (try? services.stateService.getAccountSetupVaultUnlock()) == .incomplete { - return .vaultUnlockSetup(.createAccount) - } else if await (try? services.stateService.getAccountSetupAutofill()) == .incomplete { - return .autofillSetup - } else { - await setCarouselShownIfEnabled() - return .complete } + + if !isInAppExtension { + if await (try? services.stateService.getAccountSetupVaultUnlock()) == .incomplete { + return .vaultUnlockSetup(.createAccount) + } else if await (try? services.stateService.getAccountSetupAutofill()) == .incomplete { + return .autofillSetup + } + } + + await setCarouselShownIfEnabled() + return .complete } /// Handles the `.didDeleteAccount`route and redirects the user to the correct screen