Skip to content

Commit

Permalink
[PM-12012] Remove region parsing from email URL (#947)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrebispo5 authored Sep 19, 2024
1 parent a8d5a6c commit 1893bd1
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 40 deletions.
12 changes: 4 additions & 8 deletions BitwardenShared/UI/Auth/AuthCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,16 @@ final class AuthCoordinator: NSObject, // swiftlint:disable:this type_body_lengt
case let .completeRegistration(emailVerificationToken, userEmail):
showCompleteRegistration(
emailVerificationToken: emailVerificationToken,
userEmail: userEmail,
region: nil
userEmail: userEmail
)
case let .completeRegistrationFromAppLink(emailVerificationToken, userEmail, fromEmail, region):
case let .completeRegistrationFromAppLink(emailVerificationToken, userEmail, fromEmail):
// Coming from an AppLink clear the current stack
stackNavigator?.dismiss {
self.showLanding()
self.showCompleteRegistration(
emailVerificationToken: emailVerificationToken,
userEmail: userEmail,
fromEmail: fromEmail,
region: region
fromEmail: fromEmail
)
}
case .createAccount:
Expand Down Expand Up @@ -334,8 +332,7 @@ final class AuthCoordinator: NSObject, // swiftlint:disable:this type_body_lengt
private func showCompleteRegistration(
emailVerificationToken: String,
userEmail: String,
fromEmail: Bool = false,
region: RegionType?
fromEmail: Bool = false
) {
let view = CompleteRegistrationView(
store: Store(
Expand All @@ -345,7 +342,6 @@ final class AuthCoordinator: NSObject, // swiftlint:disable:this type_body_lengt
state: CompleteRegistrationState(
emailVerificationToken: emailVerificationToken,
fromEmail: fromEmail,
region: region,
userEmail: userEmail
)
)
Expand Down
6 changes: 2 additions & 4 deletions BitwardenShared/UI/Auth/AuthCoordinatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ class AuthCoordinatorTests: BitwardenTestCase { // swiftlint:disable:this type_b
subject.navigate(to: .completeRegistrationFromAppLink(
emailVerificationToken: "thisisanamazingtoken",
userEmail: "[email protected]",
fromEmail: true,
region: .unitedStates
fromEmail: true
))

let landingAction = try XCTUnwrap(stackNavigator.actions[1])
Expand Down Expand Up @@ -173,8 +172,7 @@ class AuthCoordinatorTests: BitwardenTestCase { // swiftlint:disable:this type_b
subject.navigate(to: .completeRegistrationFromAppLink(
emailVerificationToken: "thisisanamazingtoken",
userEmail: "[email protected]",
fromEmail: true,
region: .unitedStates
fromEmail: true
))
subject.navigate(to: .expiredLink)
subject.navigate(to: .startRegistrationFromExpiredLink)
Expand Down
4 changes: 1 addition & 3 deletions BitwardenShared/UI/Auth/AuthRoute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ public enum AuthRoute: Equatable {
/// - emailVerificationToken: Token needed to complete registration.
/// - userEmail: The user's email.
/// - fromEmail: The user opened the app from an email AppLink.
/// - region: Region where the complete registration should happen.
///
case completeRegistrationFromAppLink(
emailVerificationToken: String,
userEmail: String,
fromEmail: Bool,
region: RegionType
fromEmail: Bool
)

/// Dismisses the auth flow becuase the vault was unlocked with the never unlock key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ struct CompleteRegistrationState: Equatable, Sendable {
arePasswordsVisible ? Asset.Images.hidden : Asset.Images.visible
}

/// The region where the account should be created
var region: RegionType?

/// The required text count for the password strength.
var requiredPasswordCount = Constants.minimumPasswordCharacters

Expand Down
5 changes: 2 additions & 3 deletions BitwardenShared/UI/Platform/Application/AppProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public class AppProcessor {

// Check for specific URL components that you need.
guard let params = components.queryItems,
let host = components.host else {
components.host != nil else {
services.errorReporter.log(error: AppProcessorError.appLinksInvalidURL)
return
}
Expand All @@ -190,8 +190,7 @@ public class AppProcessor {
AuthRoute.completeRegistrationFromAppLink(
emailVerificationToken: verificationToken,
userEmail: email,
fromEmail: Bool(fromEmail) ?? true,
region: host.contains(RegionType.europe.baseUrlDescription) ? .europe : .unitedStates
fromEmail: Bool(fromEmail) ?? true
)))
}

Expand Down
21 changes: 2 additions & 19 deletions BitwardenShared/UI/Platform/Application/AppProcessorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,23 +223,7 @@ class AppProcessorTests: BitwardenTestCase { // swiftlint:disable:this type_body
XCTAssertEqual(coordinator.routes.last, .auth(.completeRegistrationFromAppLink(
emailVerificationToken: "verificationtoken",
userEmail: "[email protected]",
fromEmail: true,
region: .unitedStates
)))
}

/// `handleAppLinks(URL)` navigates the user based on the input URL with EU region.
@MainActor
func test_init_handleAppLinks_regionEU() {
// swiftlint:disable:next line_length
let url = URL(string: "https://bitwarden.eu/redirect-connector.html#[email protected]&token=verificationtoken&fromEmail=true")
subject.handleAppLinks(incomingURL: url!)

XCTAssertEqual(coordinator.routes.last, .auth(.completeRegistrationFromAppLink(
emailVerificationToken: "verificationtoken",
userEmail: "[email protected]",
fromEmail: true,
region: .europe
fromEmail: true
)))
}

Expand All @@ -253,8 +237,7 @@ class AppProcessorTests: BitwardenTestCase { // swiftlint:disable:this type_body
XCTAssertEqual(coordinator.routes.last, .auth(.completeRegistrationFromAppLink(
emailVerificationToken: "verificationtoken",
userEmail: "[email protected]",
fromEmail: true,
region: .europe
fromEmail: true
)))
}

Expand Down

0 comments on commit 1893bd1

Please sign in to comment.