Skip to content

Commit 8212d0a

Browse files
committed
test updating TCC.db
1 parent 0787fd2 commit 8212d0a

3 files changed

Lines changed: 35 additions & 7 deletions

File tree

Jenkinsfiles/mac

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ pipeline {
1919
cd osxscraper
2020
xcodebuild -list -project OSXScraper.xcodeproj
2121
xcodebuild -scheme OSXScraper build
22-
xcodebuild test -project OSXScraper.xcodeproj -scheme OSXScraper
23-
22+
2423
echo "Build OSXProxy..."
2524
cd ../osxproxy
2625
xcodebuild -list -project OSXProxy.xcodeproj
@@ -35,6 +34,29 @@ pipeline {
3534
timeout(time: 1, unit: 'HOURS'){
3635
sh '''
3736
echo "Test(s) go here"
37+
cd osxscraper
38+
/Applications/Calculator.app/Contents/MacOS/Calculator &
39+
40+
echo "build-for-testing"
41+
xcodebuild build-for-testing -project OSXScraper.xcodeproj -scheme OSXScraper
42+
43+
echo "clean the TCC.db"
44+
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" 'select * from access'
45+
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" "SELECT name FROM PRAGMA_TABLE_INFO('access')"
46+
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" "delete from access where client='edu.unc.OSXScraper' and service='kTCCServiceAccessibility'"
47+
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" 'select * from access'
48+
49+
echo "test-without-building, run 1 case to enable Accessibility access magically"
50+
xcodebuild test-without-building -project OSXScraper.xcodeproj -scheme OSXScraper -only-testing:OSXScraperTests/OSXScrapperTests/testLS
51+
52+
echo "enable the allow access in TCC.db"
53+
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" 'select * from access'
54+
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" "SELECT name FROM PRAGMA_TABLE_INFO('access')"
55+
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" 'UPDATE access SET allowed = "1";'
56+
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" 'select * from access'
57+
58+
echo "test-without-building, run the testcases"
59+
xcodebuild test-without-building -project OSXScraper.xcodeproj -scheme OSXScraper
3860
'''
3961
}
4062
}

osxscraper/OSXScraper/AccAPI.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ + (Entity *) getEntityForApp:(pid_t) pid {
9090
}
9191

9292
+ (void) addValidApp: (NSString*) appName {
93-
[valid_apps addObject:appName];
93+
if(![valid_apps containsObject:appName])
94+
[valid_apps addObject:appName];
9495
}
9596

9697
// ls command
@@ -102,15 +103,19 @@ + (Sinter *) getListOfApplications {
102103
int nProcessAbleToSee = 0;
103104

104105
NSArray * processes = [self getAllProcessesIDs];
106+
NSLog(@"%s valid apps: %@", __PRETTY_FUNCTION__, valid_apps);
105107
for ( NSNumber * process_id in processes){
106108
Entity * e = [self getEntityForApp: (pid_t) [process_id integerValue]];
107109
if(e != nil){
108110
nProcessAbleToSee ++;
111+
NSLog(@"%s ableToSee: %@", __PRETTY_FUNCTION__, e.name);
109112
if([valid_apps containsObject:e.name]) {
110113
[sinter.entities addObject:e];
114+
NSLog(@"%s add_to_Sinter: %@", __PRETTY_FUNCTION__, e.name);
111115
}
112116
}
113117
}
118+
NSLog(@"process in Sinter: %ld", [sinter.entities count]);
114119
NSLog(@"nProcessAbleToSee = %i", nProcessAbleToSee);
115120
return sinter;
116121
}

osxscraper/OSXScraperTests/OSXScraperTests.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ - (void)setUp
5959
[CalcTask setLaunchPath:@"/Applications/Calculator.app/Contents/MacOS/Calculator"];
6060
[CalcTask setArguments:[NSArray arrayWithObjects:@"/bin/bash", nil]];
6161
[CalcTask launchAndReturnError:&err];
62+
NSLog(@"err: %@", err.localizedDescription);
6263
}
6364

6465
- (void)tearDown
@@ -68,27 +69,27 @@ - (void)tearDown
6869
[CalcTask terminate];
6970
}
7071

71-
- (void) testLS
72+
- (void) test001LS
7273
{
7374
//test 'list of applications', should see itself (OSXScraper)
7475
Sinter * sinterInput = [[Sinter alloc] initWithServiceCode:[serviceCodes objectForKey:STRLsReq]];
7576
Sinter * sinterOutput = [scraper execute:sinterInput];
7677
XCTAssertNotNil(sinterOutput);
7778
XCTAssertTrue([sinterOutput.header.service_code isEqualToNumber: [serviceCodes objectForKey:STRLsRes]]);
7879
XCTAssertTrue(sinterOutput.entities.count >= 1);
80+
7981
BOOL bFoundSelf = NO;
82+
NSLog(@"[sinterOutput.entities count]: %ld", [sinterOutput.entities count]);
8083
for (Entity* e in sinterOutput.entities){
8184
NSLog(@"%s %@, %@", __PRETTY_FUNCTION__, e.name, e.process_id);
8285
if ([e.name isEqualToString:OSXScraperName]){
8386
bFoundSelf = YES;
84-
NSLog(@"%s %@ in STRLsRes", __PRETTY_FUNCTION__, e.name);
85-
break;
8687
}
8788
}
8889
XCTAssertTrue(bFoundSelf);
8990
}
9091

91-
- (void) testLongLS
92+
- (void) test002LongLS
9293
{
9394
//first get the process_id of itself, then test long LS (scrape it and output a response sinter
9495
Sinter * sinterInput = [[Sinter alloc] initWithServiceCode:[serviceCodes objectForKey:STRLsReq]];

0 commit comments

Comments
 (0)