Replace Vault dependency with @KeychainStorage property wrapper
Changelog-Changed: replace Vault dependency with @KeychainStorage property wrapper Closes: #1076
This commit is contained in:
committed by
William Casarin
parent
27fb4e797d
commit
e4860f3ba8
46
damusTests/KeychainStorageTests.swift
Normal file
46
damusTests/KeychainStorageTests.swift
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// KeychainStorageTests.swift
|
||||
// damusTests
|
||||
//
|
||||
// Created by Bryan Montz on 5/3/23.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import damus
|
||||
import Security
|
||||
|
||||
final class KeychainStorageTests: XCTestCase {
|
||||
@KeychainStorage(account: "test-keyname")
|
||||
var secret: String?
|
||||
|
||||
override func tearDownWithError() throws {
|
||||
secret = nil
|
||||
}
|
||||
|
||||
func testWriteToKeychain() throws {
|
||||
// write a secret to the keychain using the property wrapper's setter
|
||||
secret = "super-secure-key"
|
||||
|
||||
// verify it exists in the keychain using the property wrapper's getter
|
||||
XCTAssertEqual(secret, "super-secure-key")
|
||||
|
||||
// verify it exists in the keychain directly
|
||||
let query = [
|
||||
kSecAttrService: "damus",
|
||||
kSecAttrAccount: "test-keyname",
|
||||
kSecClass: kSecClassGenericPassword,
|
||||
kSecReturnData: true,
|
||||
kSecMatchLimit: kSecMatchLimitOne
|
||||
] as [CFString: Any] as CFDictionary
|
||||
|
||||
var result: AnyObject?
|
||||
let status = SecItemCopyMatching(query, &result)
|
||||
XCTAssertEqual(status, errSecSuccess)
|
||||
|
||||
let data = try XCTUnwrap(result as? Data)
|
||||
let the_secret = String(data: data, encoding: .utf8)
|
||||
|
||||
XCTAssertEqual(the_secret, "super-secure-key")
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user