Skip to content

Commit cf85b3c

Browse files
committed
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 6d01d1c commit cf85b3c

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
@@ -166,6 +166,7 @@
166166
7C4D19A8E52B461AB3D80E70 /* GLFileViewContentCacheTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7C4D19A8E52B461AB3D80E71 /* GLFileViewContentCacheTests.m */; };
167167
5E1B93C7D04A47F2A8C61B30 /* PBGitCommitControllerRefreshTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E1B93C7D04A47F2A8C61B31 /* PBGitCommitControllerRefreshTests.m */; };
168168
7C41A9E2B5D340E1A7F26C08 /* PBGitHistorySelectionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E9D3B41C86F42A7B10D5E33 /* PBGitHistorySelectionTests.m */; };
169+
4B1C7D2E9F0A41B3C5D6E701 /* PBGitXEntitlementsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B1C7D2E9F0A41B3C5D6E702 /* PBGitXEntitlementsTests.m */; };
169170
53E95A725F5849DA845F5010 /* PBGitHistoryMenuValidationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9AD4A0BA06594816ACB9327B /* PBGitHistoryMenuValidationTests.m */; };
170171
9120A847CBE34BD0AEEA32CD /* PBGitRepositoryCheckoutErrorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 751132C10E5249A5A42FDC71 /* PBGitRepositoryCheckoutErrorTests.m */; };
171172
1D8C4F70A93E42B6BE7C0D95 /* PBGitWindowWiringTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4F2E8A13C7D9406B85A31E27 /* PBGitWindowWiringTests.m */; };
@@ -183,6 +184,7 @@
183184
7EDCE8EE2EBEFEEF0062CE78 /* AppIcon.icon in Resources */ = {isa = PBXBuildFile; fileRef = 7EDCE8ED2EBEFEEF0062CE78 /* AppIcon.icon */; };
184185
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
185186
911112370E5A097800BF76B4 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 911112360E5A097800BF76B4 /* Security.framework */; };
187+
4B1C7D2E9F0A41B3C5D6E703 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 911112360E5A097800BF76B4 /* Security.framework */; };
186188
913D5E500E55645900CECEA2 /* gitx in Resources */ = {isa = PBXBuildFile; fileRef = 913D5E490E55644600CECEA2 /* gitx */; };
187189
9288179619F9AFBD9A6CBCC3 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5EBDA8F9EBABA601AD309B8 /* Cocoa.framework */; };
188190
94280860227842508DE943E1 /* PBCommitList.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1CE3C5CEB7C423189591B5A /* PBCommitList.swift */; };
@@ -719,6 +721,7 @@
719721
7C4D19A8E52B461AB3D80E71 /* GLFileViewContentCacheTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = GLFileViewContentCacheTests.m; path = GitXTests/GLFileViewContentCacheTests.m; sourceTree = "<group>"; };
720722
5E1B93C7D04A47F2A8C61B31 /* PBGitCommitControllerRefreshTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitCommitControllerRefreshTests.m; path = GitXTests/PBGitCommitControllerRefreshTests.m; sourceTree = "<group>"; };
721723
5E9D3B41C86F42A7B10D5E33 /* PBGitHistorySelectionTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitHistorySelectionTests.m; path = GitXTests/PBGitHistorySelectionTests.m; sourceTree = "<group>"; };
724+
4B1C7D2E9F0A41B3C5D6E702 /* PBGitXEntitlementsTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitXEntitlementsTests.m; path = GitXTests/PBGitXEntitlementsTests.m; sourceTree = "<group>"; };
722725
9AD4A0BA06594816ACB9327B /* PBGitHistoryMenuValidationTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitHistoryMenuValidationTests.m; path = GitXTests/PBGitHistoryMenuValidationTests.m; sourceTree = "<group>"; };
723726
751132C10E5249A5A42FDC71 /* PBGitRepositoryCheckoutErrorTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitRepositoryCheckoutErrorTests.m; path = GitXTests/PBGitRepositoryCheckoutErrorTests.m; sourceTree = "<group>"; };
724727
4F2E8A13C7D9406B85A31E27 /* PBGitWindowWiringTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitWindowWiringTests.m; path = GitXTests/PBGitWindowWiringTests.m; sourceTree = "<group>"; };
@@ -799,6 +802,7 @@
799802
files = (
800803
A3F71C46D2894B0E9C5A7F12 /* ObjectiveGit.framework in Frameworks */,
801804
9288179619F9AFBD9A6CBCC3 /* Cocoa.framework in Frameworks */,
805+
4B1C7D2E9F0A41B3C5D6E703 /* Security.framework in Frameworks */,
802806
);
803807
runOnlyForDeploymentPostprocessing = 0;
804808
};
@@ -858,6 +862,7 @@
858862
7C4D19A8E52B461AB3D80E71 /* GLFileViewContentCacheTests.m */,
859863
5E1B93C7D04A47F2A8C61B31 /* PBGitCommitControllerRefreshTests.m */,
860864
5E9D3B41C86F42A7B10D5E33 /* PBGitHistorySelectionTests.m */,
865+
4B1C7D2E9F0A41B3C5D6E702 /* PBGitXEntitlementsTests.m */,
861866
9AD4A0BA06594816ACB9327B /* PBGitHistoryMenuValidationTests.m */,
862867
751132C10E5249A5A42FDC71 /* PBGitRepositoryCheckoutErrorTests.m */,
863868
4F2E8A13C7D9406B85A31E27 /* PBGitWindowWiringTests.m */,
@@ -1812,6 +1817,7 @@
18121817
7C4D19A8E52B461AB3D80E70 /* GLFileViewContentCacheTests.m in Sources */,
18131818
5E1B93C7D04A47F2A8C61B30 /* PBGitCommitControllerRefreshTests.m in Sources */,
18141819
7C41A9E2B5D340E1A7F26C08 /* PBGitHistorySelectionTests.m in Sources */,
1820+
4B1C7D2E9F0A41B3C5D6E701 /* PBGitXEntitlementsTests.m in Sources */,
18151821
53E95A725F5849DA845F5010 /* PBGitHistoryMenuValidationTests.m in Sources */,
18161822
9120A847CBE34BD0AEEA32CD /* PBGitRepositoryCheckoutErrorTests.m in Sources */,
18171823
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)