generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BIT-2366: Alert user to switch to existing account with matching emai…
…l on login (#688)
- Loading branch information
1 parent
eca5364
commit 54f855c
Showing
16 changed files
with
307 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,6 +247,68 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo | |
XCTAssertEqual(client.requests[0].url, URL(string: "https://example.com/api/accounts")) | ||
} | ||
|
||
/// `existingAccountUserId(email:)` returns the user ID of the existing account with the same | ||
/// email and base URLs. | ||
func test_existingAccountUserId() async throws { | ||
environmentService.baseURL = try XCTUnwrap(EnvironmentUrlData.defaultUS.base) | ||
stateService.activeAccount = .fixture(profile: .fixture(email: "[email protected]", userId: "1")) | ||
stateService.environmentUrls["1"] = .defaultUS | ||
stateService.userIds = ["1"] | ||
|
||
let userId = await subject.existingAccountUserId(email: "[email protected]") | ||
|
||
XCTAssertEqual(userId, "1") | ||
} | ||
|
||
/// `existingAccountUserId(email:)` returns `nil` if getting the environment URLs throws an error. | ||
func test_existingAccountUserId_getEnvironmentUrlsError() async throws { | ||
environmentService.baseURL = try XCTUnwrap(EnvironmentUrlData.defaultUS.base) | ||
stateService.activeAccount = .fixture(profile: .fixture(email: "[email protected]", userId: "1")) | ||
stateService.environmentUrlsError = StateServiceError.noAccounts | ||
stateService.userIds = ["1"] | ||
|
||
let userId = await subject.existingAccountUserId(email: "[email protected]") | ||
|
||
XCTAssertNil(userId) | ||
} | ||
|
||
/// `existingAccountUserId(email:)` returns `nil` if there's an existing account with the same | ||
/// email but the base URLs are different. | ||
func test_existingAccountUserId_matchingAccountDifferentBaseUrl() async throws { | ||
environmentService.baseURL = try XCTUnwrap(EnvironmentUrlData.defaultEU.base) | ||
stateService.activeAccount = .fixture(profile: .fixture(email: "[email protected]", userId: "1")) | ||
stateService.environmentUrls["1"] = .defaultUS | ||
stateService.userIds = ["1"] | ||
|
||
let userId = await subject.existingAccountUserId(email: "[email protected]") | ||
|
||
XCTAssertNil(userId) | ||
} | ||
|
||
/// `existingAccountUserId(email:)` returns the matching user ID with the same base URL, if | ||
/// there are multiple matches for the user's email. | ||
func test_existingAccountUserId_multipleMatching() async throws { | ||
stateService.activeAccount = .fixture(profile: .fixture(email: "[email protected]", userId: "1")) | ||
stateService.environmentUrls["1"] = .defaultUS | ||
stateService.environmentUrls["2"] = .defaultEU | ||
stateService.userIds = ["1", "2"] | ||
|
||
environmentService.baseURL = try XCTUnwrap(EnvironmentUrlData.defaultUS.base) | ||
var userId = await subject.existingAccountUserId(email: "[email protected]") | ||
XCTAssertEqual(userId, "1") | ||
|
||
environmentService.baseURL = try XCTUnwrap(EnvironmentUrlData.defaultEU.base) | ||
userId = await subject.existingAccountUserId(email: "[email protected]") | ||
XCTAssertEqual(userId, "2") | ||
} | ||
|
||
/// `existingAccountUserId(email:)` returns `nil` if there isn't an account that matches the email. | ||
func test_existingAccountUserId_noMatchingAccount() async throws { | ||
let userId = await subject.existingAccountUserId(email: "[email protected]") | ||
|
||
XCTAssertNil(userId) | ||
} | ||
|
||
/// `allowBioMetricUnlock(:)` throws an error if required. | ||
func test_allowBioMetricUnlock_biometricsRepositoryError() async throws { | ||
biometricsRepository.setBiometricUnlockKeyError = BiometricsServiceError.setAuthKeyFailed | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -729,6 +729,55 @@ class StateServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body | |
XCTAssertTrue(userHasMasterPassword) | ||
} | ||
|
||
/// `getUserIds(email:)` returns the user ID of any users with a matching email. | ||
func test_getUserIds() async { | ||
appSettingsStore.state = State( | ||
accounts: [ | ||
"1": .fixture(profile: .fixture(email: "[email protected]", userId: "1")), | ||
"2": .fixture(profile: .fixture(email: "[email protected]", userId: "2")), | ||
"3": .fixture(profile: .fixture(email: "[email protected]", userId: "3")), | ||
] | ||
) | ||
|
||
let user1Ids = await subject.getUserIds(email: "[email protected]") | ||
XCTAssertEqual(user1Ids, ["1"]) | ||
|
||
let user3Ids = await subject.getUserIds(email: "[email protected]") | ||
XCTAssertEqual(user3Ids, ["3"]) | ||
} | ||
|
||
/// `getUserIds(email:)` returns multiple user IDs if they all have a matching email. | ||
func test_getUserIds_multiple() async { | ||
appSettingsStore.state = State( | ||
accounts: [ | ||
"1": .fixture(profile: .fixture(email: "[email protected]", userId: "1")), | ||
"2": .fixture(profile: .fixture(email: "[email protected]", userId: "2")), | ||
"3": .fixture(profile: .fixture(email: "[email protected]", userId: "3")), | ||
] | ||
) | ||
|
||
let userIds = await subject.getUserIds(email: "[email protected]") | ||
XCTAssertEqual(userIds.sorted(), ["1", "2", "3"]) | ||
} | ||
|
||
/// `getUserIds(email:)` returns `nil` if there isn't a user with a matching email. | ||
func test_getUserIds_noMatchingUser() async { | ||
appSettingsStore.state = State( | ||
accounts: [ | ||
"1": .fixture(profile: .fixture(email: "[email protected]", userId: "1")), | ||
] | ||
) | ||
|
||
let userIds = await subject.getUserIds(email: "[email protected]") | ||
XCTAssertTrue(userIds.isEmpty) | ||
} | ||
|
||
/// `getUserIds(email:)` returns `nil` if there are no other users. | ||
func test_getUserIds_noUsers() async { | ||
let userIds = await subject.getUserIds(email: "[email protected]") | ||
XCTAssertTrue(userIds.isEmpty) | ||
} | ||
|
||
/// `getUsernameGenerationOptions()` gets the saved username generation options for the account. | ||
func test_getUsernameGenerationOptions() async throws { | ||
let options1 = UsernameGenerationOptions(plusAddressedEmail: "[email protected]") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
// MARK: - LandingEffect | ||
|
||
/// Effects that can be processed by a `LandingProcessor`. | ||
enum LandingEffect { | ||
enum LandingEffect: Equatable { | ||
/// The vault list appeared on screen. | ||
case appeared | ||
|
||
/// The continue button was pressed. | ||
case continuePressed | ||
|
||
/// A Profile Switcher Effect. | ||
case profileSwitcher(ProfileSwitcherEffect) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.