Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Entitlements in debugger? #60

Closed
starlight173 opened this issue Nov 12, 2015 · 19 comments
Closed

Missing Entitlements in debugger? #60

starlight173 opened this issue Nov 12, 2015 · 19 comments

Comments

@starlight173
Copy link

A 'Missing Entitlements' error occurred. This is likely due to an Apple Keychain bug. As a workaround try running on a device that is not attached to a debugger.

More information: https://forums.developer.apple.com/thread/4743

Guy, I got this issue in log when saving a string token to keychain on iOS 9

valet = VALValet(identifier:"com.abc.xyz", accessibility: .WhenUnlockedThisDeviceOnly)
valet!.setString(token, forKey: "token")

Any help?

@starlight173 starlight173 changed the title Missing Entitlements Missing Entitlements in debugger? Nov 12, 2015
@dfed
Copy link
Collaborator

dfed commented Nov 12, 2015

Were you running your app on a device attached to Xcode? If so, please follow the instructions in the error message and try running in the simulator or running on the device without Xcode attached.

Please also see the debugging section of the README. Closing for now, but please comment if none of the above debugging tips apply.

@gligorkot
Copy link

Hi @dfed, I've started getting this issue again now that I've updated to XCode 9 and running the tests. Any guidance would be appreciated. Thanks!

@dfed
Copy link
Collaborator

dfed commented Sep 19, 2017

I haven't encountered anything different in Xcode 9, so I don't have any Xcode-9-specific tips. Have you gone through the debugging section? If you download the Valet project and run the Valet unit tests, do entitlements work for you?

My suggestion is to study Valet's iOS test host app configuration for hints on how to get your app set up with keychain. I assume you're still using a standard (not shared-access) VALValet?

@gligorkot
Copy link

Thanks for the prompt reply. Yeah, I've gone through the debugging section and I think point 6 would apply to me in this situation. I'll try your suggestion and report back. Thanks

@gligorkot
Copy link

Hi again, have downloaded Valet's iOS app and am able to run the tests on XCode 9 just fine, however have not found anything that I am doing differently in my application. It's really weird as it worked just fine in XCode 8.3 and only started happening when I switched to XCode 9.

I'll give you some details on my project below, if you can spot anything that I am doing differently I would really appreciate if you could point me in the right direction please.

My project is split into 2, one project for the application, another project for a framework/library that is fully unit tested (this is where I use Valet). The workspace includes these two projects as well as the Pods project.

My unit tests are all part of the framework/library project but I can run them from the Main application scheme (ie. using the main app as a test host)

I use VALSynchronizableValet with accessibility .whenUnlocked

@dfed
Copy link
Collaborator

dfed commented Sep 20, 2017

At face value this sounds right – you're running your unit tests within your main app as your host. At which point... if your Valets are working in the main app (are they?), they should also be working in unit tests (since they're running in the main app).

I hate to ask this, but: if you go back to Xcode 8 and run your tests, do they still work? If you have a use case where it works on Xcode 8 but not on 9 (and you can show this side-by-side), we're in some pretty interesting waters.

I'm curious: do you have signing enabled on your unit test target?

@gligorkot
Copy link

Interesting indeed.

The Valets are working in the main app as I can run it in the simulator (even debug version) and all is fine.

Unfortunately I can't get stuff running again in XCode 8 as I've updated to Swift 4, but I'll try doing this from an old branch and see if I can reproduce this side-by-side as you suggest.

Enabling/disabling signing on the unit test target didn't make any difference. The only signing that I have enabled is for my main app Release build, no signing on Debug for either target.

Really appreciate your responses to this, if you need any more hands on deck for the library let me know, happy to help any way I can.

@dfed
Copy link
Collaborator

dfed commented Sep 20, 2017

The only signing that I have enabled is for my main app Release build, no signing on Debug for either target.

Not to send you down a rabbit hole, but my guess is you need signing in Debug too.

And if you'd like to help out, keep an eye on #80! We're doing a lot of work there. We could use feedback on the Swift API we're building for Valet 3. It's still somewhat rough (we're maybe 75% of the way through the work we want to do), but we're actively working on it and can always use more eyes :)

@gligorkot
Copy link

gligorkot commented Sep 20, 2017

Have just reverted back to an old branch before all the XCode 9 specific diffs, running in XCode 8.3.3 (8E3004b) I was able to run my unit tests as usual.

XCode 9, I've tried adding signing to Debug of the main app, of the library and the unit tests target and there's no difference. Still getting this same error. Interesting to note: I get this error when running on iOS 9.3 or iOS 10.3.1 simulator, when I run on iOS 11 my tests fail with the same fatalError but I don't see this error in the console.

I wonder if it might be Swift 4 that is the issue, I'll go back to XCode 9 and try run it under Swift 3 still.

@gligorkot
Copy link

Right, opened the same commit in XCode 9 just now (still Swift 3), did a clean and build. Ran the tests and I get this error. If I close that and open the workspace in XCode 8, all is working.

This is bizarre.

@dfed
Copy link
Collaborator

dfed commented Sep 20, 2017

Wow this is a new one. Please do let me know what you find!!

@gligorkot
Copy link

Hmm... even tried using the develop/3.0 branch code and changed all my VALValet to using the new Swift api, still the same result. Will keep digging. This has been a major setback unfortunately.

@gligorkot
Copy link

@dfed
Copy link
Collaborator

dfed commented Sep 20, 2017

Woof. I wouldn’t have expected 3.0 to help. This reeks of an entitlements problem rather than a Valet issue – my guess is any other keychain interactor would fail too.

Crazy idea (I’m reaching now): create a brand new test target. Host it in the app. Import Valet (or use keychain manually, or another wrapper), write a single test that sees if you can access the keychain. If it succeeds, then we’ve learned it’s a target configuration issue. If it fails, we’ve learned that something about running the tests in your host app is the issue. Good luck!

@dfed
Copy link
Collaborator

dfed commented Sep 20, 2017

Ouch. Just saw the stackoverflow post. I’m not surprised that you’re not the only one. The fact that Valet unit tests worked for you on Xcode 9 is a good sign though. Means that it’s possible on your machine to have a test host that works.

Another crazy idea: create a brand new host app test target (that is entirely empty) with Xcode 9 and host your unit tests in it. Make sure you’ve turned on the keychain sharing entitlement (you may not need it but it can’t hurt!). If it works, you know it’s your host app’s build settings or entitlements that are failing, and you can compare locally. If it doesn’t... well, we’ll cross that bridge if we get there.

Another q: if you use a vanilla Valet rather than a Synchronizable, do your tests work? Synchronizable keychain items require entitlements in a test environment; vanilla ones do not.

(I know the “create a new host / test target” suggestions sound a bit left field. But I promise you this is what I do when I hit these kinds of bugs. It sucks. It’s time consuming. You’ll learn more than you ever wanted to about build settings / signing / entitlements. But sometimes you can get a good hint about what’s wrong by starting from scratch / limiting your potential problem space).

@gligorkot
Copy link

Voila! Got it working!!

Yeah, I hear you on the new targets / build settings / signing etc. That's exactly what I do as well.

So the key seems to be - the test target needs to be part of the Main app project, not the framework/library project!!??

Thanks to your previous suggestion, this worked with a single test accessing the keychain, then I quickly copied all of my tests from the library into this new target and they all ran just fine.

Perhaps it's just an XCode 9.0 defect and they will fix in a later version, but for now I'm going to have to move all of my tests into the main app project. Seems weird seeing as how these tests don't even test the app, but alas.

@dfed
Copy link
Collaborator

dfed commented Sep 20, 2017

Glad it worked!!!! That is indeed a pretty weird fix. Sounds like entitlements aren’t transferring to embedded frameworks properly. But hey, you’ve got a solution!! Thanks for reporting back 🤗

@gligorkot
Copy link

Thanks for all the suggestions man, really appreciate it!

And also as a side note, I don't have the shared keychain entitlements enabled in the app either, but this has never been an issue before. I kept trying with that enabled/disabled and the tests in the library, but didn't make a difference.

@dfed
Copy link
Collaborator

dfed commented Sep 20, 2017

Good to know re the shared keychain entitlement. That's supposed to affect shared access groups, but on prior Xcode versions toggling that on has been a lifesaver when unit testing other kinds of Valets. Glad at least that's no longer part of the equation 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants