mocking prep: PasswordStoreTest has its own KeyStore
This commit is contained in:
parent
e3de11f71c
commit
38649f96fe
1 changed files with 16 additions and 11 deletions
|
|
@ -15,11 +15,15 @@ import XCTest
|
|||
final class PasswordStoreTest: XCTestCase {
|
||||
private let localRepoURL: URL = Globals.sharedContainerURL.appendingPathComponent("Library/password-store-test/")
|
||||
|
||||
private var keyStore: KeyStore! = nil
|
||||
private var pgpAgent: PGPAgent! = nil
|
||||
private var passwordStore: PasswordStore! = nil
|
||||
|
||||
override func setUp() {
|
||||
pgpAgent = PGPAgent()
|
||||
super.setUp()
|
||||
|
||||
keyStore = DictBasedKeychain()
|
||||
pgpAgent = PGPAgent(keyStore: keyStore)
|
||||
passwordStore = PasswordStore(url: localRepoURL, pgpAgent: pgpAgent)
|
||||
}
|
||||
|
||||
|
|
@ -27,8 +31,11 @@ final class PasswordStoreTest: XCTestCase {
|
|||
passwordStore.erase()
|
||||
passwordStore = nil
|
||||
pgpAgent = nil
|
||||
keyStore = nil
|
||||
|
||||
Defaults.removeAll()
|
||||
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
func testInitPasswordEntityCoreData() throws {
|
||||
|
|
@ -78,7 +85,7 @@ final class PasswordStoreTest: XCTestCase {
|
|||
PasscodeLock.shared.save(passcode: "1234")
|
||||
|
||||
XCTAssertGreaterThan(passwordStore.numberOfPasswords, 0)
|
||||
XCTAssertTrue(AppKeychain.shared.contains(key: PGPKey.PUBLIC.getKeychainKey()))
|
||||
XCTAssertTrue(keyStore.contains(key: PGPKey.PUBLIC.getKeychainKey()))
|
||||
XCTAssertEqual(Defaults.gitSignatureName, "Test User")
|
||||
XCTAssertTrue(PasscodeLock.shared.hasPasscode)
|
||||
XCTAssertTrue(pgpAgent.isInitialized())
|
||||
|
|
@ -88,7 +95,7 @@ final class PasswordStoreTest: XCTestCase {
|
|||
passwordStore.erase()
|
||||
|
||||
XCTAssertEqual(passwordStore.numberOfPasswords, 0)
|
||||
XCTAssertFalse(AppKeychain.shared.contains(key: PGPKey.PUBLIC.getKeychainKey()))
|
||||
XCTAssertFalse(keyStore.contains(key: PGPKey.PUBLIC.getKeychainKey()))
|
||||
XCTAssertFalse(Defaults.hasKey(\.gitSignatureName))
|
||||
XCTAssertFalse(PasscodeLock.shared.hasPasscode)
|
||||
XCTAssertFalse(pgpAgent.isInitialized())
|
||||
|
|
@ -382,17 +389,15 @@ final class PasswordStoreTest: XCTestCase {
|
|||
}
|
||||
|
||||
private func importSinglePGPKey() throws {
|
||||
let keychain = AppKeychain.shared
|
||||
try KeyFileManager(keyType: PGPKey.PUBLIC, keyPath: "", keyHandler: keychain.add).importKey(from: RSA4096.publicKey)
|
||||
try KeyFileManager(keyType: PGPKey.PRIVATE, keyPath: "", keyHandler: keychain.add).importKey(from: RSA4096.privateKey)
|
||||
try PGPAgent.shared.initKeys()
|
||||
try KeyFileManager(keyType: PGPKey.PUBLIC, keyPath: "", keyHandler: keyStore.add).importKey(from: RSA4096.publicKey)
|
||||
try KeyFileManager(keyType: PGPKey.PRIVATE, keyPath: "", keyHandler: keyStore.add).importKey(from: RSA4096.privateKey)
|
||||
try pgpAgent.initKeys()
|
||||
}
|
||||
|
||||
private func importMultiplePGPKeys() throws {
|
||||
let keychain = AppKeychain.shared
|
||||
try KeyFileManager(keyType: PGPKey.PUBLIC, keyPath: "", keyHandler: keychain.add).importKey(from: RSA2048_RSA4096.publicKeys)
|
||||
try KeyFileManager(keyType: PGPKey.PRIVATE, keyPath: "", keyHandler: keychain.add).importKey(from: RSA2048_RSA4096.privateKeys)
|
||||
try PGPAgent.shared.initKeys()
|
||||
try KeyFileManager(keyType: PGPKey.PUBLIC, keyPath: "", keyHandler: keyStore.add).importKey(from: RSA2048_RSA4096.publicKeys)
|
||||
try KeyFileManager(keyType: PGPKey.PRIVATE, keyPath: "", keyHandler: keyStore.add).importKey(from: RSA2048_RSA4096.privateKeys)
|
||||
try pgpAgent.initKeys()
|
||||
}
|
||||
|
||||
private func decrypt(path: String, keyID: String? = nil) throws -> Password {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue