Skip to content

Commit

Permalink
Update AutofillCredentialIdentityStoreManager to allow vault to be in…
Browse files Browse the repository at this point in the history
…itialised lazily (#1145)

Task/Issue URL:
https://app.asana.com/0/414709148257752/1209045090157949/f
iOS PR: duckduckgo/iOS#3763
macOS PR: duckduckgo/macos-browser#3702
What kind of version bump will this require?: Minor

**Description**:
Update to vault initialization in AutofillCredentialIdentityStoreManager
to only init on demand
  • Loading branch information
amddg44 authored Jan 8, 2025
1 parent bb43f0c commit 99bea80
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
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) {}
}

0 comments on commit 99bea80

Please sign in to comment.