Reading from Keychain Xcode 9 simulators returns nothing
Asked Answered
D

2

6

Since I'm using Xcode 9, all unit tests communicating with keychain are broken. It also happens with Xcode GM. As I traced, there is no OSStatus errors while reading and writing but reading from keychain returns nothing and causes failure for all unit tests using keychain. I've already faced something like this when Apple released Xcode 8 with iOS 10 simulator which keychain was not working and Apple fixed that in Xcode 8.2. Is anybody else facing this issue with iOS 11 simulator too? Any idea on this?

Dickson answered 19/9, 2017 at 11:35 Comment(1)
Hey Elyas, I'm facing a similar issue. My unit tests are working on XCode 8.3.3 in both iOS 9.3 and 10.3.1 simulators. However, if I run them using XCode 9, they fail on all simulators (iOS 9.3, 10.3.1 and 11.0). Would be keen to know if you find a solution to this.Misology
D
17

Finally we found the problem. As @Gix said the problem is with unit tests inside our framework. The SDK tests don’t have an app context, so don’t have the/a keychain available. But actually we didn't want to move the tests from SDK into app as you did @Gix. So we could fix the problem just by adding an app target in the SDK project, then set that as host for the SDK unit tests. Now unit tests are passing. But I still don't understand why its only failing in the new Xcode. We realize it's not an iOS 11 Simulator issue because the same failure happens with iOS 10 simulators in Xcode 9 too. So this restriction is a property of Xcode 9 Simulator app which can be fixed with the solution I provided. It is still messy but it works and you don't need to move tests from SDK into app!

Dickson answered 20/9, 2017 at 8:34 Comment(1)
Same here, since Xcode 9 the Unit Tests for the Keychain are failing unless I add a AppTarget into my Framework.Stepchild
M
1

Just figured this one out on my side, so I thought I'd let you know in case you are having the same issue.

My problem was the way I have my project set up. In my project I have a workspace with 3 projects, 1 is the Main App, 1 is a framework/library and 1 is the Pods project. I was accessing the keychain in my framework, and my unit tests target was part of this project.

After extensive discussion and work with Dan Federman from the team behind the library Valet (which you can find here), we figured out that my unit tests target needs to be part of the project where the Main App is. Once I copied all of my tests from the library project to the Main App project, everything ran and worked just fine.

Hope this helps!

Misology answered 20/9, 2017 at 3:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.