Add tests for filtering allowed channels and macOS releases

This commit is contained in:
Zorg committed 2021-06-27 00:28:09 -07:00
1 parent 267f2b82b1
commit 9bb59b8c00
5 files changed
+156 -16

No files matched your search

+4
View File
@@ -188,6 +188,7 @@
723C8A541E2D60DB00C14942 /* SUTouchBarButtonGroup.h in Headers */ = {isa = PBXBuildFile; fileRef = 723C8A521E2D60DB00C14942 /* SUTouchBarButtonGroup.h */; };
723C8A551E2D60DB00C14942 /* SUTouchBarButtonGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = 723C8A531E2D60DB00C14942 /* SUTouchBarButtonGroup.m */; };
723C8A561E2D60DB00C14942 /* SUTouchBarButtonGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = 723C8A531E2D60DB00C14942 /* SUTouchBarButtonGroup.m */; };
723EDC3F26885A8E000BCBA4 /* testappcast_channels.xml in Resources */ = {isa = PBXBuildFile; fileRef = 723EDC3E26885A8E000BCBA4 /* testappcast_channels.xml */; };
72464F701E1F31E000FB341C /* SUOperatingSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */; };
72464F711E1F326A00FB341C /* SUOperatingSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */; };
72464F721E1F327C00FB341C /* SUOperatingSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */; };
@@ -1082,6 +1083,7 @@
723B5DA51CF7AB0100365F95 /* SPUDownloaderProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SPUDownloaderProtocol.h; path = Downloader/SPUDownloaderProtocol.h; sourceTree = SOURCE_ROOT; };
723C8A521E2D60DB00C14942 /* SUTouchBarButtonGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUTouchBarButtonGroup.h; sourceTree = "<group>"; };
723C8A531E2D60DB00C14942 /* SUTouchBarButtonGroup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUTouchBarButtonGroup.m; sourceTree = "<group>"; };
723EDC3E26885A8E000BCBA4 /* testappcast_channels.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = testappcast_channels.xml; sourceTree = "<group>"; };
7246E0A11C83B685003B4E75 /* SPUStandardUpdaterController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUStandardUpdaterController.h; sourceTree = "<group>"; };
7246E0A21C83B685003B4E75 /* SPUStandardUpdaterController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUStandardUpdaterController.m; sourceTree = "<group>"; };
724BB36C1D31D0B7005D534A /* org.sparkle-project.InstallerConnection.xpc */ = {isa = PBXFileReference; explicitFileType = "wrapper.xpc-service"; includeInIndex = 0; path = "org.sparkle-project.InstallerConnection.xpc"; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -1685,6 +1687,7 @@
14958C6C19AEBC610061B14F /* test-pubkey.pem */,
5AF6C74E1AEA46D10014A3AB /* test.pkg */,
5AD0FA7E1C73F2E2004BCEFF /* testappcast.xml */,
723EDC3E26885A8E000BCBA4 /* testappcast_channels.xml */,
725B3A81263FBF0C0041AB8E /* testappcast_minimumAutoupdateVersion.xml */,
722545B526805FF80036465C /* testappcast_info_updates.xml */,
5F1510A11C96E591006E1629 /* testnamespaces.xml */,
@@ -2936,6 +2939,7 @@
files = (
725B3A82263FBF0C0041AB8E /* testappcast_minimumAutoupdateVersion.xml in Resources */,
14958C6E19AEBC950061B14F /* signed-test-file.txt in Resources */,
723EDC3F26885A8E000BCBA4 /* testappcast_channels.xml in Resources */,
72AC6B2E1B9B218C00F62325 /* SparkleTestCodeSignApp.dmg in Resources */,
C23E885B1BE7B24F0050BB73 /* SparkleTestCodeSignApp.enc.dmg in Resources */,
72AC6B281B9AAD6700F62325 /* SparkleTestCodeSignApp.tar in Resources */,
+22 -16
View File
@@ -173,22 +173,7 @@
allowedChannels = [NSSet set];
}
SUAppcast *macOSAppcast = [loadedAppcast copyByFilteringItems:^(SUAppcastItem *item) {
// We will never care about other OS's
BOOL macOSUpdate = [item isMacOsUpdate];
if (!macOSUpdate) {
return NO;
}
NSSet<NSString *> *channels = item.channels;
if (channels.count == 0) {
// Item is on the default channel
return YES;
}
// Item channels and allowed channels must have one channel in common
return [channels intersectsSet:allowedChannels];
}];
SUAppcast *macOSAppcast = [[self class] filterAppcast:loadedAppcast forMacOSAndAllowedChannels:allowedChannels];
id<SUVersionComparison> applicationVersionComparator = [self versionComparator];
@@ -240,6 +225,27 @@
}
}
// This method is used by unit tests
+ (SUAppcast *)filterAppcast:(SUAppcast *)appcast forMacOSAndAllowedChannels:(NSSet<NSString *> *)allowedChannels
{
return [appcast copyByFilteringItems:^(SUAppcastItem *item) {
// We will never care about other OS's
BOOL macOSUpdate = [item isMacOsUpdate];
if (!macOSUpdate) {
return NO;
}
NSSet<NSString *> *channels = item.channels;
if (channels.count == 0) {
// Item is on the default channel
return YES;
}
// Item channels and allowed channels must have one channel in common
return [channels intersectsSet:allowedChannels];
}];
}
// This method is used by unit tests
+ (SUAppcast *)filterSupportedAppcast:(SUAppcast *)appcast phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup skippedUpdate:(SPUSkippedUpdate * _Nullable)skippedUpdate hostVersion:(NSString *)hostVersion versionComparator:(id<SUVersionComparison>)versionComparator testOSVersion:(BOOL)testOSVersion testMinimumAutoupdateVersion:(BOOL)testMinimumAutoupdateVersion
{
+69
View File
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle">
<channel>
<title>For unit test only</title>
<!-- Implicitly no channels -->
<item>
<title>Version 2.0</title>
<description>desc</description>
<pubDate>Sat, 26 Jul 2014 15:20:11 +0000</pubDate>
<enclosure url="http://localhost:1337/Sparkle_Test_App.zip" sparkle:version="2.0" />
<sparkle:criticalUpdate sparkle:version="1.5" />
</item>
<!-- Explicitly no channels -->
<item>
<title>Version 3.0</title>
<sparkle:phasedRolloutInterval>86400</sparkle:phasedRolloutInterval>
<sparkle:tags><sparkle:criticalUpdate /></sparkle:tags>
<enclosure url="http://localhost:1337/Sparkle_Test_App.zip" sparkle:version="3.0" length="1346234" />
<sparkle:deltas>
<enclosure url="http://localhost:1337/3.0_from_2.0.patch"
sparkle:version="3.0"
sparkle:deltaFrom="2.0"
length="1235"
type="application/octet-stream"
sparkle:edSignature="..." />
<enclosure url="http://localhost:1337/3.0_from_1.0.patch"
sparkle:version="3.0"
sparkle:deltaFrom="1.0"
length="1485"
type="application/octet-stream"
sparkle:edSignature="..." />
</sparkle:deltas>
<sparkle:channels>
</sparkle:channels>
</item>
<!-- Beta channel -->
<item>
<title>Version 4.0</title>
<sparkle:version>4.0</sparkle:version>
<pubDate>Sat, 26 Jul 2014 15:20:13 +0000</pubDate>
<enclosure url="http://localhost:1337/Sparkle_Test_App.zip" length="1346234" />
<sparkle:channels>
<sparkle:beta/>
</sparkle:channels>
</item>
<!-- Beta and nightly channel -->
<item>
<title>Version 5.0</title>
<sparkle:version>5.0</sparkle:version>
<enclosure url="http://localhost:1337/Sparkle_Test_App.zip" length="1346234" />
<sparkle:channels>
<sparkle:beta/>
<sparkle:nightly/>
</sparkle:channels>
</item>
<!-- A Windows release -->
<item>
<title>Version 6.0</title>
<sparkle:version>6.0</sparkle:version>
<enclosure url="http://localhost:1337/Sparkle_Test_App.zip" length="1346234" sparkle:os="windows" />
<sparkle:channels>
<sparkle:beta/>
<sparkle:nightly/>
</sparkle:channels>
</item>
</channel>
</rss>
+59
View File
@@ -76,6 +76,65 @@ class SUAppcastTest: XCTestCase {
}
}
func testChannelsAndMacOSReleases() {
let testURL = Bundle(for: SUAppcastTest.self).url(forResource: "testappcast_channels", withExtension: "xml")!
do {
let testData = try Data(contentsOf: testURL)
let versionComparator = SUStandardVersionComparator.default()
let hostVersion = "1.0"
let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator)
let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver)
XCTAssertEqual(5, appcast.items.count)
do {
let filteredAppcast = SUAppcastDriver.filterAppcast(appcast, forMacOSAndAllowedChannels: ["sparkle:beta", "sparkle:nightly"])
XCTAssertEqual(4, filteredAppcast.items.count)
XCTAssertEqual("2.0", filteredAppcast.items[0].versionString)
XCTAssertEqual("3.0", filteredAppcast.items[1].versionString)
XCTAssertEqual("4.0", filteredAppcast.items[2].versionString)
XCTAssertEqual("5.0", filteredAppcast.items[3].versionString)
}
do {
let filteredAppcast = SUAppcastDriver.filterAppcast(appcast, forMacOSAndAllowedChannels: [])
XCTAssertEqual(2, filteredAppcast.items.count)
XCTAssertEqual("2.0", filteredAppcast.items[0].versionString)
XCTAssertEqual("3.0", filteredAppcast.items[1].versionString)
}
do {
let filteredAppcast = SUAppcastDriver.filterAppcast(appcast, forMacOSAndAllowedChannels: ["sparkle:beta"])
XCTAssertEqual(4, filteredAppcast.items.count)
XCTAssertEqual("2.0", filteredAppcast.items[0].versionString)
XCTAssertEqual("3.0", filteredAppcast.items[1].versionString)
XCTAssertEqual("4.0", filteredAppcast.items[2].versionString)
XCTAssertEqual("5.0", filteredAppcast.items[3].versionString)
}
do {
let filteredAppcast = SUAppcastDriver.filterAppcast(appcast, forMacOSAndAllowedChannels: ["sparkle:nightly"])
XCTAssertEqual(3, filteredAppcast.items.count)
XCTAssertEqual("2.0", filteredAppcast.items[0].versionString)
XCTAssertEqual("3.0", filteredAppcast.items[1].versionString)
XCTAssertEqual("5.0", filteredAppcast.items[2].versionString)
}
do {
let filteredAppcast = SUAppcastDriver.filterAppcast(appcast, forMacOSAndAllowedChannels: ["sparkle:madeup"])
XCTAssertEqual("2.0", filteredAppcast.items[0].versionString)
XCTAssertEqual("3.0", filteredAppcast.items[1].versionString)
XCTAssertEqual(2, filteredAppcast.items.count)
}
} catch let err as NSError {
NSLog("%@", err)
XCTFail(err.localizedDescription)
}
}
func testCriticalUpdateVersion() {
let testURL = Bundle(for: SUAppcastTest.self).url(forResource: "testappcast", withExtension: "xml")!
@@ -42,6 +42,8 @@ static const char *SUAppleQuarantineIdentifier = "com.apple.quarantine";
+ (SUAppcast *)filterSupportedAppcast:(SUAppcast *)appcast phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup skippedUpdate:(SPUSkippedUpdate * _Nullable)skippedUpdate hostVersion:(NSString *)hostVersion versionComparator:(id<SUVersionComparison>)versionComparator testOSVersion:(BOOL)testOSVersion testMinimumAutoupdateVersion:(BOOL)testMinimumAutoupdateVersion;
+ (SUAppcast *)filterAppcast:(SUAppcast *)appcast forMacOSAndAllowedChannels:(NSSet<NSString *> *)allowedChannels;
@end
@interface SUBinaryDeltaUnarchiver (Private)