From b8fecf1f36515b100107dcc04a1754e80c41d0fa Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 12 Mar 2016 18:21:07 -0500 Subject: [PATCH] Fix issues with unit tests I added public DSA file, automatic update checking, disabled system profiling in the unit test's info.plist so that SUUpdater won't complain that DSA is missing, and it won't prompt for update permission the first time. I also made SUUpdater use the correct bundle in SUUpdaterTest --- Tests/SUCodeSigningVerifierTest.m | 31 ++++++++++++++++++++----------- Tests/SUUpdaterTest.m | 2 +- Tests/SparkleTests-Info.plist | 6 ++++++ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Tests/SUCodeSigningVerifierTest.m b/Tests/SUCodeSigningVerifierTest.m index a2b7e764..43f91d7e 100644 --- a/Tests/SUCodeSigningVerifierTest.m +++ b/Tests/SUCodeSigningVerifierTest.m @@ -10,6 +10,7 @@ #import #import "NTSynchronousTask.h" #import "SUCodeSigningVerifier.h" +#import "SUFileManager.h" @interface SUCodeSigningVerifierTest : XCTestCase @@ -32,11 +33,24 @@ NSBundle *unitTestBundle = [NSBundle bundleForClass:[self class]]; NSString *unitTestBundleIdentifier = unitTestBundle.bundleIdentifier; NSString *zippedAppPath = [unitTestBundle pathForResource:@"SparkleTestCodeSignApp" ofType:@"zip"]; - NSString *tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:unitTestBundleIdentifier]; + + SUFileManager *fileManager = [SUFileManager fileManagerAllowingAuthorization:NO]; + + NSError *tempError = nil; + NSURL *tempDir = [fileManager makeTemporaryDirectoryWithPreferredName:unitTestBundleIdentifier appropriateForDirectoryURL:[NSURL fileURLWithPath:zippedAppPath] error:&tempError]; + + if (tempDir == nil) { + XCTFail(@"Failed to create temporary directory with error: %@", tempError); + return; + } + + NSString *tempDirPath = tempDir.path; + XCTAssertNotNil(tempDirPath); + NSError *error = nil; - if ([[NSFileManager defaultManager] createDirectoryAtPath:tempDir withIntermediateDirectories:YES attributes:nil error:&error]) { - if ([self unzip:zippedAppPath toPath:tempDir]) { - self.notSignedAppPath = [tempDir stringByAppendingPathComponent:@"SparkleTestCodeSignApp.app"]; + if ([[NSFileManager defaultManager] createDirectoryAtPath:tempDirPath withIntermediateDirectories:YES attributes:nil error:&error]) { + if ([self unzip:zippedAppPath toPath:tempDirPath]) { + self.notSignedAppPath = [tempDirPath stringByAppendingPathComponent:@"SparkleTestCodeSignApp.app"]; [self setupValidSignedApp]; [self setupInvalidSignedApp]; } @@ -54,13 +68,8 @@ [super tearDown]; if (self.notSignedAppPath) { - [[NSFileManager defaultManager] removeItemAtPath:self.notSignedAppPath error:nil]; - } - if (self.validSignedAppPath) { - [[NSFileManager defaultManager] removeItemAtPath:self.validSignedAppPath error:nil]; - } - if (self.invalidSignedAppPath) { - [[NSFileManager defaultManager] removeItemAtPath:self.invalidSignedAppPath error:nil]; + NSString *tempDir = [self.notSignedAppPath stringByDeletingLastPathComponent]; + [[NSFileManager defaultManager] removeItemAtPath:tempDir error:nil]; } } diff --git a/Tests/SUUpdaterTest.m b/Tests/SUUpdaterTest.m index 0e7d6e76..0ff7e930 100644 --- a/Tests/SUUpdaterTest.m +++ b/Tests/SUUpdaterTest.m @@ -24,7 +24,7 @@ { [super setUp]; self.queue = [[NSOperationQueue alloc] init]; - self.updater = [[SUUpdater alloc] init]; + self.updater = [[SUUpdater alloc] initForBundle:[NSBundle bundleForClass:[self class]]]; self.updater.delegate = self; } diff --git a/Tests/SparkleTests-Info.plist b/Tests/SparkleTests-Info.plist index 460a7d93..e7e83b9d 100644 --- a/Tests/SparkleTests-Info.plist +++ b/Tests/SparkleTests-Info.plist @@ -16,5 +16,11 @@ ???? CFBundleVersion 1.0 + SUEnableAutomaticChecks + + SUEnableSystemProfiling + + SUPublicDSAKeyFile + test-pubkey.pem