Skip to content

Commit

Permalink
Fix regression in update method to fix #110
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewpalmer committed Feb 16, 2016
1 parent 80df919 commit 6b32c7e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Locksmith.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Locksmith"
s.version = "2.0.7"
s.version = "2.0.8"
s.summary = "Locksmith is a powerful, protocol-oriented library for working with the keychain in Swift."
s.description = <<-DESC
Locksmith is a powerful, protocol-oriented library for working with the iOS, Mac OS X, watchOS, and tvOS keychain in Swift. It provides extensive support for a lot of different keychain requests, and extensively uses Swift-native concepts.
Expand Down
14 changes: 9 additions & 5 deletions Source/Locksmith.swift
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,15 @@ extension CreateableSecureStorable {
let status = SecItemUpdate(query, attributesToUpdate)

if let error = LocksmithError(fromStatusCode: Int(status)) {
throw error
}

if status != errSecSuccess {
throw LocksmithError.Undefined
if error == .NotFound || error == .NotAvailable {
try self.createInSecureStore()
} else {
throw error
}
} else {
if status != errSecSuccess {
throw LocksmithError.Undefined
}
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions Tests/LocksmithTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class LocksmithTests: XCTestCase {
let loaded3 = Locksmith.loadDataForUserAccount(userAccount, inService: service)! as! TestingDictionaryType

XCTAssertEqual(loaded3, updatedData)

try! Locksmith.deleteDataForUserAccount(userAccount, inService: service)

try! Locksmith.updateData(["some update": "data"], forUserAccount: userAccount, inService: service)
let updateResult = Locksmith.loadDataForUserAccount(userAccount, inService: service)! as! [String: String]
XCTAssertEqual(updateResult, ["some update": "data"])
}

func testStaticMethodsForDefaultService() {
Expand Down Expand Up @@ -94,6 +100,22 @@ class LocksmithTests: XCTestCase {
createGenericPasswordWithData(data)
}

func testUpdateCreatesIfNotExists() {
let data = ["some": "data"]

struct CreateGenericPassword: CreateableSecureStorable, GenericPasswordSecureStorable, ReadableSecureStorable {
var data: [String: AnyObject]
let account: String
let service: String
}

let update = CreateGenericPassword(data: data, account: userAccount, service: service)
try! update.updateInSecureStore()

let read = update.readFromSecureStore()!.data as! [String: String]
XCTAssertEqual(read, ["some": "data"])
}

func testUpdateForGenericPassword() {
let data = ["some": "data"]

Expand Down

0 comments on commit 6b32c7e

Please sign in to comment.