OSStatus error -34018 on SecItemAdd with AccessGroup in unit tests.

I'm trying to write some unit tests for my Keychain Access code, but the tests fail because SecItemAdd returns the OSSStatus -34018 in the tests.


My project is setup the following way:

Framework containing the Keychain access code: "APIClient"

An example app demonstrating usage of the framework: "APIClientExampleApp"

A unit test bundle for "APIClientExampleApp" containing unit tests: "APIClientExampleAppTests" (the the tests are running inside a host app)

The unit tests in question, which live inside "APIClientExampleAppTests", fail with an error -34018 from SecItemAdd inside the Keychain code.


After researching a bit I found many issue related to Xcode 8/iOS 10 simulators but not much for iOS 11.

If found the following potential causes, but think I ruled them all out:

- Keychain does not work with logic-tests => My tests are running inside a host application called "APIClientExampleApp"

- Missing application-identifier in entitlements => I think I solved this by Adding the Keychain Sharing capability to the ""APIClientExampleApp", which hosts my tests

- Keychain requires a signed app, but simulator build is not signed => I changed the build settings to always sign the app


Still I get the same error.


One thing that I didn't find in the other discussion so far: I'm using access groups. So I'm trying to store a keychain item with a specific access groups so it can be accessed by other apps/extensions. When I do not set the `kSecAttrAccessGroup` key on the Keychain query dictionary everything works fine. When I do set it on the dictionary passed to SecItemAdd(), I get the -34018 error.


Should access groups work in the simulator? I see that SAMKeychain does not use access groups on the simulator, but can't find any documentation why that is.



This is happening on iOS 11.2 simulators with Xcode 9.2 for me. Any idea pointers what's wrong?

Replies

Access groups don't work in the simulator.