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

[ios_xctestrun_runner] codesigning/entitlements blockers #1912

Closed
iainsmith opened this issue Mar 18, 2023 · 10 comments
Closed

[ios_xctestrun_runner] codesigning/entitlements blockers #1912

iainsmith opened this issue Mar 18, 2023 · 10 comments
Assignees

Comments

@iainsmith
Copy link

iainsmith commented Mar 18, 2023

Summary

ios_xctestrun_runner doesn't match codesigning/entitlements from Xcodes XCTRunner.app, which blocks certain API's (in our case a Network.framework based HTTP Server). This Apple forums post, seems to indicate this as the likely cause.

More details

We tried migrating to the new ios_xctestrunner for our UITests and hit this issue. We did a bit of digging, and think it's related to the codesigning/entitlements. Our UITest try to start a (Network.framework) based MockServer, which fails to launch.

There is a previous issue #504 about moving the codesigning responsibilities outside of the test runner from a couple of years ago.

I was wondering if the test runner can call tools/codesigningtool.py or if it's better to just shell out to codesign -f directly in the ios_xctestrun_runner.template.sh

cc @mattrobmattrob

@keith
Copy link
Member

keith commented Mar 18, 2023

@maxwellE

@maxwellE
Copy link
Contributor

So I assume that you are running on device? Or even using Network.framework on sim crashes?

Feel free to assign to me. Ideally we have a test case for this scenario as well

@iainsmith
Copy link
Author

iainsmith commented Mar 18, 2023

So I assume that you are running on device? Or even using Network.framework on sim crashes?

It happens on the simulator.

We probably crash in our test because we assume that server always starts. I think the underlying issue is NWListener can't bind to the port, from within XTRunner on the simulator.

I will try and post a minimal reproducer later.

@maxwellE
Copy link
Contributor

@keith you can assign to me, should be able to take a look today

maxwellE added a commit to maxwellE/rules_apple that referenced this issue Mar 26, 2023
Attempts to adhoc code sign the runner app itself and
its bundled frameworks during UI Testing to resolve
[ios_xctestrun_runner] codesigning/entitlements blockers bazelbuild#1912
@maxwellE
Copy link
Contributor

@iainsmith Can you check out #1932 and see if that works for you?

@iainsmith
Copy link
Author

Hey @maxwellE I tried this out locally, but I'm hitting the same error where we can't start the NWListener.

I can see these lines in the log,

entitlements_path=/var/folders/9j/_v7frzl550x84_qn_8d6rrm00000gq/T//test_tmp_dir.D7dg5F/XCTRunner.app/RunnerEntitlements.plist
find /var/folders/9j/_v7frzl550x84_qn_8d6rrm00000gq/T//test_tmp_dir.D7dg5F/XCTRunner.app/Frameworks -name '*.framework' -exec codesign -f --entitlements /var/folders/9j/_v7frzl550x84_qn_8d6rrm00000gq/T//test_tmp_dir.D7dg5F/XCTRunner.app/RunnerEntitlements.plist --timestamp=none -s - '{}' ';'
codesign -f --entitlements /var/folders/9j/_v7frzl550x84_qn_8d6rrm00000gq/T//test_tmp_dir.D7dg5F/XCTRunner.app/RunnerEntitlements.plist --timestamp=none -s - /var/folders/9j/_v7frzl550x84_qn_8d6rrm00000gq/T//test_tmp_dir.D7dg5F/XCTRunner.app

Unable to start mock server on port: 11704 (some random port)

@maxwellE
Copy link
Contributor

maxwellE commented Apr 8, 2023

@iainsmith Can you push up a small repro to this branch for me to test with?

@maxwellE
Copy link
Contributor

I am starting to investigate this again

@maxwellE
Copy link
Contributor

@iainsmith I am ready to test again with #1968

mattrobmattrob pushed a commit that referenced this issue Jun 2, 2023
Adds the necessary setup to codesign the runner and places artifacts in expected locations to support on device running of ui tests

Related #1912

Attached is an image of a test running on my phone

<img width="686" alt="Screenshot 2023-05-18 at 9 25 56 PM" src="https://github.com/bazelbuild/rules_apple/assets/566328/21d21225-8fa9-4e75-bbce-e7176f29dde3">

https://github.com/bazelbuild/rules_apple/assets/566328/b9d52ae1-328a-41e4-b2dd-b4dd76ed544c
@iainsmith
Copy link
Author

Fixed in 2.4.0

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

No branches or pull requests

3 participants