Skip to content

Commit b762deb

Browse files
gonengGonen
authored andcommitted
Fix Open in Terminal doing nothing in released builds (issue gitx#636)
Opening a repository in a terminal is carried entirely by an Apple event, which the hardened runtime refuses to send unless the application asks for the privilege. * Declare com.apple.security.automation.apple-events, so the command reaches Terminal or iTerm2 instead of being rejected below the consent layer, where it produces neither a prompt nor an error. * Cover the entitlement with a test. The restriction is lifted for local builds by com.apple.security.get-task-allow, so the failure never shows up when building from Xcode and needs guarding rather than noticing. * Link Security.framework into the test target, which the check needs.
1 parent 9b93ee1 commit b762deb

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

‎GitX.entitlements‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
4-
<dict/>
4+
<dict>
5+
<key>com.apple.security.automation.apple-events</key>
6+
<true/>
7+
</dict>
58
</plist>

‎GitX.xcodeproj/project.pbxproj‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
7C41A9E2B5D340E1A7F26C08 /* PBGitHistorySelectionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E9D3B41C86F42A7B10D5E33 /* PBGitHistorySelectionTests.m */; };
170170
09EB95E6AD3341A38EFA5B2F /* PBGitHistoryWorktreeMenuTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 68477EB22B3146C5AAB4FEFA /* PBGitHistoryWorktreeMenuTests.m */; };
171171
D95DB968C64F4AC7B93EA89A /* PBGitRepositoryWorktreeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C60E5F191BB343B19F63AFE9 /* PBGitRepositoryWorktreeTests.m */; };
172+
4B1C7D2E9F0A41B3C5D6E701 /* PBGitXEntitlementsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B1C7D2E9F0A41B3C5D6E702 /* PBGitXEntitlementsTests.m */; };
172173
53E95A725F5849DA845F5010 /* PBGitHistoryMenuValidationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9AD4A0BA06594816ACB9327B /* PBGitHistoryMenuValidationTests.m */; };
173174
9120A847CBE34BD0AEEA32CD /* PBGitRepositoryCheckoutErrorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 751132C10E5249A5A42FDC71 /* PBGitRepositoryCheckoutErrorTests.m */; };
174175
1D8C4F70A93E42B6BE7C0D95 /* PBGitWindowWiringTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4F2E8A13C7D9406B85A31E27 /* PBGitWindowWiringTests.m */; };
@@ -186,6 +187,7 @@
186187
7EDCE8EE2EBEFEEF0062CE78 /* AppIcon.icon in Resources */ = {isa = PBXBuildFile; fileRef = 7EDCE8ED2EBEFEEF0062CE78 /* AppIcon.icon */; };
187188
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
188189
911112370E5A097800BF76B4 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 911112360E5A097800BF76B4 /* Security.framework */; };
190+
4B1C7D2E9F0A41B3C5D6E703 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 911112360E5A097800BF76B4 /* Security.framework */; };
189191
913D5E500E55645900CECEA2 /* gitx in Resources */ = {isa = PBXBuildFile; fileRef = 913D5E490E55644600CECEA2 /* gitx */; };
190192
9288179619F9AFBD9A6CBCC3 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5EBDA8F9EBABA601AD309B8 /* Cocoa.framework */; };
191193
94280860227842508DE943E1 /* PBCommitList.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1CE3C5CEB7C423189591B5A /* PBCommitList.swift */; };
@@ -727,6 +729,7 @@
727729
5E9D3B41C86F42A7B10D5E33 /* PBGitHistorySelectionTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitHistorySelectionTests.m; path = GitXTests/PBGitHistorySelectionTests.m; sourceTree = "<group>"; };
728730
68477EB22B3146C5AAB4FEFA /* PBGitHistoryWorktreeMenuTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitHistoryWorktreeMenuTests.m; path = GitXTests/PBGitHistoryWorktreeMenuTests.m; sourceTree = "<group>"; };
729731
C60E5F191BB343B19F63AFE9 /* PBGitRepositoryWorktreeTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitRepositoryWorktreeTests.m; path = GitXTests/PBGitRepositoryWorktreeTests.m; sourceTree = "<group>"; };
732+
4B1C7D2E9F0A41B3C5D6E702 /* PBGitXEntitlementsTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitXEntitlementsTests.m; path = GitXTests/PBGitXEntitlementsTests.m; sourceTree = "<group>"; };
730733
9AD4A0BA06594816ACB9327B /* PBGitHistoryMenuValidationTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitHistoryMenuValidationTests.m; path = GitXTests/PBGitHistoryMenuValidationTests.m; sourceTree = "<group>"; };
731734
751132C10E5249A5A42FDC71 /* PBGitRepositoryCheckoutErrorTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitRepositoryCheckoutErrorTests.m; path = GitXTests/PBGitRepositoryCheckoutErrorTests.m; sourceTree = "<group>"; };
732735
4F2E8A13C7D9406B85A31E27 /* PBGitWindowWiringTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitWindowWiringTests.m; path = GitXTests/PBGitWindowWiringTests.m; sourceTree = "<group>"; };
@@ -808,6 +811,7 @@
808811
files = (
809812
A3F71C46D2894B0E9C5A7F12 /* ObjectiveGit.framework in Frameworks */,
810813
9288179619F9AFBD9A6CBCC3 /* Cocoa.framework in Frameworks */,
814+
4B1C7D2E9F0A41B3C5D6E703 /* Security.framework in Frameworks */,
811815
);
812816
runOnlyForDeploymentPostprocessing = 0;
813817
};
@@ -869,6 +873,7 @@
869873
5E9D3B41C86F42A7B10D5E33 /* PBGitHistorySelectionTests.m */,
870874
68477EB22B3146C5AAB4FEFA /* PBGitHistoryWorktreeMenuTests.m */,
871875
C60E5F191BB343B19F63AFE9 /* PBGitRepositoryWorktreeTests.m */,
876+
4B1C7D2E9F0A41B3C5D6E702 /* PBGitXEntitlementsTests.m */,
872877
9AD4A0BA06594816ACB9327B /* PBGitHistoryMenuValidationTests.m */,
873878
751132C10E5249A5A42FDC71 /* PBGitRepositoryCheckoutErrorTests.m */,
874879
4F2E8A13C7D9406B85A31E27 /* PBGitWindowWiringTests.m */,
@@ -1829,6 +1834,7 @@
18291834
7C41A9E2B5D340E1A7F26C08 /* PBGitHistorySelectionTests.m in Sources */,
18301835
09EB95E6AD3341A38EFA5B2F /* PBGitHistoryWorktreeMenuTests.m in Sources */,
18311836
D95DB968C64F4AC7B93EA89A /* PBGitRepositoryWorktreeTests.m in Sources */,
1837+
4B1C7D2E9F0A41B3C5D6E701 /* PBGitXEntitlementsTests.m in Sources */,
18321838
53E95A725F5849DA845F5010 /* PBGitHistoryMenuValidationTests.m in Sources */,
18331839
9120A847CBE34BD0AEEA32CD /* PBGitRepositoryCheckoutErrorTests.m in Sources */,
18341840
1D8C4F70A93E42B6BE7C0D95 /* PBGitWindowWiringTests.m in Sources */,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// PBGitXEntitlementsTests.m
3+
// GitXTests
4+
//
5+
6+
#import <XCTest/XCTest.h>
7+
#import <Security/Security.h>
8+
9+
// Opening a repository in Terminal or iTerm2 is carried entirely by an Apple
10+
// event, which the hardened runtime refuses to send for an application that does
11+
// not ask for the privilege. Released builds are signed with that runtime, so
12+
// without the entitlement the event is rejected below the consent layer: the
13+
// terminal is launched but the command never arrives, and nothing tells the user.
14+
@interface PBGitXEntitlementsTests : XCTestCase
15+
@end
16+
17+
@implementation PBGitXEntitlementsTests
18+
19+
- (void)testTheApplicationIsAllowedToSendAppleEvents
20+
{
21+
SecTaskRef task = SecTaskCreateFromSelf(kCFAllocatorDefault);
22+
XCTAssertTrue(task != NULL, @"the test host should be a signed task");
23+
24+
CFTypeRef entitlement = SecTaskCopyValueForEntitlement(task, CFSTR("com.apple.security.automation.apple-events"), NULL);
25+
CFRelease(task);
26+
27+
XCTAssertTrue(entitlement == kCFBooleanTrue, @"GitX cannot drive a terminal application without this entitlement");
28+
29+
if (entitlement)
30+
CFRelease(entitlement);
31+
}
32+
33+
@end

0 commit comments

Comments
 (0)