From 7634ecdd44f40ce3c2c85850840225c2095fa9b9 Mon Sep 17 00:00:00 2001 From: Erica Fu Date: Fri, 20 Mar 2020 15:10:33 -0400 Subject: [PATCH] test updating TCC.db --- Jenkinsfiles/mac | 26 ++++++++++++++++++-- osxscraper/OSXScraper/AccAPI.m | 13 +++++++--- osxscraper/OSXScraperTests/OSXScraperTests.m | 9 ++++--- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/Jenkinsfiles/mac b/Jenkinsfiles/mac index 55fabbb..64df2d5 100644 --- a/Jenkinsfiles/mac +++ b/Jenkinsfiles/mac @@ -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 @@ -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 ''' } } diff --git a/osxscraper/OSXScraper/AccAPI.m b/osxscraper/OSXScraper/AccAPI.m index 2316f4c..44cb655 100644 --- a/osxscraper/OSXScraper/AccAPI.m +++ b/osxscraper/OSXScraper/AccAPI.m @@ -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 @@ -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; } diff --git a/osxscraper/OSXScraperTests/OSXScraperTests.m b/osxscraper/OSXScraperTests/OSXScraperTests.m index 808bb6f..7b7ceee 100644 --- a/osxscraper/OSXScraperTests/OSXScraperTests.m +++ b/osxscraper/OSXScraperTests/OSXScraperTests.m @@ -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 @@ -68,7 +69,7 @@ - (void)tearDown [CalcTask terminate]; } -- (void) testLS +- (void) test001LS { //test 'list of applications', should see itself (OSXScraper) Sinter * sinterInput = [[Sinter alloc] initWithServiceCode:[serviceCodes objectForKey:STRLsReq]]; @@ -76,19 +77,19 @@ - (void) testLS 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]];