diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index e0a5985a..b84c79ed 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -73,8 +73,10 @@ 55C14F9A136F045400649790 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B5F8F609C4CEB300B25A18 /* Security.framework */; }; 55C14FC7136F05E100649790 /* Sparkle.strings in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8220A321A7F00D8810D /* Sparkle.strings */; }; 55E6F33319EC9F6C00005E76 /* SUErrors.h in Headers */ = {isa = PBXBuildFile; fileRef = 55E6F33219EC9F6C00005E76 /* SUErrors.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 5AF6C1E91AE86E270014A3AB /* test archive.zip in Resources */ = {isa = PBXBuildFile; fileRef = 5AF6C1E81AE86E270014A3AB /* test archive.zip */; }; 5AF6C1E51AE86A410014A3AB /* SUPipedUnarchiverTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AF6C1EA1AE870A90014A3AB /* SUPipedUnarchiverTest.m */; }; + 5AF6C1E91AE86E270014A3AB /* test archive.zip in Resources */ = {isa = PBXBuildFile; fileRef = 5AF6C1E81AE86E270014A3AB /* test archive.zip */; }; + 5AF6C74F1AEA46D10014A3AB /* test.sparkle_guided.pkg in Resources */ = {isa = PBXBuildFile; fileRef = 5AF6C74E1AEA46D10014A3AB /* test.sparkle_guided.pkg */; }; + 5AF6C7541AEA49840014A3AB /* SUInstallerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AF6C74C1AEA40760014A3AB /* SUInstallerTest.m */; }; 5AF9DC3C1981DBEE001EA135 /* SUDSAVerifierTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AF9DC3B1981DBEE001EA135 /* SUDSAVerifierTest.m */; }; 5D06E8E90FD68CDB005AE3F6 /* bsdiff.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DB0FD68CB9005AE3F6 /* bsdiff.c */; settings = {COMPILER_FLAGS = "-w"; }; }; 5D06E8EA0FD68CDB005AE3F6 /* SUBinaryDeltaTool.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8E30FD68CC7005AE3F6 /* SUBinaryDeltaTool.m */; }; @@ -415,6 +417,8 @@ 5AEF45D9189D1CC90030D7DC /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/Sparkle.strings; sourceTree = ""; }; 5AF6C1E81AE86E270014A3AB /* test archive.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = "test archive.zip"; sourceTree = ""; }; 5AF6C1EA1AE870A90014A3AB /* SUPipedUnarchiverTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUPipedUnarchiverTest.m; sourceTree = ""; }; + 5AF6C74C1AEA40760014A3AB /* SUInstallerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUInstallerTest.m; sourceTree = ""; }; + 5AF6C74E1AEA46D10014A3AB /* test.sparkle_guided.pkg */ = {isa = PBXFileReference; lastKnownFileType = file; path = test.sparkle_guided.pkg; sourceTree = ""; }; 5AF9DC3B1981DBEE001EA135 /* SUDSAVerifierTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUDSAVerifierTest.m; sourceTree = ""; }; 5D06E8D00FD68C7C005AE3F6 /* BinaryDelta */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = BinaryDelta; sourceTree = BUILT_PRODUCTS_DIR; }; 5D06E8DB0FD68CB9005AE3F6 /* bsdiff.c */ = {isa = PBXFileReference; comments = "-Wno-shorten-64-to-32"; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bsdiff.c; sourceTree = ""; }; @@ -787,6 +791,7 @@ F8761EB21ADC50EB000C9034 /* SparkleTestCodeSignApp.zip */, 5AF6C1E81AE86E270014A3AB /* test archive.zip */, 14958C6C19AEBC610061B14F /* test-pubkey.pem */, + 5AF6C74E1AEA46D10014A3AB /* test.sparkle_guided.pkg */, ); path = Resources; sourceTree = ""; @@ -839,6 +844,7 @@ 142E0E0819A83AAC00E4312B /* SUBinaryDeltaTest.m */, F8761EB01ADC5068000C9034 /* SUCodeSigningVerifierTest.m */, 5AF9DC3B1981DBEE001EA135 /* SUDSAVerifierTest.m */, + 5AF6C74C1AEA40760014A3AB /* SUInstallerTest.m */, 5AF6C1EA1AE870A90014A3AB /* SUPipedUnarchiverTest.m */, 14950074195FDF5900BC5B5B /* SUUpdaterTest.m */, 61227A150DB548B800AB99EA /* SUVersionComparisonTest.m */, @@ -1276,6 +1282,7 @@ F8761EB31ADC50EB000C9034 /* SparkleTestCodeSignApp.zip in Resources */, 5AF6C1E91AE86E270014A3AB /* test archive.zip in Resources */, 14958C6F19AEBC980061B14F /* test-pubkey.pem in Resources */, + 5AF6C74F1AEA46D10014A3AB /* test.sparkle_guided.pkg in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1443,6 +1450,7 @@ 142E0E0919A83AAC00E4312B /* SUBinaryDeltaTest.m in Sources */, F8761EB11ADC5068000C9034 /* SUCodeSigningVerifierTest.m in Sources */, 5AF9DC3C1981DBEE001EA135 /* SUDSAVerifierTest.m in Sources */, + 5AF6C7541AEA49840014A3AB /* SUInstallerTest.m in Sources */, 14652F8219A9746000959E44 /* SULog.m in Sources */, 5AF6C1E51AE86A410014A3AB /* SUPipedUnarchiverTest.m in Sources */, ); diff --git a/Sparkle/SUInstaller.m b/Sparkle/SUInstaller.m index 19d1a718..2513973a 100644 --- a/Sparkle/SUInstaller.m +++ b/Sparkle/SUInstaller.m @@ -44,6 +44,9 @@ static NSString *sUpdateFolder = nil; + (NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host isPackage:(BOOL *)isPackagePtr isGuided:(BOOL *)isGuidedPtr { + NSParameterAssert(inUpdateFolder); + NSParameterAssert(host); + // Search subdirectories for the application NSString *currentFile, *newAppDownloadPath = nil, @@ -111,6 +114,10 @@ static NSString *sUpdateFolder = nil; *isPackagePtr = isPackage; if (isGuidedPtr) *isGuidedPtr = isGuided; + + if (!newAppDownloadPath) { + SULog(@"Searched %@ for %@.(app|pkg)", inUpdateFolder, bundleFileNameNoExtension); + } return newAppDownloadPath; } diff --git a/Tests/Resources/test.sparkle_guided.pkg b/Tests/Resources/test.sparkle_guided.pkg new file mode 100644 index 00000000..f4933a80 Binary files /dev/null and b/Tests/Resources/test.sparkle_guided.pkg differ diff --git a/Tests/SUInstallerTest.m b/Tests/SUInstallerTest.m new file mode 100644 index 00000000..ceee0b6c --- /dev/null +++ b/Tests/SUInstallerTest.m @@ -0,0 +1,65 @@ +// +// SUInstallerTest.m +// Sparkle +// +// Created by Kornel on 24/04/2015. +// Copyright (c) 2015 Sparkle Project. All rights reserved. +// + +#import +#import +#import "SUHost.h" +#import "SUInstaller.h" +#import + +@interface SUInstallerTest : XCTestCase + +@end + +@implementation SUInstallerTest + +- (void)setUp +{ + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown +{ + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testInstallIfRoot +{ + uid_t uid = getuid(); + + if (uid) { + NSLog(@"Test must be run as root: sudo xctest -XCTest SUInstallerTest 'Sparkle Unit Tests.xctest'"); + return; + } + + NSString *expectedDestination = @"/tmp/sparklepkgtest.app"; + NSFileManager *fm = [NSFileManager defaultManager]; + [fm removeItemAtPath:expectedDestination error:nil]; + XCTAssertFalse([fm fileExistsAtPath:expectedDestination isDirectory:nil]); + + XCTestExpectation *done = [self expectationWithDescription:@"install finished"]; + + NSBundle *bundle = [NSBundle bundleForClass:[self class]]; + NSString *path = [bundle pathForResource:@"test.sparkle_guided" ofType:@"pkg"]; + XCTAssertNotNil(path); + + SUHost *host = [[SUHost alloc] initWithBundle:bundle]; + + [SUInstaller installFromUpdateFolder:[path stringByDeletingLastPathComponent] overHost:host installationPath:@"/tmp" versionComparator:nil completionHandler:^(NSError *error) { + XCTAssertNil(error); + XCTAssertTrue([fm fileExistsAtPath:expectedDestination isDirectory:nil]); + [done fulfill]; + }]; + + [self waitForExpectationsWithTimeout:40 handler:nil]; + [fm removeItemAtPath:expectedDestination error:nil]; +} + +@end