From 2ded5402af7b794a7c28af0a7177f94353653a7f Mon Sep 17 00:00:00 2001 From: Artur Guseinov Date: Wed, 1 Nov 2023 21:46:45 +0800 Subject: [PATCH] testUpdateItemNotFoundFails test fixed --- .../WalletConnectKMS/Keychain/KeychainStorage.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Sources/WalletConnectKMS/Keychain/KeychainStorage.swift b/Sources/WalletConnectKMS/Keychain/KeychainStorage.swift index bd9d19798..d354cad91 100644 --- a/Sources/WalletConnectKMS/Keychain/KeychainStorage.swift +++ b/Sources/WalletConnectKMS/Keychain/KeychainStorage.swift @@ -75,7 +75,7 @@ public final class KeychainStorage: KeychainStorageProtocol { case errSecSuccess: return case errSecItemNotFound: - tryMigrateAttrAccessibleOnUpdate(data: data, key: key) // TODO: Remove once migration period ends + try tryMigrateAttrAccessibleOnUpdate(data: data, key: key) // TODO: Remove once migration period ends default: throw KeychainError(status) } @@ -133,7 +133,7 @@ public final class KeychainStorage: KeychainStorageProtocol { return item as? Data } - private func tryMigrateAttrAccessibleOnUpdate(data: Data, key: String) { + private func tryMigrateAttrAccessibleOnUpdate(data: Data, key: String) throws { var updateAccessQuery = buildBaseServiceQuery(for: key) updateAccessQuery[kSecAttrAccessible] = kSecAttrAccessibleWhenUnlockedThisDeviceOnly @@ -141,12 +141,16 @@ public final class KeychainStorage: KeychainStorageProtocol { let accessStatus = secItem.update(updateAccessQuery as CFDictionary, accessAttributes as CFDictionary) guard accessStatus == errSecSuccess else { - return + throw KeychainError.itemNotFound } let updateQuery = buildBaseServiceQuery(for: key) let updateAttributes = [kSecValueData: data] - _ = secItem.update(updateQuery as CFDictionary, updateAttributes as CFDictionary) + let updateStatus = secItem.update(updateQuery as CFDictionary, updateAttributes as CFDictionary) + + guard updateStatus == errSecSuccess else { + throw KeychainError.itemNotFound + } } }