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

Update AutofillCredentialIdentityStoreManager to allow vault to be initialised lazily #1145

Merged
merged 3 commits into from
Jan 8, 2025
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 @@ -19,6 +19,7 @@
import Foundation
import AuthenticationServices
import Common
import SecureStorage
import os.log

public protocol AutofillCredentialIdentityStoreManaging {
Expand All @@ -32,14 +33,17 @@ public protocol AutofillCredentialIdentityStoreManaging {
final public class AutofillCredentialIdentityStoreManager: AutofillCredentialIdentityStoreManaging {

private let credentialStore: ASCredentialIdentityStoring
private let vault: (any AutofillSecureVault)?
private var vault: (any AutofillSecureVault)?
private let reporter: SecureVaultReporting
private let tld: TLD

public init(credentialStore: ASCredentialIdentityStoring = ASCredentialIdentityStore.shared,
vault: (any AutofillSecureVault)?,
vault: (any AutofillSecureVault)? = nil,
reporter: SecureVaultReporting,
tld: TLD) {
self.credentialStore = credentialStore
self.vault = vault
self.reporter = reporter
self.tld = tld
}

Expand Down Expand Up @@ -240,8 +244,15 @@ final public class AutofillCredentialIdentityStoreManager: AutofillCredentialIde

// MARK: - Private Secure Vault Operations

private func secureVault() -> (any AutofillSecureVault)? {
if vault == nil {
vault = try? AutofillSecureVaultFactory.makeVault(reporter: reporter)
}
return vault
}

private func fetchAccounts() throws -> [SecureVaultModels.WebsiteAccount] {
guard let vault = vault else {
guard let vault = secureVault() else {
Logger.autofill.error("Vault not created")
return []
}
Expand All @@ -256,7 +267,7 @@ final public class AutofillCredentialIdentityStoreManager: AutofillCredentialIde
}

private func fetchAccountsFor(domain: String) throws -> [SecureVaultModels.WebsiteAccount] {
guard let vault = vault else {
guard let vault = secureVault() else {
Logger.autofill.error("Vault not created")
return []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class AutofillCredentialIdentityStoreManagerTests: XCTestCase {
mockVault = DefaultAutofillSecureVault(providers: providers)

tld = TLD()
manager = AutofillCredentialIdentityStoreManager(credentialStore: mockStore, vault: mockVault, tld: tld)
manager = AutofillCredentialIdentityStoreManager(credentialStore: mockStore, vault: mockVault, reporter: MockSecureVaultReporting(), tld: tld)
}

override func tearDown() {
Expand Down Expand Up @@ -205,3 +205,7 @@ final class AutofillCredentialIdentityStoreManagerTests: XCTestCase {
}

}

private class MockSecureVaultReporting: SecureVaultReporting {
func secureVaultError(_ error: SecureStorage.SecureStorageError) {}
}
Loading