generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PM-10524: Persist user's autofill and vault unlock setup progress in …
…create account flow (#944)
- Loading branch information
1 parent
1893bd1
commit 67ee5d9
Showing
22 changed files
with
520 additions
and
166 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 |
---|---|---|
|
@@ -331,7 +331,77 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ | |
try await subject.loginWithMasterPassword( | ||
"Password1234!", | ||
username: "[email protected]", | ||
captchaToken: nil | ||
captchaToken: nil, | ||
isNewAccount: false | ||
) | ||
|
||
// Verify the results. | ||
let preLoginRequest = PreLoginRequestModel( | ||
email: "[email protected]" | ||
) | ||
let tokenRequest = IdentityTokenRequestModel( | ||
authenticationMethod: .password(username: "[email protected]", password: "hashed password"), | ||
captchaToken: nil, | ||
deviceInfo: DeviceInfo( | ||
identifier: "App id", | ||
name: "Model id" | ||
), | ||
loginRequestId: nil | ||
) | ||
XCTAssertEqual(client.requests.count, 2) | ||
XCTAssertEqual(client.requests[0].body, try preLoginRequest.encode()) | ||
XCTAssertEqual(client.requests[1].body, try tokenRequest.encode()) | ||
|
||
XCTAssertEqual(clientService.mockAuth.hashPasswordEmail, "[email protected]") | ||
XCTAssertEqual(clientService.mockAuth.hashPasswordPassword, "Password1234!") | ||
XCTAssertEqual(clientService.mockAuth.hashPasswordKdfParams, .pbkdf2(iterations: 600_000)) | ||
|
||
XCTAssertEqual(stateService.accountsAdded, [Account.fixtureAccountLogin()]) | ||
XCTAssertEqual( | ||
stateService.accountEncryptionKeys, | ||
[ | ||
"13512467-9cfe-43b0-969f-07534084764b": AccountEncryptionKeys( | ||
encryptedPrivateKey: "PRIVATE_KEY", | ||
encryptedUserKey: "KEY" | ||
), | ||
] | ||
) | ||
XCTAssertNil(stateService.accountSetupAutofill["13512467-9cfe-43b0-969f-07534084764b"]) | ||
XCTAssertNil(stateService.accountSetupVaultUnlock["13512467-9cfe-43b0-969f-07534084764b"]) | ||
XCTAssertEqual( | ||
stateService.masterPasswordHashes, | ||
["13512467-9cfe-43b0-969f-07534084764b": "hashed password"] | ||
) | ||
try XCTAssertEqual( | ||
keychainRepository.getValue(for: .accessToken(userId: "13512467-9cfe-43b0-969f-07534084764b")), | ||
IdentityTokenResponseModel.fixture().accessToken | ||
) | ||
try XCTAssertEqual( | ||
keychainRepository.getValue(for: .refreshToken(userId: "13512467-9cfe-43b0-969f-07534084764b")), | ||
IdentityTokenResponseModel.fixture().refreshToken | ||
) | ||
assertGetConfig() | ||
} | ||
|
||
/// `loginWithMasterPassword(_:username:captchaToken:)` logs the user in with the password for | ||
/// a newly created account. | ||
func test_loginWithMasterPassword_isNewAccount() async throws { // swiftlint:disable:this function_body_length | ||
client.results = [ | ||
.httpSuccess(testData: .preLoginSuccess), | ||
.httpSuccess(testData: .identityTokenSuccess), | ||
] | ||
appSettingsStore.appId = "App id" | ||
clientService.mockAuth.hashPasswordResult = .success("hashed password") | ||
configService.featureFlagsBool[.nativeCreateAccountFlow] = true | ||
stateService.preAuthEnvironmentUrls = EnvironmentUrlData(base: URL(string: "https://vault.bitwarden.com")) | ||
systemDevice.modelIdentifier = "Model id" | ||
|
||
// Attempt to login. | ||
try await subject.loginWithMasterPassword( | ||
"Password1234!", | ||
username: "[email protected]", | ||
captchaToken: nil, | ||
isNewAccount: true | ||
) | ||
|
||
// Verify the results. | ||
|
@@ -365,6 +435,8 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ | |
), | ||
] | ||
) | ||
XCTAssertEqual(stateService.accountSetupAutofill["13512467-9cfe-43b0-969f-07534084764b"], .incomplete) | ||
XCTAssertEqual(stateService.accountSetupVaultUnlock["13512467-9cfe-43b0-969f-07534084764b"], .incomplete) | ||
XCTAssertEqual( | ||
stateService.masterPasswordHashes, | ||
["13512467-9cfe-43b0-969f-07534084764b": "hashed password"] | ||
|
@@ -398,7 +470,8 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ | |
try await subject.loginWithMasterPassword( | ||
"Password1234!", | ||
username: "[email protected]", | ||
captchaToken: nil | ||
captchaToken: nil, | ||
isNewAccount: false | ||
) | ||
|
||
// Verify the results. | ||
|
@@ -461,7 +534,8 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ | |
try await subject.loginWithMasterPassword( | ||
"Password1234!", | ||
username: "[email protected]", | ||
captchaToken: nil | ||
captchaToken: nil, | ||
isNewAccount: false | ||
) | ||
} | ||
|
||
|
@@ -607,7 +681,8 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ | |
try await subject.loginWithMasterPassword( | ||
"Password1234!", | ||
username: "[email protected]", | ||
captchaToken: nil | ||
captchaToken: nil, | ||
isNewAccount: false | ||
) | ||
} | ||
|
||
|
@@ -675,7 +750,8 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ | |
try await subject.loginWithMasterPassword( | ||
"Password1234!", | ||
username: "[email protected]", | ||
captchaToken: nil | ||
captchaToken: nil, | ||
isNewAccount: false | ||
) | ||
} | ||
|
||
|
@@ -713,7 +789,8 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ | |
try await subject.loginWithMasterPassword( | ||
"Password1234!", | ||
username: "[email protected]", | ||
captchaToken: nil | ||
captchaToken: nil, | ||
isNewAccount: false | ||
) | ||
} | ||
|
||
|
@@ -823,7 +900,8 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ | |
try await subject.loginWithMasterPassword( | ||
"Password1234!", | ||
username: "[email protected]", | ||
captchaToken: nil | ||
captchaToken: nil, | ||
isNewAccount: false | ||
) | ||
} | ||
|
||
|
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
14 changes: 14 additions & 0 deletions
14
BitwardenShared/Core/Platform/Models/Enum/AccountSetupProgress.swift
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// MARK: - AccountSetupProgress | ||
|
||
/// An enum to represent a user's progress towards setting up new account functionality. | ||
/// | ||
enum AccountSetupProgress: Int, Codable { | ||
/// The user hasn't yet made any progress. | ||
case incomplete = 0 | ||
|
||
/// The user choose to set up the functionality later. | ||
case setUpLater = 1 | ||
|
||
/// The user has completed the set up. | ||
case complete = 2 | ||
} |
Oops, something went wrong.