Skip to content

Commit

Permalink
BIT-2346: Additional tests and feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-livefront committed Jun 4, 2024
1 parent 67ccf6c commit 60beb7d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,30 @@ class AutofillCredentialServiceTests: BitwardenTestCase {
XCTAssertNil(pasteboardService.copiedString)
}

/// `provideCredential(for:)` copies the cipher's TOTP code if the user doesn't have premium
/// but the org uses TOTP.
func test_provideCredential_totpCopyOrgUseTotp() async throws {
cipherService.fetchCipherResult = .success(
.fixture(
login: .fixture(
password: "password123",
username: "[email protected]",
totp: "totp"
),
organizationUseTotp: true
)
)
stateService.activeAccount = .fixture()
stateService.doesActiveAccountHavePremiumResult = .success(false)
vaultTimeoutService.isClientLocked["1"] = false

let credential = try await subject.provideCredential(for: "1", repromptPasswordValidated: false)

XCTAssertEqual(credential.password, "password123")
XCTAssertEqual(credential.user, "[email protected]")
XCTAssertEqual(pasteboardService.copiedString, "123456")
}

/// `provideCredential(for:)` throws an error if the user's vault is locked.
func test_provideCredential_vaultLocked() async {
stateService.activeAccount = .fixture()
Expand Down
10 changes: 9 additions & 1 deletion BitwardenShared/Core/Platform/Services/StateServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ class StateServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body
func test_doesActiveAccountHavePremium_personalFalse_organizationTrue() async throws {
await subject.addAccount(.fixture(profile: .fixture(hasPremiumPersonally: false)))
try await dataStore.replaceOrganizations([.fixture(usersGetPremium: true)], userId: "1")
let organizations = try await dataStore.fetchAllOrganizations(userId: "1")
let hasPremium = try await subject.doesActiveAccountHavePremium()
XCTAssertTrue(hasPremium)
}
Expand Down Expand Up @@ -194,6 +193,15 @@ class StateServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body
XCTAssertFalse(hasPremium)
}

/// `doesActiveAccountHavePremium()` with no premium personally and an organization with premium
/// for a different user returns false.
func test_doesActiveAccountHavePremium_personalFalse_organizationTrueForOtherUser() async throws {
await subject.addAccount(.fixture(profile: .fixture(hasPremiumPersonally: false)))
try await dataStore.replaceOrganizations([.fixture(enabled: true, usersGetPremium: true)], userId: "2")
let hasPremium = try await subject.doesActiveAccountHavePremium()
XCTAssertFalse(hasPremium)
}

/// `getAccountEncryptionKeys(_:)` returns the encryption keys for the user account.
func test_getAccountEncryptionKeys() async throws {
appSettingsStore.encryptedPrivateKeys["1"] = "1:PRIVATE_KEY"
Expand Down

0 comments on commit 60beb7d

Please sign in to comment.