test add, edit, delete
This commit is contained in:
parent
98ad323431
commit
12c8c04203
2 changed files with 65 additions and 6 deletions
|
|
@ -320,7 +320,7 @@ public class PasswordStore {
|
||||||
saveUpdatedContext()
|
saveUpdatedContext()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func saveUpdatedContext() {
|
private func saveUpdatedContext() {
|
||||||
PersistenceController.shared.save()
|
PersistenceController.shared.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -115,16 +115,75 @@ final class PasswordStoreTest: XCTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testEncryptSaveDecryptMultiline() throws {
|
func testAddPassword() throws {
|
||||||
try cloneRepository(.empty)
|
try cloneRepository(.empty)
|
||||||
try importSinglePGPKey()
|
try importSinglePGPKey()
|
||||||
|
|
||||||
let password = Password(name: "test", path: "test.gpg", plainText: "foobar\nwith\nmultiple\nlines")
|
let password1 = Password(name: "test1", path: "test1.gpg", plainText: "foobar")
|
||||||
_ = try passwordStore.add(password: password)
|
let password2 = Password(name: "test2", path: "test2.gpg", plainText: "hello world")
|
||||||
let decryptedPassword = try decrypt(path: "test.gpg")
|
let password3 = Password(name: "test3", path: "test3.gpg", plainText: "lorem ipsum")
|
||||||
XCTAssertEqual(decryptedPassword.plainText, "foobar\nwith\nmultiple\nlines")
|
let password4 = Password(name: "test4", path: "test4.gpg", plainText: "you are valuable and you matter")
|
||||||
|
|
||||||
|
[password1, password2, password3, password4].forEach { password in
|
||||||
|
expectation(forNotification: .passwordStoreUpdated, object: nil)
|
||||||
|
|
||||||
|
let savedEntity = try? passwordStore.add(password: password)
|
||||||
|
|
||||||
|
XCTAssertEqual(savedEntity!.name, password.name)
|
||||||
|
waitForExpectations(timeout: 1, handler: nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testDeletePassword() throws {
|
||||||
|
try cloneRepository(.withGPGID)
|
||||||
|
|
||||||
|
expectation(forNotification: .passwordStoreUpdated, object: nil)
|
||||||
|
|
||||||
|
let entity = passwordStore.fetchPasswordEntity(with: "personal/github.com.gpg")
|
||||||
|
try passwordStore.delete(passwordEntity: entity!)
|
||||||
|
|
||||||
|
XCTAssertNil(passwordStore.fetchPasswordEntity(with: "personal/github.com.gpg"))
|
||||||
|
waitForExpectations(timeout: 1, handler: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testEditPasswordValue() throws {
|
||||||
|
try cloneRepository(.withGPGID)
|
||||||
|
try importSinglePGPKey()
|
||||||
|
let entity = passwordStore.fetchPasswordEntity(with: "personal/github.com.gpg")!
|
||||||
|
|
||||||
|
expectation(forNotification: .passwordStoreUpdated, object: nil)
|
||||||
|
|
||||||
|
let editedPassword = Password(name: entity.name, path: entity.path, plainText: "editedpassword")
|
||||||
|
editedPassword.changed = PasswordChange.content.rawValue
|
||||||
|
let editedEntity = try passwordStore.edit(passwordEntity: entity, password: editedPassword)
|
||||||
|
|
||||||
|
XCTAssertNotNil(editedEntity)
|
||||||
|
XCTAssertEqual(editedEntity!.name, "github.com")
|
||||||
|
XCTAssertFalse(editedEntity!.isSynced)
|
||||||
|
XCTAssertEqual(try decrypt(path: "personal/github.com.gpg").plainText, "editedpassword")
|
||||||
|
waitForExpectations(timeout: 1, handler: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testMovePassword() throws {
|
||||||
|
try cloneRepository(.withGPGID)
|
||||||
|
try importSinglePGPKey()
|
||||||
|
let entity = passwordStore.fetchPasswordEntity(with: "personal/github.com.gpg")!
|
||||||
|
|
||||||
|
expectation(forNotification: .passwordStoreUpdated, object: nil)
|
||||||
|
|
||||||
|
let editedPassword = Password(name: "new name", path: "new name.gpg", plainText: "passwordforpersonal\n")
|
||||||
|
editedPassword.changed = PasswordChange.path.rawValue
|
||||||
|
let editedEntity = try passwordStore.edit(passwordEntity: entity, password: editedPassword)
|
||||||
|
|
||||||
|
XCTAssertEqual(editedEntity!.name, "new name")
|
||||||
|
XCTAssertFalse(editedEntity!.isSynced)
|
||||||
|
XCTAssertEqual(try decrypt(path: "new name.gpg").plainText, "passwordforpersonal\n")
|
||||||
|
XCTAssertNil(passwordStore.fetchPasswordEntity(with: "personal/github.com.gpg"))
|
||||||
|
waitForExpectations(timeout: 1, handler: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - .gpg-id support
|
||||||
|
|
||||||
func testCloneAndDecryptMultiKeys() throws {
|
func testCloneAndDecryptMultiKeys() throws {
|
||||||
try cloneRepository(.withGPGID)
|
try cloneRepository(.withGPGID)
|
||||||
try importMultiplePGPKeys()
|
try importMultiplePGPKeys()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue