diff --git a/CHANGELOG b/CHANGELOG index b514cb8d..d730c9db 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,15 +1,17 @@ -# 1.14.0 +# 1.14.0 (Mar 11, 2016) +* Disable javascript by default and make it opt-in (Zorg) * URL-encoding of appcast URLs is preserved (Kornel Lesiński) * Delegate is asked for fallback updates if delta update fails (Kornel Lesiński) +* Fixed crash on 10.7 - subscript operator not available (kleuter) * Fixed check of feed URL before delegate had a chance to set it (Kornel Lesiński) * Re-added support for password-protected dmg images (Andrew K. Boyd) * Added warning about ATS blocking (Kornel Lesiński) * Translation fixes for pt-BR. (vitu) * Add some Japanese lozalized strings (1024jp) * Made test app available in all languages #695 (LIU Dongyuan / 柳东原) -* Removed a test resource from the framework bundle (Karl Moskowski) * Czech localizations update (Frantisek Erben) +* Removed a test resource from the framework bundle (Karl Moskowski) * Test if the updated app is the frontmost one (Zorg) * UI Tests for the Test Application (Zorg) diff --git a/Makefile b/Makefile index f46efad9..f27e6e8c 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,8 @@ localizable-strings: release: xcodebuild -scheme Distribution -configuration Release -derivedDataPath "$(BUILDDIR)" build open -R "$(BUILDDIR)/Build/Products/Release/Sparkle-"*.tar.bz2 + cat Sparkle.podspec + @echo "Don't forget to update CocoaPods!" build: xcodebuild clean build diff --git a/Sparkle.podspec b/Sparkle.podspec index 889a31e7..e895c250 100644 --- a/Sparkle.podspec +++ b/Sparkle.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Sparkle" - s.version = "1.13.1" + s.version = "1.14.0" s.summary = "A software update framework for OS X" s.description = "Sparkle is an easy-to-use software update framework for Cocoa developers." s.homepage = "http://sparkle-project.org" diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 18fbe574..696d6bde 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -96,6 +96,7 @@ 5D1AF5900FD767AD0065DB48 /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D1AF58F0FD767AD0065DB48 /* libxml2.dylib */; }; 5D1AF59A0FD767E50065DB48 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D1AF5990FD767E50065DB48 /* libz.dylib */; }; 5D1AF82B0FD768180065DB48 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D1AF5990FD767E50065DB48 /* libz.dylib */; }; + 5F1510A21C96E591006E1629 /* testnamespaces.xml in Resources */ = {isa = PBXBuildFile; fileRef = 5F1510A11C96E591006E1629 /* testnamespaces.xml */; settings = {ASSET_TAGS = (); }; }; 610134730DD250470049ACDF /* SUUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 610134710DD250470049ACDF /* SUUpdateDriver.h */; settings = {ATTRIBUTES = (); }; }; 610134740DD250470049ACDF /* SUUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 610134720DD250470049ACDF /* SUUpdateDriver.m */; }; 6101347B0DD2541A0049ACDF /* SUProbingUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 610134790DD2541A0049ACDF /* SUProbingUpdateDriver.h */; settings = {ATTRIBUTES = (); }; }; @@ -513,6 +514,7 @@ 5D1AF5890FD7678C0065DB48 /* libxar.1.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxar.1.dylib; path = usr/lib/libxar.1.dylib; sourceTree = SDKROOT; }; 5D1AF58F0FD767AD0065DB48 /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = usr/lib/libxml2.dylib; sourceTree = SDKROOT; }; 5D1AF5990FD767E50065DB48 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; }; + 5F1510A11C96E591006E1629 /* testnamespaces.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = testnamespaces.xml; sourceTree = ""; }; 610134710DD250470049ACDF /* SUUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdateDriver.h; sourceTree = ""; }; 610134720DD250470049ACDF /* SUUpdateDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdateDriver.m; sourceTree = ""; }; 610134790DD2541A0049ACDF /* SUProbingUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUProbingUpdateDriver.h; sourceTree = ""; }; @@ -912,6 +914,7 @@ 14958C6C19AEBC610061B14F /* test-pubkey.pem */, 5AF6C74E1AEA46D10014A3AB /* test.sparkle_guided.pkg */, 5AD0FA7E1C73F2E2004BCEFF /* testappcast.xml */, + 5F1510A11C96E591006E1629 /* testnamespaces.xml */, ); path = Resources; sourceTree = ""; @@ -1458,6 +1461,7 @@ buildActionMask = 2147483647; files = ( 14958C6E19AEBC950061B14F /* signed-test-file.txt in Resources */, + 5F1510A21C96E591006E1629 /* testnamespaces.xml in Resources */, 72AC6B2E1B9B218C00F62325 /* SparkleTestCodeSignApp.dmg in Resources */, C23E885B1BE7B24F0050BB73 /* SparkleTestCodeSignApp.enc.dmg in Resources */, 72AC6B281B9AAD6700F62325 /* SparkleTestCodeSignApp.tar in Resources */, diff --git a/Sparkle/Autoupdate/Autoupdate.m b/Sparkle/Autoupdate/Autoupdate.m index ddc60f6c..51b9619a 100644 --- a/Sparkle/Autoupdate/Autoupdate.m +++ b/Sparkle/Autoupdate/Autoupdate.m @@ -247,16 +247,16 @@ int main(int __unused argc, const char __unused *argv[]) NSApplication *application = [NSApplication sharedApplication]; - BOOL shouldShowUI = (args.count > 6) ? [args[6] boolValue] : YES; + BOOL shouldShowUI = (args.count > 6) ? [[args objectAtIndex:6] boolValue] : YES; if (shouldShowUI) { [application activateIgnoringOtherApps:YES]; } - AppInstaller *appInstaller = [[AppInstaller alloc] initWithHostPath:args[1] - relaunchPath:args[2] - parentProcessId:[args[3] intValue] - updateFolderPath:args[4] - shouldRelaunch:(args.count > 5) ? [args[5] boolValue] : YES + AppInstaller *appInstaller = [[AppInstaller alloc] initWithHostPath:[args objectAtIndex:1] + relaunchPath:[args objectAtIndex:2] + parentProcessId:[[args objectAtIndex:3] intValue] + updateFolderPath:[args objectAtIndex:4] + shouldRelaunch:(args.count > 5) ? [[args objectAtIndex:5] boolValue] : YES shouldShowUI:shouldShowUI]; [application setDelegate:appInstaller]; [application run]; diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index 8fc8ad4f..fd79d946 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -178,13 +178,12 @@ dict[name] = encDict; } else if ([name isEqualToString:SURSSElementPubDate]) { - // pubDate is expected to be an NSDate by SUAppcastItem, but the RSS class was returning an NSString - NSString *string = node.stringValue; - if (string) { - NSDate *date = [NSDate dateWithNaturalLanguageString:string]; - if (date) { - dict[name] = date; - } + // We don't want to parse and create a NSDate instance - + // that's a risk we can avoid. We don't use the date anywhere other + // than it being accessible from SUAppcastItem + NSString *dateString = node.stringValue; + if (dateString) { + dict[name] = dateString; } } else if ([name isEqualToString:SUAppcastElementDeltas]) { @@ -230,11 +229,8 @@ return nil; } } - - if ([appcastItems count]) { - NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO]; - [appcastItems sortUsingDescriptors:@[sort]]; - } + + self.items = appcastItems; return appcastItems; } @@ -262,9 +258,9 @@ NSUnderlyingErrorKey: error, }]; - NSURL *failingUrl = error.userInfo[NSURLErrorFailingURLErrorKey]; + NSURL *failingUrl = [error.userInfo objectForKey:NSURLErrorFailingURLErrorKey]; if (failingUrl) { - userInfo[NSURLErrorFailingURLErrorKey] = failingUrl; + [userInfo setObject:failingUrl forKey:NSURLErrorFailingURLErrorKey]; } self.completionBlock([NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastError userInfo:userInfo]); diff --git a/Sparkle/SUAppcastItem.h b/Sparkle/SUAppcastItem.h index 86843bfb..47b6ee48 100644 --- a/Sparkle/SUAppcastItem.h +++ b/Sparkle/SUAppcastItem.h @@ -14,7 +14,7 @@ SU_EXPORT @interface SUAppcastItem : NSObject @property (copy, readonly) NSString *title; -@property (copy, readonly) NSDate *date; +@property (copy, readonly) NSString *dateString; @property (copy, readonly) NSString *itemDescription; @property (strong, readonly) NSURL *releaseNotesURL; @property (copy, readonly) NSString *DSASignature; diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index a98d7afa..972758ba 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -16,7 +16,7 @@ @interface SUAppcastItem () @property (copy, readwrite) NSString *title; -@property (copy, readwrite) NSDate *date; +@property (copy, readwrite) NSString *dateString; @property (copy, readwrite) NSString *itemDescription; @property (strong, readwrite) NSURL *releaseNotesURL; @property (copy, readwrite) NSString *DSASignature; @@ -31,7 +31,7 @@ @end @implementation SUAppcastItem -@synthesize date; +@synthesize dateString; @synthesize deltaUpdates; @synthesize displayVersionString; @synthesize DSASignature; @@ -104,7 +104,7 @@ propertiesDictionary = [[NSMutableDictionary alloc] initWithDictionary:dict]; self.title = dict[SURSSElementTitle]; - self.date = dict[SURSSElementPubDate]; + self.dateString = dict[SURSSElementPubDate]; self.itemDescription = dict[SURSSElementDescription]; NSString *theInfoURL = dict[SURSSElementLink]; diff --git a/Sparkle/SUBasicUpdateDriver.h b/Sparkle/SUBasicUpdateDriver.h index 8c6960d8..301b4bc5 100644 --- a/Sparkle/SUBasicUpdateDriver.h +++ b/Sparkle/SUBasicUpdateDriver.h @@ -24,7 +24,7 @@ - (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)host; - (BOOL)isItemNewer:(SUAppcastItem *)ui; -- (BOOL)hostSupportsItem:(SUAppcastItem *)ui; ++ (BOOL)hostSupportsItem:(SUAppcastItem *)ui; - (BOOL)itemContainsSkippedVersion:(SUAppcastItem *)ui; - (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui; - (void)appcastDidFinishLoading:(SUAppcast *)ac; diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 0243eec5..fefc6a71 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -82,12 +82,28 @@ return comparator; } -- (BOOL)isItemNewer:(SUAppcastItem *)ui ++ (SUAppcastItem *)bestItemFromAppcastItems:(NSArray *)appcastItems getDeltaItem:(SUAppcastItem * __autoreleasing *)deltaItem withHostVersion:(NSString *)hostVersion comparator:(id)comparator { - return [[self versionComparator] compareVersion:[self.host version] toVersion:[ui versionString]] == NSOrderedAscending; + SUAppcastItem *item = nil; + for(SUAppcastItem *candidate in appcastItems) { + if ([[self class] hostSupportsItem:candidate]) { + if (!item || [comparator compareVersion:item.versionString toVersion:candidate.versionString] == NSOrderedAscending) { + item = candidate; + } + } + } + + if (item && deltaItem) { + SUAppcastItem *deltaUpdateItem = [item deltaUpdates][hostVersion]; + if (deltaUpdateItem && [[self class] hostSupportsItem:deltaUpdateItem]) { + *deltaItem = deltaUpdateItem; + } + } + + return item; } -- (BOOL)hostSupportsItem:(SUAppcastItem *)ui ++ (BOOL)hostSupportsItem:(SUAppcastItem *)ui { if (([ui minimumSystemVersion] == nil || [[ui minimumSystemVersion] isEqualToString:@""]) && ([ui maximumSystemVersion] == nil || [[ui maximumSystemVersion] isEqualToString:@""])) { return YES; } @@ -106,6 +122,11 @@ return minimumVersionOK && maximumVersionOK; } +- (BOOL)isItemNewer:(SUAppcastItem *)ui +{ + return [[self versionComparator] compareVersion:[self.host version] toVersion:[ui versionString]] == NSOrderedAscending; +} + - (BOOL)itemContainsSkippedVersion:(SUAppcastItem *)ui { NSString *skippedVersion = [self.host objectForUserDefaultsKey:SUSkippedVersionKey]; @@ -115,7 +136,7 @@ - (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui { - return ui && [self hostSupportsItem:ui] && [self isItemNewer:ui] && ![self itemContainsSkippedVersion:ui]; + return ui && [[self class] hostSupportsItem:ui] && [self isItemNewer:ui] && ![self itemContainsSkippedVersion:ui]; } - (void)appcastDidFinishLoading:(SUAppcast *)ac @@ -139,20 +160,13 @@ } else // If not, we'll take care of it ourselves. { - // Find the first update we can actually use. - for(SUAppcastItem *i in ac.items) { - if ([self hostSupportsItem:i]) { - item = i; - break; - } - } - - if (item) { - SUAppcastItem *deltaUpdateItem = [item deltaUpdates][[self.host version]]; - if (deltaUpdateItem && [self hostSupportsItem:deltaUpdateItem]) { - self.nonDeltaUpdateItem = item; - item = deltaUpdateItem; - } + // Find the best supported update + SUAppcastItem *deltaUpdateItem = nil; + item = [[self class] bestItemFromAppcastItems:ac.items getDeltaItem:&deltaUpdateItem withHostVersion:self.host.version comparator:[self versionComparator]]; + + if (item && deltaUpdateItem) { + self.nonDeltaUpdateItem = item; + item = deltaUpdateItem; } } diff --git a/Sparkle/SUBinaryDeltaCommon.m b/Sparkle/SUBinaryDeltaCommon.m index be3966ce..de247ee5 100644 --- a/Sparkle/SUBinaryDeltaCommon.m +++ b/Sparkle/SUBinaryDeltaCommon.m @@ -231,12 +231,12 @@ BOOL modifyPermissions(NSString *path, mode_t desiredPermissions) if (!attributes) { return NO; } - NSNumber *permissions = attributes[NSFilePosixPermissions]; + NSNumber *permissions = [attributes objectForKey:NSFilePosixPermissions]; if (!permissions) { return NO; } mode_t newMode = ([permissions unsignedShortValue] & ~PERMISSION_FLAGS) | desiredPermissions; - int (*changeModeFunc)(const char *, mode_t) = [attributes[NSFileType] isEqualToString:NSFileTypeSymbolicLink] ? lchmod : chmod; + int (*changeModeFunc)(const char *, mode_t) = [[attributes objectForKey:NSFileType] isEqualToString:NSFileTypeSymbolicLink] ? lchmod : chmod; if (changeModeFunc([path fileSystemRepresentation], newMode) != 0) { return NO; } diff --git a/Sparkle/SUFileManager.m b/Sparkle/SUFileManager.m index be5ef09b..d0fc3b00 100644 --- a/Sparkle/SUFileManager.m +++ b/Sparkle/SUFileManager.m @@ -151,7 +151,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } if (isDirectory != NULL) { - *isDirectory = [attributes[NSFileType] isEqualToString:NSFileTypeDirectory]; + *isDirectory = [[attributes objectForKey:NSFileType] isEqualToString:NSFileTypeDirectory]; } return YES; @@ -267,7 +267,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { // root-level symbolic link. NSString *rootURLPath = rootURL.path; NSDictionary *rootAttributes = [_fileManager attributesOfItemAtPath:rootURLPath error:nil]; - NSString *rootType = rootAttributes[NSFileType]; + NSString *rootType = [rootAttributes objectForKey:NSFileType]; // 10.7 can't subscript this if ([rootType isEqualToString:NSFileTypeDirectory]) { // The NSDirectoryEnumerator will avoid recursing into any contained @@ -595,7 +595,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { return NO; } - NSNumber *ownerID = matchFileAttributes[NSFileOwnerAccountID]; + NSNumber *ownerID = [matchFileAttributes objectForKey:NSFileOwnerAccountID]; if (ownerID == nil) { // shouldn't be possible to error here, but just in case if (error != NULL) { @@ -604,7 +604,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { return NO; } - NSNumber *groupID = matchFileAttributes[NSFileGroupOwnerAccountID]; + NSNumber *groupID = [matchFileAttributes objectForKey:NSFileGroupOwnerAccountID]; if (groupID == nil) { // shouldn't be possible to error here, but just in case if (error != NULL) { @@ -613,8 +613,8 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { return NO; } - NSNumber *targetOwnerID = targetFileAttributes[NSFileOwnerAccountID]; - NSNumber *targetGroupID = targetFileAttributes[NSFileGroupOwnerAccountID]; + NSNumber *targetOwnerID = [targetFileAttributes objectForKey:NSFileOwnerAccountID]; + NSNumber *targetGroupID = [targetFileAttributes objectForKey:NSFileGroupOwnerAccountID]; if ((targetOwnerID != nil && [ownerID isEqualToNumber:targetOwnerID]) && (targetGroupID != nil && [groupID isEqualToNumber:targetGroupID])) { // Assume they're the same even if we don't check every file recursively diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index c49ba368..00ba50d1 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -79,7 +79,7 @@ NSArray *cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *cachePath = nil; if ([cachePaths count]) { - cachePath = cachePaths[0]; + cachePath = [cachePaths objectAtIndex:0]; } if (!cachePath) { SULog(@"Failed to find user's cache directory! Using system default"); diff --git a/Sparkle/SUOperatingSystem.m b/Sparkle/SUOperatingSystem.m index 85c18ebc..d9f1e90a 100644 --- a/Sparkle/SUOperatingSystem.m +++ b/Sparkle/SUOperatingSystem.m @@ -20,10 +20,11 @@ { NSOperatingSystemVersion version = { 0, 0, 0 }; NSURL *coreServices = [[NSFileManager defaultManager] URLForDirectory:NSCoreServiceDirectory inDomain:NSSystemDomainMask appropriateForURL:nil create:NO error:nil]; - NSArray *components = [[NSDictionary dictionaryWithContentsOfURL:[coreServices URLByAppendingPathComponent:@"SystemVersion.plist"]][@"ProductVersion"] componentsSeparatedByString:@"."]; - version.majorVersion = components.count > 0 ? [components[0] integerValue] : 0; - version.minorVersion = components.count > 1 ? [components[1] integerValue] : 0; - version.patchVersion = components.count > 2 ? [components[2] integerValue] : 0; + NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfURL:[coreServices URLByAppendingPathComponent:@"SystemVersion.plist"]]; + NSArray *components = [ [dictionary objectForKey: @"ProductVersion"] componentsSeparatedByString:@"."]; + version.majorVersion = components.count > 0 ? [ [components objectAtIndex:0] integerValue] : 0; + version.minorVersion = components.count > 1 ? [ [components objectAtIndex:1] integerValue] : 0; + version.patchVersion = components.count > 2 ? [ [components objectAtIndex:2] integerValue] : 0; return version; } #endif diff --git a/Sparkle/SUPipedUnarchiver.m b/Sparkle/SUPipedUnarchiver.m index 7317143d..dc0b5192 100644 --- a/Sparkle/SUPipedUnarchiver.m +++ b/Sparkle/SUPipedUnarchiver.m @@ -62,7 +62,8 @@ SULog(@"Extracting using '%@' '%@' < '%@' '%@'", command, [args componentsJoinedByString:@"' '"], self.archivePath, destination); // Get the file size. - NSUInteger expectedLength = [[[NSFileManager defaultManager] attributesOfItemAtPath:self.archivePath error:nil][NSFileSize] unsignedIntegerValue]; + NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:self.archivePath error:nil]; + NSUInteger expectedLength = [[attributes objectForKey:NSFileSize] unsignedIntegerValue]; if (expectedLength > 0) { NSFileHandle *archiveInput = [NSFileHandle fileHandleForReadingAtPath:self.archivePath]; diff --git a/Sparkle/SUSystemProfiler.m b/Sparkle/SUSystemProfiler.m index 230c808f..4071da6b 100644 --- a/Sparkle/SUSystemProfiler.m +++ b/Sparkle/SUSystemProfiler.m @@ -115,7 +115,7 @@ static NSString *const SUSystemProfilerPreferredLanguageKey = @"lang"; error = sysctlbyname("hw.model", cpuModel, &length, NULL, 0); if (error == 0) { NSString *rawModelName = @(cpuModel); - NSString *visibleModelName = modelTranslation[rawModelName]; + NSString *visibleModelName = [modelTranslation objectForKey:rawModelName]; if (visibleModelName == nil) { visibleModelName = rawModelName; } @@ -135,7 +135,7 @@ static NSString *const SUSystemProfilerPreferredLanguageKey = @"lang"; NSUserDefaults *defs = [NSUserDefaults standardUserDefaults]; NSArray *languages = [defs objectForKey:@"AppleLanguages"]; if ([languages count] > 0) { - [profileArray addObject:[NSDictionary dictionaryWithObjects:@[SUSystemProfilerPreferredLanguageKey, @"Preferred Language", languages[0], languages[0]] forKeys:profileDictKeys]]; + [profileArray addObject:[NSDictionary dictionaryWithObjects:@[SUSystemProfilerPreferredLanguageKey, @"Preferred Language", [languages objectAtIndex:0], [languages objectAtIndex:0]] forKeys:profileDictKeys]]; } // Application sending the request diff --git a/Sparkle/SUUserInitiatedUpdateDriver.m b/Sparkle/SUUserInitiatedUpdateDriver.m index d1e0c9a6..04e96b23 100644 --- a/Sparkle/SUUserInitiatedUpdateDriver.m +++ b/Sparkle/SUUserInitiatedUpdateDriver.m @@ -81,7 +81,7 @@ - (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui { // We don't check to see if this update's been skipped, because the user explicitly *asked* if he had the latest version. - return [self hostSupportsItem:ui] && [self isItemNewer:ui]; + return [[self class] hostSupportsItem:ui] && [self isItemNewer:ui]; } @end diff --git a/Tests/Resources/testappcast.xml b/Tests/Resources/testappcast.xml index cc1297b4..e3894b41 100644 --- a/Tests/Resources/testappcast.xml +++ b/Tests/Resources/testappcast.xml @@ -1,18 +1,45 @@ - + For unit test only Version 2.0 desc Sat, 26 Jul 2014 15:20:11 +0000 - + + Version 3.0 - Sat, 26 Jul 2014 15:20:12 +0000 - https://sparkle-project.org/#works - + + + + + + + + + + Version 4.0 + Sat, 26 Jul 2014 15:20:13 +0000 + + 17.0.0 + + + + Version 5.0 + + 2.0.0 diff --git a/Tests/Resources/testnamespaces.xml b/Tests/Resources/testnamespaces.xml new file mode 100644 index 00000000..94f5f1de --- /dev/null +++ b/Tests/Resources/testnamespaces.xml @@ -0,0 +1,18 @@ + + + + For unit test only + + Version 3.0 + Sat, 26 Jul 2014 15:20:12 +0000 + https://sparkle-project.org/#works + + + + Version 2.0 + desc + Sat, 26 Jul 2014 15:20:11 +0000 + + + + diff --git a/Tests/SUAppcastTest.swift b/Tests/SUAppcastTest.swift index a211b46f..113ce751 100644 --- a/Tests/SUAppcastTest.swift +++ b/Tests/SUAppcastTest.swift @@ -20,16 +20,68 @@ class SUAppcastTest: XCTestCase { do { let items = try appcast.parseAppcastItemsFromXMLFile(testFileUrl) as! [SUAppcastItem]; - XCTAssertEqual(2, items.count); - XCTAssertEqual("Version 3.0", items[0].title); - XCTAssertNil(items[0].itemDescription); + XCTAssertEqual(4, items.count); + XCTAssertEqual("Version 2.0", items[0].title); + XCTAssertEqual("desc", items[0].itemDescription); + XCTAssertEqual("Sat, 26 Jul 2014 15:20:11 +0000", items[0].dateString) + + // This is the best release matching our system version + XCTAssertEqual("Version 3.0", items[1].title); + XCTAssertNil(items[1].itemDescription); + XCTAssertNil(items[1].dateString) + + XCTAssertEqual("Version 4.0", items[2].title); + XCTAssertNil(items[2].itemDescription); + XCTAssertEqual("Sat, 26 Jul 2014 15:20:13 +0000", items[2].dateString) + + XCTAssertEqual("Version 5.0", items[3].title); + XCTAssertNil(items[3].itemDescription); + XCTAssertNil(items[3].dateString) + + // Test best appcast item & a delta update item + var deltaItem: SUAppcastItem? = nil + let bestAppcastItem = SUBasicUpdateDriver.bestItemFromAppcastItems(items, getDeltaItem: &deltaItem, withHostVersion: "1.0", comparator: SUStandardVersionComparator.defaultComparator()) + + XCTAssertEqual(bestAppcastItem, items[1]) + XCTAssertEqual(deltaItem!.fileURL.lastPathComponent, "3.0_from_1.0.patch") + + // Test latest delta update item available + var latestDeltaItem: SUAppcastItem? = nil + SUBasicUpdateDriver.bestItemFromAppcastItems(items, getDeltaItem: &latestDeltaItem, withHostVersion: "2.0", comparator: SUStandardVersionComparator.defaultComparator()) + + XCTAssertEqual(latestDeltaItem!.fileURL.lastPathComponent, "3.0_from_2.0.patch") + + // Test a delta item that does not exist + var nonexistantDeltaItem: SUAppcastItem? = nil + SUBasicUpdateDriver.bestItemFromAppcastItems(items, getDeltaItem: &nonexistantDeltaItem, withHostVersion: "2.1", comparator: SUStandardVersionComparator.defaultComparator()) + + XCTAssertNil(nonexistantDeltaItem) + } catch let err as NSError { + NSLog("%@", err); + XCTFail(err.localizedDescription); + } + } + + func testNamespaces() { + let appcast = SUAppcast(); + let testFile = NSBundle(forClass: SUAppcastTest.self).pathForResource("testnamespaces", ofType: "xml")!; + let testFileUrl = NSURL(fileURLWithPath: testFile); + XCTAssertNotNil(testFileUrl); + + do { + let items = try appcast.parseAppcastItemsFromXMLFile(testFileUrl) as! [SUAppcastItem]; + + XCTAssertEqual(2, items.count); + XCTAssertEqual("Version 2.0", items[1].title); XCTAssertEqual("desc", items[1].itemDescription); + XCTAssertNotNil(items[0].releaseNotesURL); XCTAssertEqual("https://sparkle-project.org/#works", items[0].releaseNotesURL!.absoluteString); } catch let err as NSError { NSLog("%@", err); XCTFail(err.localizedDescription); } } + } diff --git a/Tests/SUCodeSigningVerifierTest.m b/Tests/SUCodeSigningVerifierTest.m index 95e394f0..a2b7e764 100644 --- a/Tests/SUCodeSigningVerifierTest.m +++ b/Tests/SUCodeSigningVerifierTest.m @@ -69,6 +69,10 @@ NSError *error = nil; NSString *tempDir = [self.notSignedAppPath stringByDeletingLastPathComponent]; NSString *signedAndValid = [tempDir stringByAppendingPathComponent:@"valid-signed.app"]; + + if ([[NSFileManager defaultManager] fileExistsAtPath:signedAndValid]) { + [[NSFileManager defaultManager] removeItemAtPath:signedAndValid error:NULL]; + } if ([[NSFileManager defaultManager] copyItemAtPath:self.notSignedAppPath toPath:signedAndValid error:&error]) { self.validSignedAppPath = signedAndValid; if (![self codesignAppPath:self.validSignedAppPath]) { @@ -85,6 +89,10 @@ NSError *error = nil; NSString *tempDir = [self.notSignedAppPath stringByDeletingLastPathComponent]; NSString *signedAndInvalid = [tempDir stringByAppendingPathComponent:@"invalid-signed.app"]; + + if ([[NSFileManager defaultManager] fileExistsAtPath:signedAndInvalid]) { + [[NSFileManager defaultManager] removeItemAtPath:signedAndInvalid error:NULL]; + } if ([[NSFileManager defaultManager] copyItemAtPath:self.notSignedAppPath toPath:signedAndInvalid error:&error]) { self.invalidSignedAppPath = signedAndInvalid; if ([self codesignAppPath:self.invalidSignedAppPath]) { diff --git a/Tests/Sparkle Unit Tests-Bridging-Header.h b/Tests/Sparkle Unit Tests-Bridging-Header.h index 512f4a58..d08dafb8 100644 --- a/Tests/Sparkle Unit Tests-Bridging-Header.h +++ b/Tests/Sparkle Unit Tests-Bridging-Header.h @@ -8,6 +8,9 @@ #import "SUFileManager.h" #import "SUAppcast.h" #import "SUAppcastItem.h" +#import "SUBasicUpdateDriver.h" +#import "SUVersionComparisonProtocol.h" +#import "SUStandardVersionComparator.h" // Duplicated to avoid exporting a private symbol from SUFileManager static const char *SUAppleQuarantineIdentifier = "com.apple.quarantine"; @@ -23,6 +26,12 @@ static const char *SUAppleQuarantineIdentifier = "com.apple.quarantine"; @end +@interface SUBasicUpdateDriver (Private) + ++ (SUAppcastItem *)bestItemFromAppcastItems:(NSArray *)appcastItems getDeltaItem:(SUAppcastItem * __autoreleasing *)deltaItem withHostVersion:(NSString *)hostVersion comparator:(id)comparator; + +@end + @interface SUAppcast (Private) - (NSArray *)parseAppcastItemsFromXMLFile:(NSURL *)appcastFile error:(NSError *__autoreleasing*)errorp;