generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PM-8216] Add warning to people who don't have two-factor authenticat…
…ion turned on (#1208)
- Loading branch information
1 parent
43e1883
commit 2aa6aef
Showing
64 changed files
with
1,971 additions
and
4 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 |
---|---|---|
|
@@ -80,6 +80,7 @@ extension Account { | |
extension Account.AccountProfile { | ||
static func fixture( | ||
avatarColor: String? = nil, | ||
creationDate: Date? = nil, | ||
email: String = "[email protected]", | ||
emailVerified: Bool? = true, | ||
forcePasswordResetReason: ForcePasswordResetReason? = nil, | ||
|
@@ -91,11 +92,13 @@ extension Account.AccountProfile { | |
name: String? = nil, | ||
orgIdentifier: String? = nil, | ||
stamp: String? = "stamp", | ||
twoFactorEnabled: Bool? = nil, | ||
userDecryptionOptions: UserDecryptionOptions? = nil, | ||
userId: String = "1" | ||
) -> Account.AccountProfile { | ||
Account.AccountProfile( | ||
avatarColor: avatarColor, | ||
creationDate: creationDate, | ||
email: email, | ||
emailVerified: emailVerified, | ||
forcePasswordResetReason: forcePasswordResetReason, | ||
|
@@ -107,6 +110,7 @@ extension Account.AccountProfile { | |
name: name, | ||
orgIdentifier: orgIdentifier, | ||
stamp: stamp, | ||
twoFactorEnabled: twoFactorEnabled, | ||
userDecryptionOptions: userDecryptionOptions, | ||
userId: userId | ||
) | ||
|
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 |
---|---|---|
|
@@ -897,6 +897,24 @@ class StateServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body | |
XCTAssertEqual(action, .logout) | ||
} | ||
|
||
/// `getTwoFactorNoticeDisplayState(userId:)` gets the display state of the two-factor notice for the user. | ||
func test_getTwoFactorNoticeDisplayState() async throws { | ||
appSettingsStore.setTwoFactorNoticeDisplayState(.canAccessEmail, userId: "[email protected]") | ||
|
||
let value = try await subject.getTwoFactorNoticeDisplayState(userId: "[email protected]") | ||
XCTAssertEqual(value, .canAccessEmail) | ||
} | ||
|
||
/// `getTwoFactorNoticeDisplayState()` gets the display state of the two-factor notice for the current user | ||
/// and throws an error if there is no current user. | ||
func test_getTwoFactorNoticeDisplayState_noId() async throws { | ||
appSettingsStore.setTwoFactorNoticeDisplayState(.canAccessEmail, userId: "1") | ||
|
||
await assertAsyncThrows(error: StateServiceError.noActiveAccount) { | ||
_ = try await subject.getTwoFactorNoticeDisplayState() | ||
} | ||
} | ||
|
||
/// `getTwoFactorToken(email:)` gets the two-factor code associated with the email. | ||
func test_getTwoFactorToken() async { | ||
appSettingsStore.setTwoFactorToken("yay_you_win!", email: "[email protected]") | ||
|
@@ -1976,6 +1994,12 @@ class StateServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body | |
} | ||
} | ||
|
||
/// `setTwoFactorNoticeDisplayState(_:userId:)` sets the display state of the two-factor notice for the user. | ||
func test_setTwoFactorNoticeDisplayState() async throws { | ||
try await subject.setTwoFactorNoticeDisplayState(.hasNotSeen, userId: "[email protected]") | ||
XCTAssertEqual(appSettingsStore.twoFactorNoticeDisplayState(userId: "[email protected]"), .hasNotSeen) | ||
} | ||
|
||
/// `setTwoFactorToken(_:email:)` sets the two-factor code for the email. | ||
func test_setTwoFactorToken() async { | ||
await subject.setTwoFactorToken("yay_you_win!", email: "[email protected]") | ||
|
@@ -2143,11 +2167,13 @@ class StateServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body | |
.fixture( | ||
profile: .fixture( | ||
avatarColor: nil, | ||
creationDate: nil, | ||
email: "[email protected]", | ||
emailVerified: false, | ||
hasPremiumPersonally: false, | ||
name: "User", | ||
stamp: "stamp", | ||
twoFactorEnabled: false, | ||
userId: "1" | ||
) | ||
) | ||
|
@@ -2156,11 +2182,13 @@ class StateServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body | |
await subject.updateProfile( | ||
from: .fixture( | ||
avatarColor: "175DDC", | ||
creationDate: Date(year: 2024, month: 12, day: 25), | ||
email: "[email protected]", | ||
emailVerified: true, | ||
name: "Other", | ||
premium: true, | ||
securityStamp: "new stamp" | ||
securityStamp: "new stamp", | ||
twoFactorEnabled: true | ||
), | ||
userId: "1" | ||
) | ||
|
@@ -2171,11 +2199,13 @@ class StateServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body | |
.fixture( | ||
profile: .fixture( | ||
avatarColor: "175DDC", | ||
creationDate: Date(year: 2024, month: 12, day: 25), | ||
email: "[email protected]", | ||
emailVerified: true, | ||
hasPremiumPersonally: true, | ||
name: "Other", | ||
stamp: "new stamp", | ||
twoFactorEnabled: true, | ||
userId: "1" | ||
) | ||
) | ||
|
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 |
---|---|---|
|
@@ -856,6 +856,21 @@ class AppSettingsStoreTests: BitwardenTestCase { // swiftlint:disable:this type_ | |
XCTAssertFalse(userDefaults.bool(forKey: "bwPreferencesStorage:shouldSyncToAuthenticator_2")) | ||
} | ||
|
||
/// `twoFactorNoticeDisplayState(userId:)` returns `.hasNotSeen` if there isn't a previously stored value. | ||
func test_twoFactorNoticeDisplayState_isInitiallyNotSeen() { | ||
XCTAssertEqual(subject.twoFactorNoticeDisplayState(userId: "[email protected]"), .hasNotSeen) | ||
} | ||
|
||
/// `twoFactorToken(email:)` can be used to get and set the persisted value in user defaults. | ||
func test_twoFactorNoticeDisplayState_withValue() { | ||
let date = Date() | ||
subject.setTwoFactorNoticeDisplayState(.canAccessEmail, userId: "[email protected]") | ||
subject.setTwoFactorNoticeDisplayState(.seen(date), userId: "[email protected]") | ||
|
||
XCTAssertEqual(subject.twoFactorNoticeDisplayState(userId: "[email protected]"), .canAccessEmail) | ||
XCTAssertEqual(subject.twoFactorNoticeDisplayState(userId: "[email protected]"), .seen(date)) | ||
} | ||
|
||
/// `twoFactorToken(email:)` returns `nil` if there isn't a previously stored value. | ||
func test_twoFactorToken_isInitiallyNil() { | ||
XCTAssertNil(subject.twoFactorToken(email: "[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
Oops, something went wrong.