Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PM-12783: Trim whitespace from email during registration #1027

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ class StartRegistrationProcessor: StateProcessor<
!token.isEmpty {
coordinator.navigate(to: .completeRegistration(
emailVerificationToken: token,
userEmail: state.emailText
userEmail: email
))
} else {
guard let preAuthUrls = await services.stateService.getPreAuthEnvironmentUrls() else {
throw StartRegistrationError.preAuthUrlsEmpty
}

await services.stateService.setAccountCreationEnvironmentUrls(urls: preAuthUrls, email: email)
coordinator.navigate(to: .checkEmail(email: state.emailText))
coordinator.navigate(to: .checkEmail(email: email))
}
} catch let error as StartRegistrationError {
showStartRegistrationErrorAlert(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,35 @@ class StartRegistrationProcessorTests: BitwardenTestCase { // swiftlint:disable:
LoadingOverlayState(title: Localizations.creatingAccount),
]
)
XCTAssertEqual(stateService.accountCreationEnvironmentUrls["[email protected]"], .defaultEU)
}

/// `perform(_:)` with `.startRegistration` sets preAuthUrls for the given email and navigates to check email.
@MainActor
func test_perform_startRegistration_setPreAuthUrls_checkEmail_emailWithSpaceAndCapitals() async throws {
subject.state = .fixture(emailText: " [email protected] ")
client.result = .httpSuccess(testData: .nilResponse)
stateService.preAuthEnvironmentUrls = .defaultEU

await subject.perform(.startRegistration)

XCTAssertEqual(client.requests.count, 1)
XCTAssertEqual(
client.requests[0].url,
URL(string: "https://example.com/identity/accounts/register/send-verification-email")
)
XCTAssertEqual(coordinator.routes.last, .checkEmail(
email: "[email protected]"
))

XCTAssertFalse(coordinator.isLoadingOverlayShowing)
XCTAssertEqual(
coordinator.loadingOverlaysShown,
[
LoadingOverlayState(title: Localizations.creatingAccount),
]
)
XCTAssertEqual(stateService.accountCreationEnvironmentUrls["[email protected]"], .defaultEU)
}

/// `perform(_:)` with `.startRegistration` fails if preAuthUrls cannot be loaded.
Expand Down Expand Up @@ -382,6 +411,15 @@ class StartRegistrationProcessorTests: BitwardenTestCase { // swiftlint:disable:

XCTAssertFalse(coordinator.isLoadingOverlayShowing)
XCTAssertEqual(coordinator.loadingOverlaysShown, [LoadingOverlayState(title: Localizations.creatingAccount)])
XCTAssertEqual(
coordinator.routes,
[
.completeRegistration(
emailVerificationToken: "0018A45C4D1DEF81644B54AB7F969B88D65\n",
userEmail: "[email protected]"
),
]
)
}

/// `perform(_:)` with `.startRegistration` and a valid email surrounded by whitespace trims the whitespace and
Expand All @@ -402,6 +440,15 @@ class StartRegistrationProcessorTests: BitwardenTestCase { // swiftlint:disable:

XCTAssertFalse(coordinator.isLoadingOverlayShowing)
XCTAssertEqual(coordinator.loadingOverlaysShown, [LoadingOverlayState(title: Localizations.creatingAccount)])
XCTAssertEqual(
coordinator.routes,
[
.completeRegistration(
emailVerificationToken: "0018A45C4D1DEF81644B54AB7F969B88D65\n",
userEmail: "[email protected]"
),
]
)
}

/// `perform(_:)` with `.startRegistration` and a valid email with uppercase characters
Expand All @@ -422,6 +469,15 @@ class StartRegistrationProcessorTests: BitwardenTestCase { // swiftlint:disable:
)
XCTAssertFalse(coordinator.isLoadingOverlayShowing)
XCTAssertEqual(coordinator.loadingOverlaysShown, [LoadingOverlayState(title: Localizations.creatingAccount)])
XCTAssertEqual(
coordinator.routes,
[
.completeRegistration(
emailVerificationToken: "0018A45C4D1DEF81644B54AB7F969B88D65\n",
userEmail: "[email protected]"
),
]
)
}

/// `receive(_:)` with `.dismiss` dismisses the view.
Expand Down
Loading