Skip to content

Commit

Permalink
test updating TCC.db
Browse files Browse the repository at this point in the history
  • Loading branch information
efu39 committed Mar 26, 2020
1 parent 0787fd2 commit 7634ecd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
26 changes: 24 additions & 2 deletions Jenkinsfiles/mac
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ pipeline {
cd osxscraper
xcodebuild -list -project OSXScraper.xcodeproj
xcodebuild -scheme OSXScraper build
xcodebuild test -project OSXScraper.xcodeproj -scheme OSXScraper
echo "Build OSXProxy..."
cd ../osxproxy
xcodebuild -list -project OSXProxy.xcodeproj
Expand All @@ -35,6 +34,29 @@ pipeline {
timeout(time: 1, unit: 'HOURS'){
sh '''
echo "Test(s) go here"
cd osxscraper
/Applications/Calculator.app/Contents/MacOS/Calculator &
echo "build-for-testing"
xcodebuild build-for-testing -project OSXScraper.xcodeproj -scheme OSXScraper
echo "clean the TCC.db"
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" 'select * from access'
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" "SELECT name FROM PRAGMA_TABLE_INFO('access')"
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" "delete from access where client='edu.unc.OSXScraper' and service='kTCCServiceAccessibility'"
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" 'select * from access'
echo "test-without-building, run 1 case to enable Accessibility access magically"
xcodebuild test-without-building -project OSXScraper.xcodeproj -scheme OSXScraper -only-testing:OSXScraperTests/OSXScrapperTests/test001LS
echo "enable the allow access in TCC.db"
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" 'select * from access'
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" "SELECT name FROM PRAGMA_TABLE_INFO('access')"
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" 'UPDATE access SET allowed = "1";'
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" 'select * from access'
echo "test-without-building, run the testcases"
xcodebuild test-without-building -project OSXScraper.xcodeproj -scheme OSXScraper
'''
}
}
Expand Down
13 changes: 9 additions & 4 deletions osxscraper/OSXScraper/AccAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ + (Entity *) getEntityForApp:(pid_t) pid {
}

+ (void) addValidApp: (NSString*) appName {
[valid_apps addObject:appName];
if(![valid_apps containsObject:appName]){
[valid_apps addObject:appName];
NSLog(@"%s valid apps: %@", __PRETTY_FUNCTION__, valid_apps);
}
}

// ls command
Expand All @@ -99,19 +102,21 @@ + (Sinter *) getListOfApplications {
sinter.header.service_code = [serviceCodes objectForKey:STRLsRes];
sinter.header.sub_code = [serviceCodes objectForKey:STRLsRes];

int nProcessAbleToSee = 0;

NSArray * processes = [self getAllProcessesIDs];

int nProcessAbleToSee = 0;
//NSLog(@"%s valid apps: %@", __PRETTY_FUNCTION__, valid_apps);
for ( NSNumber * process_id in processes){
Entity * e = [self getEntityForApp: (pid_t) [process_id integerValue]];
if(e != nil){
nProcessAbleToSee ++;
//NSLog(@"%s ableToSee: %@", __PRETTY_FUNCTION__, e.name);
if([valid_apps containsObject:e.name]) {
[sinter.entities addObject:e];
}
}
}
NSLog(@"nProcessAbleToSee = %i", nProcessAbleToSee);
//NSLog(@"nProcessAbleToSee = %i", nProcessAbleToSee);
return sinter;
}

Expand Down
9 changes: 5 additions & 4 deletions osxscraper/OSXScraperTests/OSXScraperTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ - (void)setUp
[CalcTask setLaunchPath:@"/Applications/Calculator.app/Contents/MacOS/Calculator"];
[CalcTask setArguments:[NSArray arrayWithObjects:@"/bin/bash", nil]];
[CalcTask launchAndReturnError:&err];
NSLog(@"err: %@", err.localizedDescription);
}

- (void)tearDown
Expand All @@ -68,27 +69,27 @@ - (void)tearDown
[CalcTask terminate];
}

- (void) testLS
- (void) test001LS
{
//test 'list of applications', should see itself (OSXScraper)
Sinter * sinterInput = [[Sinter alloc] initWithServiceCode:[serviceCodes objectForKey:STRLsReq]];
Sinter * sinterOutput = [scraper execute:sinterInput];
XCTAssertNotNil(sinterOutput);
XCTAssertTrue([sinterOutput.header.service_code isEqualToNumber: [serviceCodes objectForKey:STRLsRes]]);
XCTAssertTrue(sinterOutput.entities.count >= 1);

BOOL bFoundSelf = NO;
NSLog(@"[sinterOutput.entities count]: %ld", [sinterOutput.entities count]);
for (Entity* e in sinterOutput.entities){
NSLog(@"%s %@, %@", __PRETTY_FUNCTION__, e.name, e.process_id);
if ([e.name isEqualToString:OSXScraperName]){
bFoundSelf = YES;
NSLog(@"%s %@ in STRLsRes", __PRETTY_FUNCTION__, e.name);
break;
}
}
XCTAssertTrue(bFoundSelf);
}

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

0 comments on commit 7634ecd

Please sign in to comment.