mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-22 04:30:47 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
021950a5b2 | ||
|
|
2ff0da4f15 | ||
|
|
945968a0ef | ||
|
|
1e4f126f7e | ||
|
|
f47115d81f | ||
|
|
49781561f3 | ||
|
|
1587dd1dc3 | ||
|
|
c0b9eaaa0e | ||
|
|
91ac90ffcf | ||
|
|
8375922755 | ||
|
|
9dec304f64 | ||
|
|
8acd915b7b | ||
|
|
eb36100388 | ||
|
|
fb22a01a08 | ||
|
|
9a32766aeb | ||
|
|
fc468771c1 | ||
|
|
42dbf94738 | ||
|
|
86a0ca3883 | ||
|
|
ddb53f330d | ||
|
|
9dbaae64f1 | ||
|
|
d2f4687333 | ||
|
|
143045d673 | ||
|
|
d67351cb62 | ||
|
|
07d2897250 | ||
|
|
625c942561 | ||
|
|
bb299d075b | ||
|
|
73229f84f7 | ||
|
|
8152516b7f | ||
|
|
96baf2b2ce | ||
|
|
ed5dca3423 | ||
|
|
3a5c620b60 | ||
|
|
23ae527b96 | ||
|
|
2268f96759 | ||
|
|
898e063b4f | ||
|
|
e8f88bf0f1 | ||
|
|
a3407a2dbf | ||
|
|
88933a1e65 | ||
|
|
c3d8e4bbc5 | ||
|
|
f70c2a15b1 | ||
|
|
4eb518de7e | ||
|
|
5b2ce958bd | ||
|
|
077c64419f | ||
|
|
1195d4b5d2 | ||
|
|
c7a7704f3b | ||
|
|
64af6d04c2 | ||
|
|
0af27ea783 | ||
|
|
c36413ce46 | ||
|
|
13b9081873 | ||
|
|
3dccca8044 | ||
|
|
e28c62244a | ||
|
|
fec76fee12 | ||
|
|
ed3eab64d2 | ||
|
|
ee257c4070 | ||
|
|
bfec7a82c0 | ||
|
|
4cd472abe6 | ||
|
|
39268a13e5 | ||
|
|
4864dfb5aa | ||
|
|
71125e3d16 | ||
|
|
779d16e5a7 | ||
|
|
ee2e7fb46b | ||
|
|
d350cf33e0 | ||
|
|
09889d01b1 | ||
|
|
6437e0448a |
No files matched your search
+1
-3
@@ -1,7 +1,5 @@
|
||||
language: objective-c
|
||||
osx_image: xcode7
|
||||
osx_image: xcode8
|
||||
before_install:
|
||||
- brew update
|
||||
- brew install macmade/tap/xcode-coveralls
|
||||
script: make ci
|
||||
after_success: xcode-coveralls --exclude /Applications --exclude Tests --exclude Vendor build/Build/Intermediates/Sparkle.build/Coverage/Sparkle.build/Objects-normal/x86_64
|
||||
@@ -23,6 +23,8 @@
|
||||
* Removed SUEnableAutomaticChecksKeyOld and SUCheckAtStartup constants (Eitot)
|
||||
* Updated Sparkle framework headers to use modules if modules are available (B. Kevin Hardman)
|
||||
* Fixed warnings, fixed uses of SULocalizedString (Jerry Krinock)
|
||||
* Improved signing verifier to take any host and s/application/bundle/ (Zorg)
|
||||
* Improved Spotlight updates after delta extraction (Zorg)
|
||||
|
||||
# 1.14.0 (Mar 11, 2016)
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
||||
nationality, personal appearance, race, religion, or sexual identity and
|
||||
orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at kornel+sparkle@geekhood.net. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
||||
@@ -17,7 +17,7 @@ SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME = 0
|
||||
|
||||
SPARKLE_VERSION_MAJOR = 1
|
||||
SPARKLE_VERSION_MINOR = 15
|
||||
SPARKLE_VERSION_PATCH = 0
|
||||
SPARKLE_VERSION_PATCH = 1
|
||||
SPARKLE_VERSION = $(SPARKLE_VERSION_MAJOR).$(SPARKLE_VERSION_MINOR).$(SPARKLE_VERSION_PATCH)
|
||||
|
||||
CURRENT_PROJECT_VERSION = $(SPARKLE_VERSION)
|
||||
@@ -36,8 +36,11 @@ GCC_PREPROCESSOR_DEFINITIONS_COMMON = SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NA
|
||||
|
||||
CLANG_ENABLE_OBJC_ARC = YES
|
||||
GCC_ENABLE_PASCAL_STRINGS = NO
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
COMBINE_HIDPI_IMAGES = NO;
|
||||
|
||||
// Enable warnings
|
||||
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
|
||||
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES
|
||||
CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES
|
||||
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
SWIFT_VERSION = 3.0
|
||||
@@ -0,0 +1 @@
|
||||
SWIFT_OPTIMIZATION_LEVEL = -Onone
|
||||
@@ -0,0 +1 @@
|
||||
SWIFT_OPTIMIZATION_LEVEL = -Ofast
|
||||
@@ -1,5 +1,7 @@
|
||||
// UI Test only
|
||||
|
||||
#include "ConfigSwift.xcconfig"
|
||||
|
||||
INFOPLIST_FILE = UITests/UITests-Info.plist
|
||||
WRAPPER_EXTENSION = xctest
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
#include "ConfigUITest.xcconfig"
|
||||
#include "ConfigSwiftDebug.xcconfig"
|
||||
@@ -1 +1,2 @@
|
||||
#include "ConfigUITest.xcconfig"
|
||||
#include "ConfigSwiftRelease.xcconfig"
|
||||
@@ -1,5 +1,7 @@
|
||||
// Unit Test only
|
||||
|
||||
#include "ConfigSwift.xcconfig"
|
||||
|
||||
INFOPLIST_FILE = Tests/SparkleTests-Info.plist
|
||||
WRAPPER_EXTENSION = xctest
|
||||
OTHER_CFLAGS = $(inherited) -iframework"$(DEVELOPER_FRAMEWORKS_DIR)" -iframework"$(PLATFORM_DIR)/Developer/Library/Frameworks"
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
#include "ConfigUnitTest.xcconfig"
|
||||
#include "ConfigSwiftDebug.xcconfig"
|
||||
@@ -1 +1,2 @@
|
||||
#include "ConfigUnitTest.xcconfig"
|
||||
#include "ConfigSwiftRelease.xcconfig"
|
||||
@@ -13,14 +13,20 @@ if [ -z "$SRCROOT" ] || \
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the current Git master hash
|
||||
version=$(cd "$SRCROOT" ; git show-ref --abbrev heads/master | awk '{print $1}')
|
||||
if [ -z "$version" ] ; then
|
||||
echo "$0: Can't find a Git hash!" 1>&2
|
||||
version="$CURRENT_PROJECT_VERSION"
|
||||
|
||||
# Get version in format 1.x.x-commits-hash
|
||||
gitversion=$( cd "$SRCROOT"; git describe --tags --match '[12].*' || true )
|
||||
if [ -z "$gitversion" ] ; then
|
||||
echo "$0: Can't find a Git hash!" 1>&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
version="$CURRENT_PROJECT_VERSION git-$version"
|
||||
# remove everything before the first "-" to keep the hash part only
|
||||
versionsuffix=${gitversion#*-};
|
||||
if [ "$versionsuffix" != "$gitversion" ]; then
|
||||
version="$version $versionsuffix"
|
||||
fi
|
||||
|
||||
# and use it to set the CFBundleShortVersionString value
|
||||
export PATH="$PATH:/usr/libexec"
|
||||
|
||||
@@ -14,7 +14,7 @@ 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!"
|
||||
@echo "Don't forget to update CocoaPods! pod trunk push"
|
||||
|
||||
build:
|
||||
xcodebuild clean build
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
# To update the icon run make -f Makefile-icon
|
||||
# Requires:
|
||||
# autoconf, automake, libtool, pkg-config, pngquant
|
||||
|
||||
ICONDIR=./Resources/Images.xcassets/AppIcon.appiconset
|
||||
OPTIMIZEDICONS=$(ICONDIR)/optimized_16x16.png $(ICONDIR)/optimized_32x32.png $(ICONDIR)/optimized_128x128.png $(ICONDIR)/optimized_512x512.png
|
||||
DESTICON=Resources/AppIcon.icns
|
||||
|
||||
all: $(DESTICON)
|
||||
|
||||
libicns:
|
||||
git clone https://github.com/pornel/libicns.git
|
||||
|
||||
libicns/Makefile: libicns
|
||||
( cd libicns && autoreconf -vif && ./configure )
|
||||
|
||||
libicns/icnsutils/png2icns: libicns/Makefile
|
||||
( cd libicns && make -j8 )
|
||||
|
||||
optimized_%.png: icon_%.png
|
||||
pngquant -s1 -f -o $@ $<
|
||||
|
||||
$(DESTICON): libicns/icnsutils/png2icns $(OPTIMIZEDICONS)
|
||||
./libicns/icnsutils/png2icns $@ $(OPTIMIZEDICONS)
|
||||
+9
-5
@@ -1,4 +1,4 @@
|
||||
# Sparkle [](https://travis-ci.org/sparkle-project/Sparkle) [](https://coveralls.io/github/sparkle-project/Sparkle?branch=master) [](https://github.com/Carthage/Carthage) []() <a href="https://www.maxcdn.com/?utm_source=sparkle-github&utm_medium=badge&utm_campaign=readme"><img src="https://img.shields.io/badge/sponsored%20by-MaxCDN-orange.svg" alt="sponsored by: MaxCDN"></a>
|
||||
# Sparkle [](https://travis-ci.org/sparkle-project/Sparkle) [](https://github.com/Carthage/Carthage) []() <a href="https://www.stackpath.com/?utm_source=sparkle-github&utm_medium=badge&utm_campaign=readme"><img src="https://img.shields.io/badge/sponsored%20by-StackPath-orange.svg" alt="sponsored by: StackPath"></a>
|
||||
|
||||
An easy-to-use software update framework for Cocoa developers.
|
||||
|
||||
@@ -7,8 +7,8 @@ An easy-to-use software update framework for Cocoa developers.
|
||||
## Changes since 1.5b
|
||||
|
||||
* Up-to-date with 10.11 SDK and Xcode 7. Supports macOS 10.7+.
|
||||
* Important security fixes.
|
||||
* Cleaned up and modernized code, using ARC and Autolayout.
|
||||
* Merged bugfixes, security fixes and some features from multiple Sparkle forks.
|
||||
* Truly automatic background updates (no UI at all) when user agreed to "Automatically download and install updates in the future."
|
||||
* Ability to mark updates as critical.
|
||||
* Progress and status notifications for the host app.
|
||||
@@ -17,15 +17,15 @@ An easy-to-use software update framework for Cocoa developers.
|
||||
|
||||
## Features
|
||||
|
||||
* Seamless integration—there's no mention of Sparkle; your icons and app name are used.
|
||||
* True self-updating—the user can choose to automatically download and install all updates.
|
||||
* Displays a detailed progress window to the user.
|
||||
* Supports authentication for installing in secure locations.
|
||||
* Supports Apple Code Signing and DSA signatures for ultra-secure updates.
|
||||
* Easy to install. Sparkle requires no code in your app, so it's trivial to upgrade or remove the framework.
|
||||
* Uses appcasts for release information. Appcasts are supported by 3rd party update-tracking programs and websites.
|
||||
* Uses RSS-based appcasts for release information. Appcasts are supported by 3rd party update-tracking programs and websites.
|
||||
* Displays release notes to the user via WebKit.
|
||||
* Sparkle doesn't bug the user until second launch for better first impressions.
|
||||
* Seamless integration—there's no mention of Sparkle; your icons and app name are used.
|
||||
* Deep delegate support to make Sparkle work exactly as you need.
|
||||
* Optionally sends system information to the server when checking for updates.
|
||||
* Supports bundles, preference panes, plugins, and other non-.app software. Can install .pkg files for more complicated products.
|
||||
@@ -48,6 +48,10 @@ If you are adding a symbol to the public API you must decorate the declaration w
|
||||
|
||||
Alternatively, build the Distribution scheme in the Xcode UI.
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
We pledge to have an open and welcoming environment. See our [Code of Conduct](CODE_OF_CONDUCT.md).
|
||||
|
||||
## Project Sponsor
|
||||
|
||||
[MaxCDN](https://www.maxcdn.com/?utm_source=sparkle-github&utm_medium=link&utm_campaign=readme-footer)
|
||||
[StackPath](https://www.stackpath.com/?utm_source=sparkle-github&utm_medium=link&utm_campaign=readme-footer)
|
||||
Binary file not shown.
+6
-5
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "Sparkle"
|
||||
s.version = "1.14.0"
|
||||
s.version = "1.15.1"
|
||||
s.summary = "A software update framework for macOS"
|
||||
s.description = "Sparkle is an easy-to-use software update framework for Cocoa developers."
|
||||
s.homepage = "http://sparkle-project.org"
|
||||
@@ -11,15 +11,16 @@ Pod::Spec.new do |s|
|
||||
:file => 'LICENSE'
|
||||
}
|
||||
s.authors = {
|
||||
'Andy Matuschak' => 'andy@andymatuschak.org',
|
||||
'Kornel Lesiński' => 'pornel@pornel.net',
|
||||
'C.W. Betts' => 'computers57@hotmail.com',
|
||||
'Jake Petroules' => 'jake.petroules@petroules.com',
|
||||
'Mayur Pawashe' => 'zorgiepoo@gmail.com',
|
||||
'Kornel Lesiński' => 'pornel@pornel.net',
|
||||
'Jake Petroules' => 'jake.petroules@petroules.com',
|
||||
'C.W. Betts' => 'computers57@hotmail.com',
|
||||
'Andy Matuschak' => 'andy@andymatuschak.org',
|
||||
}
|
||||
|
||||
s.platform = :osx, '10.7'
|
||||
s.source = { :http => "https://github.com/sparkle-project/Sparkle/releases/download/#{s.version}/Sparkle-#{s.version}.tar.bz2" }
|
||||
s.source_files = 'Sparkle.framework/Versions/A/Headers/*.h'
|
||||
|
||||
s.public_header_files = 'Sparkle.framework/Versions/A/Headers/*.h'
|
||||
s.vendored_frameworks = 'Sparkle.framework'
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
1420DF50196247F900203BB0 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1420DF4F196247F900203BB0 /* Images.xcassets */; };
|
||||
1420DF51196247F900203BB0 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1420DF4F196247F900203BB0 /* Images.xcassets */; };
|
||||
142E0E0019A6954400E4312B /* Sparkle.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
142E0E0219A6A14700E4312B /* Sparkle.framework in Copy Files */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
142E0E0419A6A26F00E4312B /* Autoupdate.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = 55C14BB7136EEF1500649790 /* Autoupdate.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
|
||||
@@ -78,6 +77,7 @@
|
||||
5AD0FA7F1C73F2E2004BCEFF /* testappcast.xml in Resources */ = {isa = PBXBuildFile; fileRef = 5AD0FA7E1C73F2E2004BCEFF /* testappcast.xml */; };
|
||||
5AE459001C34118500E3BB47 /* SUUpdaterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 14950074195FDF5900BC5B5B /* SUUpdaterTest.m */; };
|
||||
5AE459021C34118500E3BB47 /* SUVersionComparisonTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 61227A150DB548B800AB99EA /* SUVersionComparisonTest.m */; };
|
||||
5AE7E1111DC81AD3009C2C12 /* AppIcon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 5AE7E10E1DC81ACA009C2C12 /* AppIcon.icns */; };
|
||||
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 */; };
|
||||
@@ -167,7 +167,6 @@
|
||||
61F83F720DBFE140006FDD30 /* SUBasicUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 61F83F700DBFE137006FDD30 /* SUBasicUpdateDriver.m */; };
|
||||
61F83F740DBFE141006FDD30 /* SUBasicUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61F83F6F0DBFE137006FDD30 /* SUBasicUpdateDriver.h */; settings = {ATTRIBUTES = (); }; };
|
||||
61FA52880E2D9EA400EF58AD /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* Sparkle.framework */; settings = {ATTRIBUTES = (Required, ); }; };
|
||||
720B16441C66433D006985FB /* UITests-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 720B16421C66433D006985FB /* UITests-Info.plist */; };
|
||||
720B16451C66433D006985FB /* SUTestApplicationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 720B16431C66433D006985FB /* SUTestApplicationTest.swift */; };
|
||||
7210C7681B9A9A1500EB90AC /* SUUnarchiverTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7210C7671B9A9A1500EB90AC /* SUUnarchiverTest.swift */; };
|
||||
721BC2111D1DFF05002BC71E /* SUFileOperationConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 722954C31D04E66F00ECF9CA /* SUFileOperationConstants.m */; };
|
||||
@@ -189,6 +188,7 @@
|
||||
722954CA1D04EA6000ECF9CA /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */; };
|
||||
722954CB1D04EA6900ECF9CA /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B5F8F609C4CEB300B25A18 /* Security.framework */; };
|
||||
722954CC1D04EA7000ECF9CA /* SUOperatingSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */; };
|
||||
723A920E1D722438004A9DED /* SUSpotlightImporterTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 723A920D1D722438004A9DED /* SUSpotlightImporterTest.swift */; };
|
||||
723B252D1CEAB3A600909873 /* bscommon.c in Sources */ = {isa = PBXBuildFile; fileRef = 723B252B1CEAB3A600909873 /* bscommon.c */; };
|
||||
723B252E1CEAB3A600909873 /* bscommon.c in Sources */ = {isa = PBXBuildFile; fileRef = 723B252B1CEAB3A600909873 /* bscommon.c */; };
|
||||
723B252F1CEAB3A600909873 /* bscommon.c in Sources */ = {isa = PBXBuildFile; fileRef = 723B252B1CEAB3A600909873 /* bscommon.c */; };
|
||||
@@ -205,6 +205,8 @@
|
||||
7275F9C11B5F1F2900B1D19E /* SUFileManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 7275F9BF1B5F1F2900B1D19E /* SUFileManager.h */; };
|
||||
7275F9C21B5F1F2900B1D19E /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7275F9C01B5F1F2900B1D19E /* SUFileManager.m */; };
|
||||
7275F9C31B5F1F2900B1D19E /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7275F9C01B5F1F2900B1D19E /* SUFileManager.m */; };
|
||||
729924731DF3478A00DBCDF5 /* SUUpdateValidator.h in Headers */ = {isa = PBXBuildFile; fileRef = 729924711DF3478A00DBCDF5 /* SUUpdateValidator.h */; };
|
||||
729924741DF3478A00DBCDF5 /* SUUpdateValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = 729924721DF3478A00DBCDF5 /* SUUpdateValidator.m */; };
|
||||
72A4A2401BB6567D00E7820D /* SUFileManagerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72A4A23F1BB6567D00E7820D /* SUFileManagerTest.swift */; };
|
||||
72AC6B261B9AAC8800F62325 /* SparkleTestCodeSignApp.tar.gz in Resources */ = {isa = PBXBuildFile; fileRef = 72AC6B251B9AAC8800F62325 /* SparkleTestCodeSignApp.tar.gz */; };
|
||||
72AC6B281B9AAD6700F62325 /* SparkleTestCodeSignApp.tar in Resources */ = {isa = PBXBuildFile; fileRef = 72AC6B271B9AAD6700F62325 /* SparkleTestCodeSignApp.tar */; };
|
||||
@@ -537,6 +539,7 @@
|
||||
55E6F33219EC9F6C00005E76 /* SUErrors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUErrors.h; sourceTree = "<group>"; };
|
||||
5AA4DCD01C73E5510078F128 /* SUAppcastTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SUAppcastTest.swift; sourceTree = "<group>"; };
|
||||
5AD0FA7E1C73F2E2004BCEFF /* testappcast.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = testappcast.xml; sourceTree = "<group>"; };
|
||||
5AE7E10E1DC81ACA009C2C12 /* AppIcon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = AppIcon.icns; sourceTree = "<group>"; };
|
||||
5AEF45D9189D1CC90030D7DC /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/Sparkle.strings; sourceTree = "<group>"; };
|
||||
5AF6C74C1AEA40760014A3AB /* SUInstallerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUInstallerTest.m; sourceTree = "<group>"; };
|
||||
5AF6C74E1AEA46D10014A3AB /* test.sparkle_guided.pkg */ = {isa = PBXFileReference; lastKnownFileType = file; path = test.sparkle_guided.pkg; sourceTree = "<group>"; };
|
||||
@@ -677,6 +680,10 @@
|
||||
722954C21D04E66F00ECF9CA /* SUFileOperationConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUFileOperationConstants.h; sourceTree = "<group>"; };
|
||||
722954C31D04E66F00ECF9CA /* SUFileOperationConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUFileOperationConstants.m; sourceTree = "<group>"; };
|
||||
722954C81D04E89500ECF9CA /* ConfigFileop.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigFileop.xcconfig; sourceTree = "<group>"; };
|
||||
722FB7471DD51331001D40CE /* ConfigSwift.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigSwift.xcconfig; sourceTree = "<group>"; };
|
||||
722FB7481DD51350001D40CE /* ConfigSwiftDebug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigSwiftDebug.xcconfig; sourceTree = "<group>"; };
|
||||
722FB7491DD51350001D40CE /* ConfigSwiftRelease.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigSwiftRelease.xcconfig; sourceTree = "<group>"; };
|
||||
723A920D1D722438004A9DED /* SUSpotlightImporterTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SUSpotlightImporterTest.swift; sourceTree = "<group>"; };
|
||||
723B252B1CEAB3A600909873 /* bscommon.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bscommon.c; sourceTree = "<group>"; };
|
||||
723B252C1CEAB3A600909873 /* bscommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bscommon.h; sourceTree = "<group>"; };
|
||||
7268AC621AD634C200C3E0C1 /* SUBinaryDeltaCreate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUBinaryDeltaCreate.m; sourceTree = "<group>"; };
|
||||
@@ -686,6 +693,8 @@
|
||||
726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUOperatingSystem.m; sourceTree = "<group>"; };
|
||||
7275F9BF1B5F1F2900B1D19E /* SUFileManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUFileManager.h; sourceTree = "<group>"; };
|
||||
7275F9C01B5F1F2900B1D19E /* SUFileManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUFileManager.m; sourceTree = "<group>"; };
|
||||
729924711DF3478A00DBCDF5 /* SUUpdateValidator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdateValidator.h; sourceTree = "<group>"; };
|
||||
729924721DF3478A00DBCDF5 /* SUUpdateValidator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdateValidator.m; sourceTree = "<group>"; };
|
||||
729F10FD1C65A9B500DFCCC5 /* ConfigUITest.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITest.xcconfig; sourceTree = "<group>"; };
|
||||
729F10FE1C65A9B500DFCCC5 /* ConfigUITestCoverage.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITestCoverage.xcconfig; sourceTree = "<group>"; };
|
||||
729F10FF1C65A9B500DFCCC5 /* ConfigUITestDebug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITestDebug.xcconfig; sourceTree = "<group>"; };
|
||||
@@ -923,6 +932,7 @@
|
||||
1420DF4F196247F900203BB0 /* Images.xcassets */,
|
||||
14732BBC1960EFB500593899 /* README.markdown */,
|
||||
14732BB91960EEEE00593899 /* SampleAppcast.xml */,
|
||||
5AE7E10E1DC81ACA009C2C12 /* AppIcon.icns */,
|
||||
615AE3CF0D64DC40001CA7BD /* SUModelTranslation.plist */,
|
||||
);
|
||||
path = Resources;
|
||||
@@ -1024,6 +1034,7 @@
|
||||
5AF9DC3B1981DBEE001EA135 /* SUDSAVerifierTest.m */,
|
||||
72A4A23F1BB6567D00E7820D /* SUFileManagerTest.swift */,
|
||||
5AF6C74C1AEA40760014A3AB /* SUInstallerTest.m */,
|
||||
723A920D1D722438004A9DED /* SUSpotlightImporterTest.swift */,
|
||||
7210C7671B9A9A1500EB90AC /* SUUnarchiverTest.swift */,
|
||||
14950074195FDF5900BC5B5B /* SUUpdaterTest.m */,
|
||||
61227A150DB548B800AB99EA /* SUVersionComparisonTest.m */,
|
||||
@@ -1128,6 +1139,8 @@
|
||||
61CFB2C10E384958007A1735 /* Support */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
729924711DF3478A00DBCDF5 /* SUUpdateValidator.h */,
|
||||
729924721DF3478A00DBCDF5 /* SUUpdateValidator.m */,
|
||||
61B078CC15A5FB6100600039 /* SUCodeSigningVerifier.h */,
|
||||
61B078CD15A5FB6100600039 /* SUCodeSigningVerifier.m */,
|
||||
61299A2D09CA2DAB00B7442F /* SUDSAVerifier.h */,
|
||||
@@ -1218,6 +1231,9 @@
|
||||
729F10FE1C65A9B500DFCCC5 /* ConfigUITestCoverage.xcconfig */,
|
||||
729F10FF1C65A9B500DFCCC5 /* ConfigUITestDebug.xcconfig */,
|
||||
729F11001C65A9B500DFCCC5 /* ConfigUITestRelease.xcconfig */,
|
||||
722FB7471DD51331001D40CE /* ConfigSwift.xcconfig */,
|
||||
722FB7481DD51350001D40CE /* ConfigSwiftDebug.xcconfig */,
|
||||
722FB7491DD51350001D40CE /* ConfigSwiftRelease.xcconfig */,
|
||||
14732BC91960F70A00593899 /* make-release-package.sh */,
|
||||
14652F7919A93E5F00959E44 /* set-git-version-info.sh */,
|
||||
146EC84E19A68CF8004A50C5 /* Sparkle.podspec */,
|
||||
@@ -1250,6 +1266,7 @@
|
||||
7275F9C11B5F1F2900B1D19E /* SUFileManager.h in Headers */,
|
||||
767B61AC1972D488004E0C3C /* SUGuidedPackageInstaller.h in Headers */,
|
||||
61EF67590E25C5B400F754E0 /* SUHost.h in Headers */,
|
||||
729924731DF3478A00DBCDF5 /* SUUpdateValidator.h in Headers */,
|
||||
723B25301CEAB3A600909873 /* bscommon.h in Headers */,
|
||||
618FA5010DAE88B40026945C /* SUInstaller.h in Headers */,
|
||||
55C14F06136EF6DB00649790 /* SULog.h in Headers */,
|
||||
@@ -1458,10 +1475,11 @@
|
||||
attributes = {
|
||||
CLASSPREFIX = SU;
|
||||
LastSwiftUpdateCheck = 0720;
|
||||
LastUpgradeCheck = 0720;
|
||||
LastUpgradeCheck = 0800;
|
||||
ORGANIZATIONNAME = "Sparkle Project";
|
||||
TargetAttributes = {
|
||||
612279D80DB5470200AB99EA = {
|
||||
LastSwiftMigration = 0800;
|
||||
TestTargetID = 8DC2EF4F0486A6940098B216;
|
||||
};
|
||||
722954B31D04ADAF00ECF9CA = {
|
||||
@@ -1469,6 +1487,7 @@
|
||||
};
|
||||
726B2B5C1C645FC900388755 = {
|
||||
CreatedOnToolsVersion = 7.2.1;
|
||||
LastSwiftMigration = 0800;
|
||||
TestTargetID = 61B5F90109C4CEE200B25A18;
|
||||
};
|
||||
};
|
||||
@@ -1569,7 +1588,7 @@
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
1420DF51196247F900203BB0 /* Images.xcassets in Resources */,
|
||||
5AE7E1111DC81AD3009C2C12 /* AppIcon.icns in Resources */,
|
||||
55C14FC7136F05E100649790 /* Sparkle.strings in Resources */,
|
||||
55C14BD9136EF00C00649790 /* SUStatus.xib in Resources */,
|
||||
);
|
||||
@@ -1594,7 +1613,6 @@
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
720B16441C66433D006985FB /* UITests-Info.plist in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -1727,6 +1745,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
723A920E1D722438004A9DED /* SUSpotlightImporterTest.swift in Sources */,
|
||||
721CF1A71AD7643600D9AC09 /* bsdiff.c in Sources */,
|
||||
721CF1A81AD7644100D9AC09 /* bspatch.c in Sources */,
|
||||
721CF1A91AD7644C00D9AC09 /* sais.c in Sources */,
|
||||
@@ -1803,6 +1822,7 @@
|
||||
61EF67560E25B58D00F754E0 /* SUHost.m in Sources */,
|
||||
618FA5020DAE88B40026945C /* SUInstaller.m in Sources */,
|
||||
55C14F07136EF6DB00649790 /* SULog.m in Sources */,
|
||||
729924741DF3478A00DBCDF5 /* SUUpdateValidator.m in Sources */,
|
||||
723B252D1CEAB3A600909873 /* bscommon.c in Sources */,
|
||||
726F2CE61BC9C33D001971A4 /* SUOperatingSystem.m in Sources */,
|
||||
618FA5230DAE8E8A0026945C /* SUPackageInstaller.m in Sources */,
|
||||
@@ -2308,9 +2328,6 @@
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 729F10FF1C65A9B500DFCCC5 /* ConfigUITestDebug.xcconfig */;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
@@ -2318,9 +2335,6 @@
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 729F10FE1C65A9B500DFCCC5 /* ConfigUITestCoverage.xcconfig */;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
};
|
||||
name = Coverage;
|
||||
};
|
||||
@@ -2328,8 +2342,6 @@
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 729F11001C65A9B500DFCCC5 /* ConfigUITestRelease.xcconfig */;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0710"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0710"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "2.0">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0720"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
||||
+2
@@ -28,5 +28,7 @@
|
||||
<string>MainMenu</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>${ASSETCATALOG_COMPILER_APPICON_NAME}.icns</string>
|
||||
</dict>
|
||||
</plist>
|
||||
Vendored
+34
-104
@@ -10,16 +10,14 @@
|
||||
|
||||
#import "SUHost.h"
|
||||
#import "SUOperatingSystem.h"
|
||||
#import "SUDSAVerifier.h"
|
||||
#import "SUInstaller.h"
|
||||
#import "SUStandardVersionComparator.h"
|
||||
#import "SUUnarchiver.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SULog.h"
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
#import "SUUpdater_Private.h"
|
||||
#import "SUFileManager.h"
|
||||
#import "SUUpdateValidator.h"
|
||||
|
||||
@interface SUBasicUpdateDriver ()
|
||||
|
||||
@@ -31,6 +29,8 @@
|
||||
@property (copy) NSString *tempDir;
|
||||
@property (copy) NSString *relaunchPath;
|
||||
|
||||
@property (nonatomic) SUUpdateValidator *updateValidator;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUBasicUpdateDriver
|
||||
@@ -43,6 +43,8 @@
|
||||
@synthesize tempDir;
|
||||
@synthesize relaunchPath;
|
||||
|
||||
@synthesize updateValidator = _updateValidator;
|
||||
|
||||
- (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)aHost
|
||||
{
|
||||
[super checkForUpdatesAtURL:URL host:aHost];
|
||||
@@ -274,96 +276,6 @@
|
||||
[self.download setDestination:self.downloadPath allowOverwrite:YES];
|
||||
}
|
||||
|
||||
/**
|
||||
* If the update is a package, then it must be signed using DSA. No other verification is done.
|
||||
*
|
||||
* If the update is a bundle, then it must meet any one of:
|
||||
*
|
||||
* * old and new DSA public keys are the same and valid (it allows change of Code Signing identity), or
|
||||
*
|
||||
* * old and new Code Signing identity are the same and valid
|
||||
*
|
||||
*/
|
||||
- (BOOL)validateUpdateDownloadedToPath:(NSString *)downloadedPath extractedToPath:(NSString *)extractedPath DSASignature:(NSString *)DSASignature publicDSAKey:(NSString *)publicDSAKey
|
||||
{
|
||||
BOOL isPackage = NO;
|
||||
NSString *installSourcePath = [SUInstaller installSourcePathInUpdateFolder:extractedPath forHost:self.host isPackage:&isPackage isGuided:NULL];
|
||||
if (installSourcePath == nil) {
|
||||
SULog(@"No suitable install is found in the update. The update will be rejected.");
|
||||
return NO;
|
||||
}
|
||||
|
||||
// Modern packages are not distributed as bundles and are code signed differently than regular applications
|
||||
if (isPackage) {
|
||||
if (nil == publicDSAKey) {
|
||||
SULog(@"The existing app bundle does not have a DSA key, so it can't verify installer packages.");
|
||||
}
|
||||
|
||||
BOOL packageValidated = [SUDSAVerifier validatePath:downloadedPath withEncodedDSASignature:DSASignature withPublicDSAKey:publicDSAKey];
|
||||
|
||||
if (!packageValidated) {
|
||||
SULog(@"DSA signature validation of the package failed. The update contains an installer package, and valid DSA signatures are mandatory for all installer packages. The update will be rejected. Sign the installer with a valid DSA key or use an .app bundle update instead.");
|
||||
}
|
||||
|
||||
return packageValidated;
|
||||
}
|
||||
|
||||
NSBundle *newBundle = [NSBundle bundleWithPath:installSourcePath];
|
||||
if (newBundle == nil) {
|
||||
SULog(@"No suitable bundle is found in the update. The update will be rejected.");
|
||||
return NO;
|
||||
}
|
||||
|
||||
SUHost *newHost = [[SUHost alloc] initWithBundle:newBundle];
|
||||
NSString *newPublicDSAKey = newHost.publicDSAKey;
|
||||
|
||||
// Downgrade in DSA security should not be possible
|
||||
if (publicDSAKey != nil && newPublicDSAKey == nil) {
|
||||
SULog(@"A public DSA key is found in the old bundle but no public DSA key is found in the new update. For security reasons, the update will be rejected.");
|
||||
return NO;
|
||||
}
|
||||
|
||||
BOOL dsaKeysMatch = (publicDSAKey == nil || newPublicDSAKey == nil) ? NO : [publicDSAKey isEqualToString:newPublicDSAKey];
|
||||
|
||||
// If the new DSA key differs from the old, then this check is not a security measure, because the new key is not trusted.
|
||||
// In that case, the check ensures that the app author has correctly used DSA keys, so that the app will be updateable in the next version.
|
||||
// However if the new and old DSA keys are the same, then this is a security measure.
|
||||
if (newPublicDSAKey != nil) {
|
||||
if (![SUDSAVerifier validatePath:downloadedPath withEncodedDSASignature:DSASignature withPublicDSAKey:newPublicDSAKey]) {
|
||||
SULog(@"DSA signature validation failed. The update has a public DSA key and is signed with a DSA key, but the %@ doesn't match the signature. The update will be rejected.",
|
||||
dsaKeysMatch ? @"public key" : @"new public key shipped with the update");
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL updateIsCodeSigned = [SUCodeSigningVerifier applicationAtPathIsCodeSigned:installSourcePath];
|
||||
|
||||
if (dsaKeysMatch) {
|
||||
NSError *error = nil;
|
||||
if (updateIsCodeSigned && ![SUCodeSigningVerifier codeSignatureIsValidAtPath:installSourcePath error:&error]) {
|
||||
SULog(@"The update archive has a valid DSA signature, but the app is also signed with Code Signing, which is corrupted: %@. The update will be rejected.", error);
|
||||
return NO;
|
||||
}
|
||||
} else {
|
||||
BOOL hostIsCodeSigned = [SUCodeSigningVerifier hostApplicationIsCodeSigned];
|
||||
|
||||
NSString *dsaStatus = newPublicDSAKey ? @"has a new DSA key that doesn't match the previous one" : (publicDSAKey ? @"removes the DSA key" : @"isn't signed with a DSA key");
|
||||
if (!hostIsCodeSigned || !updateIsCodeSigned) {
|
||||
NSString *acsStatus = !hostIsCodeSigned ? @"old app hasn't been signed with app Code Signing" : @"new app isn't signed with app Code Signing";
|
||||
SULog(@"The update archive %@, and the %@. At least one method of signature verification must be valid. The update will be rejected.", dsaStatus, acsStatus);
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSError *error = nil;
|
||||
if (![SUCodeSigningVerifier codeSignatureMatchesHostAndIsValidAtPath:installSourcePath error:&error]) {
|
||||
SULog(@"The update archive %@, and the app is signed with a new Code Signing identity that doesn't match code signing of the original app: %@. At least one method of signature verification must be valid. The update will be rejected.", dsaStatus, error);
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)downloadDidFinish:(NSURLDownload *)__unused d
|
||||
{
|
||||
assert(self.updateItem);
|
||||
@@ -404,14 +316,28 @@
|
||||
|
||||
- (void)extractUpdate
|
||||
{
|
||||
SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:self.downloadPath updatingHostBundlePath:[[self.host bundle] bundlePath] withPassword:self.updater.decryptionPassword];
|
||||
SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:self.downloadPath updatingHostBundlePath:self.host.bundlePath withPassword:self.updater.decryptionPassword];
|
||||
|
||||
BOOL success;
|
||||
if (!unarchiver) {
|
||||
SULog(@"Error: No valid unarchiver for %@!", self.downloadPath);
|
||||
[self unarchiverDidFail:nil];
|
||||
return;
|
||||
|
||||
success = NO;
|
||||
} else {
|
||||
// Currently unsafe archives are the only case where we can prevalidate before extraction, but that could change in the future
|
||||
BOOL needsPrevalidation = [[unarchiver class] unsafeIfArchiveIsNotValidated];
|
||||
|
||||
self.updateValidator = [[SUUpdateValidator alloc] initWithDownloadPath:self.downloadPath dsaSignature:self.updateItem.DSASignature host:self.host performingPrevalidation:needsPrevalidation];
|
||||
|
||||
success = self.updateValidator.canValidate;
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
[self unarchiverDidFail:nil];
|
||||
} else {
|
||||
unarchiver.delegate = self;
|
||||
[unarchiver start];
|
||||
}
|
||||
unarchiver.delegate = self;
|
||||
[unarchiver start];
|
||||
}
|
||||
|
||||
- (void)failedToApplyDeltaUpdate
|
||||
@@ -432,6 +358,9 @@
|
||||
|
||||
- (void)unarchiverDidFail:(SUUnarchiver *)__unused ua
|
||||
{
|
||||
// No longer needed
|
||||
self.updateValidator = nil;
|
||||
|
||||
if ([self.updateItem isDeltaUpdate]) {
|
||||
[self failedToApplyDeltaUpdate];
|
||||
return;
|
||||
@@ -474,13 +403,14 @@
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI
|
||||
{
|
||||
assert(self.updateItem);
|
||||
|
||||
if (![self validateUpdateDownloadedToPath:self.downloadPath extractedToPath:self.tempDir DSASignature:self.updateItem.DSASignature publicDSAKey:self.host.publicDSAKey])
|
||||
{
|
||||
assert(self.updateValidator);
|
||||
|
||||
BOOL validationCheckSuccess = [self.updateValidator validateWithUpdateDirectory:self.tempDir];
|
||||
if (!validationCheckSuccess) {
|
||||
NSDictionary *userInfo = @{
|
||||
NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil),
|
||||
NSLocalizedFailureReasonErrorKey: SULocalizedString(@"The update is improperly signed.", nil),
|
||||
};
|
||||
NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil),
|
||||
NSLocalizedFailureReasonErrorKey: SULocalizedString(@"The update is improperly signed.", nil),
|
||||
};
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUSignatureError userInfo:userInfo]];
|
||||
return;
|
||||
}
|
||||
|
||||
Vendored
+43
@@ -10,6 +10,7 @@
|
||||
#import "SUBinaryDeltaUnarchiver.h"
|
||||
#import "SUBinaryDeltaApply.h"
|
||||
#import "SUUnarchiver_Private.h"
|
||||
#import "SUFileManager.h"
|
||||
#import "SUHost.h"
|
||||
#import "SULog.h"
|
||||
|
||||
@@ -20,6 +21,46 @@
|
||||
return [[path pathExtension] isEqualToString:@"delta"];
|
||||
}
|
||||
|
||||
+ (BOOL)unsafeIfArchiveIsNotValidated
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
// According to https://developer.apple.com/library/mac/documentation/Carbon/Conceptual/MDImporters/Concepts/Troubleshooting.html
|
||||
// We should make sure mdimporter bundles have an up to date time in the event they were delta updated.
|
||||
// We used to invoke mdimport on the bundle but this is not a very good approach.
|
||||
// There's no need to do that for non-delta updates and for updates that contain no mdimporters.
|
||||
// Moreover, updating the timestamp on the mdimporter bundles is what developers have to do anyway when shipping their new update outside of Sparkle
|
||||
+ (void)updateSpotlightImportersAtBundlePath:(NSString *)targetPath
|
||||
{
|
||||
NSURL *targetURL = [NSURL fileURLWithPath:targetPath];
|
||||
// Only recurse if it's actually a directory. Don't recurse into a
|
||||
// root-level symbolic link.
|
||||
NSDictionary *rootAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:targetPath error:nil];
|
||||
NSString *rootType = [rootAttributes objectForKey:NSFileType];
|
||||
|
||||
if ([rootType isEqualToString:NSFileTypeDirectory]) {
|
||||
// The NSDirectoryEnumerator will avoid recursing into any contained
|
||||
// symbolic links, so no further type checks are needed.
|
||||
NSDirectoryEnumerator *directoryEnumerator = [[NSFileManager defaultManager] enumeratorAtURL:targetURL includingPropertiesForKeys:nil options:(NSDirectoryEnumerationOptions)0 errorHandler:nil];
|
||||
|
||||
NSMutableArray *filesToUpdate = [[NSMutableArray alloc] init];
|
||||
for (NSURL *file in directoryEnumerator) {
|
||||
if ([file.pathExtension isEqualToString:@"mdimporter"]) {
|
||||
[filesToUpdate addObject:file];
|
||||
}
|
||||
}
|
||||
|
||||
SUFileManager *fileManager = [SUFileManager defaultManager];
|
||||
for (NSURL *file in filesToUpdate) {
|
||||
NSError *error = nil;
|
||||
if (![fileManager updateModificationAndAccessTimeOfItemAtURL:file error:&error]) {
|
||||
SULog(@"Error: During delta unarchiving, failed to touch %@", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)applyBinaryDelta
|
||||
{
|
||||
@autoreleasepool {
|
||||
@@ -29,6 +70,8 @@
|
||||
NSError *applyDiffError = nil;
|
||||
BOOL success = applyBinaryDelta(sourcePath, targetPath, self.archivePath, NO, &applyDiffError);
|
||||
if (success) {
|
||||
[[self class] updateSpotlightImportersAtBundlePath:targetPath];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self notifyDelegateOfSuccess];
|
||||
});
|
||||
|
||||
Vendored
+3
-4
@@ -12,10 +12,9 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface SUCodeSigningVerifier : NSObject
|
||||
+ (BOOL)codeSignatureMatchesHostAndIsValidAtPath:(NSString *)applicationPath error:(NSError **)error;
|
||||
+ (BOOL)codeSignatureIsValidAtPath:(NSString *)applicationPath error:(NSError **)error;
|
||||
+ (BOOL)hostApplicationIsCodeSigned;
|
||||
+ (BOOL)applicationAtPathIsCodeSigned:(NSString *)applicationPath;
|
||||
+ (BOOL)codeSignatureAtBundleURL:(NSURL *)oldBundlePath matchesSignatureAtBundleURL:(NSURL *)newBundlePath error:(NSError **)error;
|
||||
+ (BOOL)codeSignatureIsValidAtBundleURL:(NSURL *)bundlePath error:(NSError **)error;
|
||||
+ (BOOL)bundleAtURLIsCodeSigned:(NSURL *)bundlePath;
|
||||
@end
|
||||
|
||||
#endif
|
||||
Vendored
+29
-66
@@ -13,53 +13,46 @@
|
||||
|
||||
@implementation SUCodeSigningVerifier
|
||||
|
||||
+ (BOOL)codeSignatureMatchesHostAndIsValidAtPath:(NSString *)applicationPath error:(NSError *__autoreleasing *)error
|
||||
+ (BOOL)codeSignatureAtBundleURL:(NSURL *)oldBundleURL matchesSignatureAtBundleURL:(NSURL *)newBundleURL error:(NSError *__autoreleasing *)error
|
||||
{
|
||||
OSStatus result;
|
||||
SecRequirementRef requirement = NULL;
|
||||
SecStaticCodeRef staticCode = NULL;
|
||||
SecCodeRef hostCode = NULL;
|
||||
NSBundle *newBundle;
|
||||
SecStaticCodeRef oldCode = NULL;
|
||||
CFErrorRef cfError = NULL;
|
||||
if (error) {
|
||||
*error = nil;
|
||||
}
|
||||
|
||||
result = SecCodeCopySelf(kSecCSDefaultFlags, &hostCode);
|
||||
if (result != noErr) {
|
||||
SULog(@"Failed to copy host code %d", result);
|
||||
goto finally;
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)oldBundleURL, kSecCSDefaultFlags, &oldCode);
|
||||
if (result == errSecCSUnsigned) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
result = SecCodeCopyDesignatedRequirement(hostCode, kSecCSDefaultFlags, &requirement);
|
||||
result = SecCodeCopyDesignatedRequirement(oldCode, kSecCSDefaultFlags, &requirement);
|
||||
if (result != noErr) {
|
||||
SULog(@"Failed to copy designated requirement. Code Signing OSStatus code: %d", result);
|
||||
goto finally;
|
||||
}
|
||||
|
||||
newBundle = [NSBundle bundleWithPath:applicationPath];
|
||||
if (!newBundle) {
|
||||
SULog(@"Failed to load NSBundle for update");
|
||||
result = -1;
|
||||
goto finally;
|
||||
}
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)[newBundle bundleURL], kSecCSDefaultFlags, &staticCode);
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)newBundleURL, kSecCSDefaultFlags, &staticCode);
|
||||
if (result != noErr) {
|
||||
SULog(@"Failed to get static code %d", result);
|
||||
goto finally;
|
||||
}
|
||||
|
||||
|
||||
// Note that kSecCSCheckNestedCode may not work with pre-Mavericks code signing.
|
||||
// See https://github.com/sparkle-project/Sparkle/issues/376#issuecomment-48824267 and https://developer.apple.com/library/mac/technotes/tn2206
|
||||
SecCSFlags flags = (SecCSFlags) (kSecCSDefaultFlags | kSecCSCheckAllArchitectures);
|
||||
// Aditionally, there are several reasons to stay away from deep verification and to prefer DSA signing the download archive instead.
|
||||
// See https://github.com/sparkle-project/Sparkle/pull/523#commitcomment-17549302 and https://github.com/sparkle-project/Sparkle/issues/543
|
||||
SecCSFlags flags = (SecCSFlags) (kSecCSDefaultFlags | kSecCSCheckAllArchitectures);
|
||||
result = SecStaticCodeCheckValidityWithErrors(staticCode, flags, requirement, &cfError);
|
||||
|
||||
|
||||
if (cfError) {
|
||||
NSError *tmpError = CFBridgingRelease(cfError);
|
||||
if (error) *error = tmpError;
|
||||
}
|
||||
|
||||
|
||||
if (result != noErr) {
|
||||
if (result == errSecCSUnsigned) {
|
||||
SULog(@"The host app is signed, but the new version of the app is not signed using Apple Code Signing. Please ensure that the new app is signed and that archiving did not corrupt the signature.");
|
||||
@@ -70,61 +63,52 @@
|
||||
SULog(@"Code signature of the new version doesn't match the old version: %@. Please ensure that old and new app is signed using exactly the same certificate.", requirementString);
|
||||
CFRelease(requirementString);
|
||||
}
|
||||
|
||||
[self logSigningInfoForCode:hostCode label:@"host info"];
|
||||
|
||||
[self logSigningInfoForCode:oldCode label:@"old info"];
|
||||
[self logSigningInfoForCode:staticCode label:@"new info"];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
finally:
|
||||
if (hostCode) CFRelease(hostCode);
|
||||
if (oldCode) CFRelease(oldCode);
|
||||
if (staticCode) CFRelease(staticCode);
|
||||
if (requirement) CFRelease(requirement);
|
||||
return (result == noErr);
|
||||
}
|
||||
|
||||
+ (BOOL)codeSignatureIsValidAtPath:(NSString *)applicationPath error:(NSError *__autoreleasing *)error
|
||||
+ (BOOL)codeSignatureIsValidAtBundleURL:(NSURL *)bundleURL error:(NSError *__autoreleasing *)error
|
||||
{
|
||||
OSStatus result;
|
||||
SecStaticCodeRef staticCode = NULL;
|
||||
NSBundle *newBundle;
|
||||
CFErrorRef cfError = NULL;
|
||||
if (error) {
|
||||
*error = nil;
|
||||
}
|
||||
|
||||
newBundle = [NSBundle bundleWithPath:applicationPath];
|
||||
if (!newBundle) {
|
||||
SULog(@"Failed to load NSBundle");
|
||||
result = -1;
|
||||
goto finally;
|
||||
}
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)[newBundle bundleURL], kSecCSDefaultFlags, &staticCode);
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)bundleURL, kSecCSDefaultFlags, &staticCode);
|
||||
if (result != noErr) {
|
||||
SULog(@"Failed to get static code %d", result);
|
||||
goto finally;
|
||||
}
|
||||
|
||||
// Note that kSecCSCheckNestedCode may not work with pre-Mavericks code signing.
|
||||
// See https://github.com/sparkle-project/Sparkle/issues/376#issuecomment-48824267 and https://developer.apple.com/library/mac/technotes/tn2206
|
||||
SecCSFlags flags = (SecCSFlags) (kSecCSDefaultFlags | kSecCSCheckAllArchitectures);
|
||||
// See in -codeSignatureAtBundleURL:matchesSignatureAtBundleURL:error: for why kSecCSCheckNestedCode is not passed
|
||||
SecCSFlags flags = (SecCSFlags) (kSecCSDefaultFlags | kSecCSCheckAllArchitectures);
|
||||
result = SecStaticCodeCheckValidityWithErrors(staticCode, flags, NULL, &cfError);
|
||||
|
||||
|
||||
if (cfError) {
|
||||
NSError *tmpError = CFBridgingRelease(cfError);
|
||||
if (error) *error = tmpError;
|
||||
}
|
||||
|
||||
|
||||
if (result != noErr) {
|
||||
if (result == errSecCSUnsigned) {
|
||||
SULog(@"Error: The app is not signed using Apple Code Signing. %@", applicationPath);
|
||||
SULog(@"Error: The app is not signed using Apple Code Signing. %@", bundleURL);
|
||||
}
|
||||
if (result == errSecCSReqFailed) {
|
||||
[self logSigningInfoForCode:staticCode label:@"new info"];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
finally:
|
||||
if (staticCode) CFRelease(staticCode);
|
||||
return (result == noErr);
|
||||
@@ -150,35 +134,14 @@ static id valueOrNSNull(id value) {
|
||||
}
|
||||
}
|
||||
|
||||
+ (BOOL)hostApplicationIsCodeSigned
|
||||
{
|
||||
OSStatus result;
|
||||
SecCodeRef hostCode = NULL;
|
||||
result = SecCodeCopySelf(kSecCSDefaultFlags, &hostCode);
|
||||
if (result != 0) return NO;
|
||||
|
||||
SecRequirementRef requirement = NULL;
|
||||
result = SecCodeCopyDesignatedRequirement(hostCode, kSecCSDefaultFlags, &requirement);
|
||||
if (hostCode) CFRelease(hostCode);
|
||||
if (requirement) CFRelease(requirement);
|
||||
return (result == 0);
|
||||
}
|
||||
|
||||
+ (BOOL)applicationAtPathIsCodeSigned:(NSString *)applicationPath
|
||||
+ (BOOL)bundleAtURLIsCodeSigned:(NSURL *)bundleURL
|
||||
{
|
||||
OSStatus result;
|
||||
SecStaticCodeRef staticCode = NULL;
|
||||
NSBundle *newBundle;
|
||||
|
||||
newBundle = [NSBundle bundleWithPath:applicationPath];
|
||||
if (!newBundle) {
|
||||
SULog(@"Failed to load NSBundle");
|
||||
return NO;
|
||||
}
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)[newBundle bundleURL], kSecCSDefaultFlags, &staticCode);
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)bundleURL, kSecCSDefaultFlags, &staticCode);
|
||||
if (result == errSecCSUnsigned) {
|
||||
return NO;
|
||||
return NO;
|
||||
}
|
||||
|
||||
SecRequirementRef requirement = NULL;
|
||||
@@ -190,7 +153,7 @@ static id valueOrNSNull(id value) {
|
||||
CFRelease(requirement);
|
||||
}
|
||||
if (result == errSecCSUnsigned) {
|
||||
return NO;
|
||||
return NO;
|
||||
}
|
||||
return (result == 0);
|
||||
}
|
||||
|
||||
Vendored
+5
@@ -18,6 +18,11 @@
|
||||
return [[path pathExtension] isEqualToString:@"dmg"];
|
||||
}
|
||||
|
||||
+ (BOOL)unsafeIfArchiveIsNotValidated
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
// Called on a non-main thread.
|
||||
- (void)extractDMG
|
||||
{
|
||||
|
||||
Vendored
+29
-1
@@ -11,6 +11,7 @@
|
||||
#import "SUSystemProfiler.h"
|
||||
#include <sys/mount.h> // For statfs for isRunningOnReadOnlyVolume
|
||||
#import "SULog.h"
|
||||
#import "SUFileManager.h"
|
||||
|
||||
#if __MAC_OS_X_VERSION_MAX_ALLOWED < 101000
|
||||
@interface NSProcessInfo ()
|
||||
@@ -74,7 +75,34 @@
|
||||
// Note it's very well possible to have the bundle be writable but not be able to write into the parent directory
|
||||
// And if the bundle isn't writable, but we can write into the parent directory, we will still need to authorize to replace it
|
||||
NSString *bundlePath = [self bundlePath];
|
||||
return [[NSFileManager defaultManager] isWritableFileAtPath:bundlePath.stringByDeletingLastPathComponent] && [[NSFileManager defaultManager] isWritableFileAtPath:bundlePath];
|
||||
if (![[NSFileManager defaultManager] isWritableFileAtPath:bundlePath.stringByDeletingLastPathComponent] || ![[NSFileManager defaultManager] isWritableFileAtPath:bundlePath]) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
// Just because we have writability access does not mean we can set the correct owner/group silently
|
||||
// Test if we can set the owner/group on a temporarily created file
|
||||
// If we can, then we can probably perform an update without authorization
|
||||
// One place where this matters is if you copy and run an app from /tmp/
|
||||
|
||||
NSString *tempFilename = @"permission_test" ;
|
||||
|
||||
SUFileManager *suFileManager = [SUFileManager defaultManager];
|
||||
NSURL *tempDirectoryURL = [suFileManager makeTemporaryDirectoryWithPreferredName:tempFilename appropriateForDirectoryURL:[NSURL fileURLWithPath:NSTemporaryDirectory()] error:NULL];
|
||||
|
||||
if (tempDirectoryURL == nil) {
|
||||
// I don't imagine this ever happening but in case it does, requesting authorization may be the better option
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSURL *tempFileURL = [tempDirectoryURL URLByAppendingPathComponent:tempFilename];
|
||||
|
||||
BOOL changeOwnerAndGroupSuccess =
|
||||
[[NSData data] writeToURL:tempFileURL atomically:NO] &&
|
||||
[suFileManager changeOwnerAndGroupOfItemAtRootURL:tempFileURL toMatchURL:self.bundle.bundleURL error:NULL];
|
||||
|
||||
[suFileManager removeItemAtURL:tempDirectoryURL error:NULL];
|
||||
|
||||
return changeOwnerAndGroupSuccess;
|
||||
}
|
||||
|
||||
- (NSString *)installationPath
|
||||
|
||||
Vendored
+1
-22
@@ -122,30 +122,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)mdimportInstallationPath:(NSString *)installationPath
|
||||
{
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!
|
||||
|
||||
SULog(@"mdimporting");
|
||||
|
||||
NSTask *mdimport = [[NSTask alloc] init];
|
||||
[mdimport setLaunchPath:@"/usr/bin/mdimport"];
|
||||
[mdimport setArguments:@[installationPath]];
|
||||
@try {
|
||||
[mdimport launch];
|
||||
[mdimport waitUntilExit];
|
||||
}
|
||||
@catch (NSException *launchException)
|
||||
{
|
||||
// No big deal.
|
||||
SULog(@"Error: %@", [launchException description]);
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result error:(NSError *)error completionHandler:(void (^)(NSError *))completionHandler
|
||||
+ (void)finishInstallationToPath:(NSString *)__unused installationPath withResult:(BOOL)result error:(NSError *)error completionHandler:(void (^)(NSError *))completionHandler
|
||||
{
|
||||
if (result) {
|
||||
[self mdimportInstallationPath:installationPath];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
completionHandler(nil);
|
||||
});
|
||||
|
||||
Vendored
+5
@@ -41,6 +41,11 @@
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+ (BOOL)unsafeIfArchiveIsNotValidated
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)start
|
||||
{
|
||||
[NSThread detachNewThreadSelector:[[self class] selectorConformingToTypeOfPath:self.archivePath] toTarget:self withObject:nil];
|
||||
|
||||
Vendored
+1
-1
@@ -164,7 +164,7 @@
|
||||
// Prevent malicious downgrades
|
||||
if (!allowDowngrades) {
|
||||
if ([comparator compareVersion:[host version] toVersion:[[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]] == NSOrderedDescending) {
|
||||
NSString *errorMessage = [NSString stringWithFormat:@"Sparkle Updater: Possible attack in progress! Attempting to \"upgrade\" from %@ to %@. Aborting update.", [host version], [[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]];
|
||||
NSString *errorMessage = [NSString stringWithFormat:@"For security reasons, updates that downgrade version of the application are not allowed. Refusing to downgrade app from version %@ to %@. Aborting update.", [host version], [[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]];
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDowngradeError userInfo:@{ NSLocalizedDescriptionKey: errorMessage }];
|
||||
[self finishInstallationToPath:installationPath withResult:NO error:error completionHandler:completionHandler];
|
||||
return;
|
||||
|
||||
Vendored
+1
@@ -10,6 +10,7 @@
|
||||
<connections>
|
||||
<outlet property="actionButton" destination="12" id="34"/>
|
||||
<outlet property="progressBar" destination="11" id="49"/>
|
||||
<outlet property="statusTextField" destination="16" id="MiZ-Tn-yVg"/>
|
||||
<outlet property="window" destination="5" id="25"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
|
||||
Vendored
+1
@@ -15,6 +15,7 @@
|
||||
@interface SUStatusController : SUWindowController
|
||||
@property (weak) IBOutlet NSButton *actionButton;
|
||||
@property (weak) IBOutlet NSProgressIndicator *progressBar;
|
||||
@property (weak) IBOutlet NSTextField *statusTextField;
|
||||
|
||||
@property (copy) NSString *statusText;
|
||||
@property double progressValue;
|
||||
|
||||
Vendored
+9
@@ -11,6 +11,7 @@
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUOperatingSystem.h"
|
||||
#import "SUStatusController.h"
|
||||
#import "SUHost.h"
|
||||
|
||||
@@ -28,6 +29,7 @@
|
||||
@synthesize host;
|
||||
@synthesize actionButton;
|
||||
@synthesize progressBar;
|
||||
@synthesize statusTextField;
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)aHost
|
||||
{
|
||||
@@ -51,6 +53,13 @@
|
||||
[[self window] center];
|
||||
[[self window] setFrameAutosaveName:@"SUStatusFrame"];
|
||||
[self.progressBar setUsesThreadedAnimation:YES];
|
||||
|
||||
if ([SUOperatingSystem isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 11, 0}]) {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wpartial-availability"
|
||||
[self.statusTextField setFont:[NSFont monospacedDigitSystemFontOfSize:0 weight:NSFontWeightRegular]];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)windowTitle
|
||||
|
||||
Vendored
+24
-7
@@ -98,8 +98,9 @@
|
||||
alert.informativeText = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [self.host name], [self.host displayVersion]];
|
||||
[alert addButtonWithTitle:SULocalizedString(@"OK", nil)];
|
||||
[self showAlert:alert];
|
||||
[self abortUpdate];
|
||||
}
|
||||
|
||||
[self abortUpdate];
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(NSNotification *)__unused aNotification
|
||||
@@ -114,10 +115,6 @@
|
||||
[self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey];
|
||||
switch (choice) {
|
||||
case SUInstallUpdateChoice:
|
||||
self.statusController = [[SUStatusController alloc] initWithHost:self.host];
|
||||
[self.statusController beginActionWithTitle:SULocalizedString(@"Downloading update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
|
||||
[self.statusController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelDownload:) isDefault:NO];
|
||||
[self.statusController showWindow:self];
|
||||
[self downloadUpdate];
|
||||
break;
|
||||
|
||||
@@ -137,6 +134,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)downloadUpdate
|
||||
{
|
||||
BOOL createdStatusController = NO;
|
||||
if (self.statusController == nil) {
|
||||
self.statusController = [[SUStatusController alloc] initWithHost:self.host];
|
||||
createdStatusController = YES;
|
||||
}
|
||||
|
||||
[self.statusController beginActionWithTitle:SULocalizedString(@"Downloading update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
|
||||
[self.statusController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelDownload:) isDefault:NO];
|
||||
[self.statusController setButtonEnabled:YES];
|
||||
|
||||
if (createdStatusController) {
|
||||
[self.statusController showWindow:self];
|
||||
}
|
||||
|
||||
[super downloadUpdate];
|
||||
}
|
||||
|
||||
- (void)download:(NSURLDownload *)__unused download didReceiveResponse:(NSURLResponse *)response
|
||||
{
|
||||
[self.statusController setMaxProgressValue:[response expectedContentLength]];
|
||||
@@ -166,8 +182,9 @@
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wpartial-availability"
|
||||
return [NSByteCountFormatter stringFromByteCount:value
|
||||
countStyle:NSByteCountFormatterCountStyleFile];
|
||||
NSByteCountFormatter *formatter = [[NSByteCountFormatter alloc] init];
|
||||
[formatter setZeroPadsFractionDigits:YES];
|
||||
return [formatter stringFromByteCount:value];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
|
||||
Vendored
+3
@@ -23,7 +23,10 @@
|
||||
|
||||
+ (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHostBundlePath:(NSString *)host withPassword:(NSString *)decryptionPassword;
|
||||
|
||||
+ (BOOL)unsafeIfArchiveIsNotValidated;
|
||||
|
||||
- (void)start;
|
||||
|
||||
@end
|
||||
|
||||
@protocol SUUnarchiverDelegate <NSObject>
|
||||
|
||||
Vendored
+5
@@ -55,6 +55,11 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (BOOL)unsafeIfArchiveIsNotValidated
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)notifyDelegateOfProgress:(double)progress
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(unarchiver:extractedProgress:)]) {
|
||||
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// SUUpdateValidator.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 12/3/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class SUHost;
|
||||
|
||||
@interface SUUpdateValidator : NSObject
|
||||
|
||||
// Pass YES to performingPrevalidation if archive validation must be done immediately, before extraction
|
||||
- (instancetype)initWithDownloadPath:(NSString *)downloadPath dsaSignature:(NSString *)dsaSignature host:(SUHost *)host performingPrevalidation:(BOOL)performingPrevalidation;
|
||||
|
||||
// Indicates whether we can perform (post) validation later
|
||||
@property (nonatomic, readonly) BOOL canValidate;
|
||||
|
||||
// precondition: validation must be possible (see -canValidate)
|
||||
// This is "post" validation, after an archive has been extracted
|
||||
- (BOOL)validateWithUpdateDirectory:(NSString *)updateDirectory;
|
||||
|
||||
@end
|
||||
Vendored
+192
@@ -0,0 +1,192 @@
|
||||
//
|
||||
// SUUpdateValidator.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 12/3/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUUpdateValidator.h"
|
||||
#import "SUDSAVerifier.h"
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
#import "SUInstaller.h"
|
||||
#import "SUHost.h"
|
||||
#import "SULog.h"
|
||||
|
||||
@interface SUUpdateValidator ()
|
||||
|
||||
@property (nonatomic, readonly) SUHost *host;
|
||||
@property (nonatomic, readonly) BOOL prevalidatedDsaSignature;
|
||||
@property (nonatomic, readonly) NSString *dsaSignature;
|
||||
@property (nonatomic, readonly) NSString *downloadPath;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUUpdateValidator
|
||||
|
||||
@synthesize host = _host;
|
||||
@synthesize canValidate = _canValidate;
|
||||
@synthesize prevalidatedDsaSignature = _prevalidatedDsaSignature;
|
||||
@synthesize dsaSignature = _dsaSignature;
|
||||
@synthesize downloadPath = _downloadPath;
|
||||
|
||||
- (instancetype)initWithDownloadPath:(NSString *)downloadPath dsaSignature:(NSString *)dsaSignature host:(SUHost *)host performingPrevalidation:(BOOL)performingPrevalidation
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
BOOL canValidate;
|
||||
BOOL prevalidatedDsaSignature;
|
||||
if (performingPrevalidation) {
|
||||
NSString *publicDSAKey = host.publicDSAKey;
|
||||
|
||||
if (publicDSAKey == nil) {
|
||||
prevalidatedDsaSignature = NO;
|
||||
SULog(@"Failed to validate update before unarchiving because no DSA key was found");
|
||||
} else if (dsaSignature == nil) {
|
||||
prevalidatedDsaSignature = NO;
|
||||
SULog(@"Failed to validate update before unarchiving because no DSA signature was found");
|
||||
} else {
|
||||
prevalidatedDsaSignature = [SUDSAVerifier validatePath:downloadPath withEncodedDSASignature:dsaSignature withPublicDSAKey:publicDSAKey];
|
||||
if (!prevalidatedDsaSignature) {
|
||||
SULog(@"DSA signature validation before unarchiving failed for update %@", downloadPath);
|
||||
}
|
||||
}
|
||||
|
||||
canValidate = prevalidatedDsaSignature;
|
||||
} else {
|
||||
prevalidatedDsaSignature = NO;
|
||||
canValidate = YES;
|
||||
}
|
||||
|
||||
_canValidate = canValidate;
|
||||
_prevalidatedDsaSignature = prevalidatedDsaSignature;
|
||||
_downloadPath = [downloadPath copy];
|
||||
_dsaSignature = [dsaSignature copy];
|
||||
_host = host;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)validateWithUpdateDirectory:(NSString *)updateDirectory
|
||||
{
|
||||
assert(self.canValidate);
|
||||
|
||||
NSString *DSASignature = self.dsaSignature;
|
||||
NSString *publicDSAKey = self.host.publicDSAKey;
|
||||
NSString *downloadPath = self.downloadPath;
|
||||
SUHost *host = self.host;
|
||||
|
||||
BOOL prevalidatedDsaSignature = self.prevalidatedDsaSignature;
|
||||
|
||||
BOOL validationCheckSuccess;
|
||||
BOOL isPackage = NO;
|
||||
|
||||
// install source could point to a new bundle or a package
|
||||
NSString *installSource = [SUInstaller installSourcePathInUpdateFolder:updateDirectory forHost:host isPackage:&isPackage isGuided:NULL];
|
||||
if (installSource == nil) {
|
||||
SULog(@"No suitable install is found in the update. The update will be rejected.");
|
||||
validationCheckSuccess = NO;
|
||||
} else {
|
||||
NSURL *installSourceURL = [NSURL fileURLWithPath:installSource];
|
||||
|
||||
if (!prevalidatedDsaSignature) {
|
||||
// Check to see if we have a package or bundle to validate
|
||||
if (isPackage) {
|
||||
// For package type updates, all we do is check if the DSA signature is valid
|
||||
validationCheckSuccess = [SUDSAVerifier validatePath:downloadPath withEncodedDSASignature:DSASignature withPublicDSAKey:publicDSAKey];
|
||||
if (!validationCheckSuccess) {
|
||||
SULog(@"DSA signature validation of the package failed. The update contains an installer package, and valid DSA signatures are mandatory for all installer packages. The update will be rejected. Sign the installer with a valid DSA key or use an .app bundle update instead.");
|
||||
}
|
||||
} else {
|
||||
// For application bundle updates, we check both the DSA and Apple code signing signatures
|
||||
validationCheckSuccess = [self validateUpdateForHost:host downloadedToPath:downloadPath newBundleURL:installSourceURL DSASignature:DSASignature];
|
||||
}
|
||||
} else if (isPackage) {
|
||||
// We shouldn't get here because we don't validate packages before extracting them currently
|
||||
SULog(@"Error: not expecting to find package after being required to validate update before extraction");
|
||||
validationCheckSuccess = NO;
|
||||
} else {
|
||||
// Because we already validated the DSA signature, this is just a consistency check to see
|
||||
// if the developer signed their application properly with their Apple ID
|
||||
// Currently, this case only gets hit for binary delta updates
|
||||
NSError *error = nil;
|
||||
if ([SUCodeSigningVerifier bundleAtURLIsCodeSigned:installSourceURL] && ![SUCodeSigningVerifier codeSignatureIsValidAtBundleURL:installSourceURL error:&error]) {
|
||||
SULog(@"Failed to validate apple code sign signature on bundle after archive validation with error: %@", error);
|
||||
validationCheckSuccess = NO;
|
||||
} else {
|
||||
validationCheckSuccess = YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return validationCheckSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the update is a bundle, then it must meet any one of:
|
||||
*
|
||||
* * old and new DSA public keys are the same and valid (it allows change of Code Signing identity), or
|
||||
*
|
||||
* * old and new Code Signing identity are the same and valid
|
||||
*
|
||||
*/
|
||||
- (BOOL)validateUpdateForHost:(SUHost *)host downloadedToPath:(NSString *)downloadedPath newBundleURL:(NSURL *)newBundleURL DSASignature:(NSString *)DSASignature
|
||||
{
|
||||
NSBundle *newBundle = [NSBundle bundleWithURL:newBundleURL];
|
||||
if (newBundle == nil) {
|
||||
SULog(@"No suitable bundle is found in the update. The update will be rejected.");
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSString *publicDSAKey = host.publicDSAKey;
|
||||
|
||||
SUHost *newHost = [[SUHost alloc] initWithBundle:newBundle];
|
||||
NSString *newPublicDSAKey = newHost.publicDSAKey;
|
||||
|
||||
// Downgrade in DSA security should not be possible
|
||||
if (publicDSAKey != nil && newPublicDSAKey == nil) {
|
||||
SULog(@"A public DSA key is found in the old bundle but no public DSA key is found in the new update. For security reasons, the update will be rejected.");
|
||||
return NO;
|
||||
}
|
||||
|
||||
BOOL dsaKeysMatch = (publicDSAKey == nil || newPublicDSAKey == nil) ? NO : [publicDSAKey isEqualToString:newPublicDSAKey];
|
||||
|
||||
// If the new DSA key differs from the old, then this check is not a security measure, because the new key is not trusted.
|
||||
// In that case, the check ensures that the app author has correctly used DSA keys, so that the app will be updateable in the next version.
|
||||
// However if the new and old DSA keys are the same, then this is a security measure.
|
||||
if (newPublicDSAKey != nil) {
|
||||
if (![SUDSAVerifier validatePath:downloadedPath withEncodedDSASignature:DSASignature withPublicDSAKey:newPublicDSAKey]) {
|
||||
SULog(@"DSA signature validation failed. The update has a public DSA key and is signed with a DSA key, but the %@ doesn't match the signature. The update will be rejected.",
|
||||
dsaKeysMatch ? @"public key" : @"new public key shipped with the update");
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
BOOL updateIsCodeSigned = [SUCodeSigningVerifier bundleAtURLIsCodeSigned:newHost.bundle.bundleURL];
|
||||
|
||||
if (dsaKeysMatch) {
|
||||
NSError *error = nil;
|
||||
if (updateIsCodeSigned && ![SUCodeSigningVerifier codeSignatureIsValidAtBundleURL:newHost.bundle.bundleURL error:&error]) {
|
||||
SULog(@"The update archive has a valid DSA signature, but the app is also signed with Code Signing, which is corrupted: %@. The update will be rejected.", error);
|
||||
return NO;
|
||||
}
|
||||
} else {
|
||||
BOOL hostIsCodeSigned = [SUCodeSigningVerifier bundleAtURLIsCodeSigned:host.bundle.bundleURL];
|
||||
|
||||
NSString *dsaStatus = newPublicDSAKey ? @"has a new DSA key that doesn't match the previous one" : (publicDSAKey ? @"removes the DSA key" : @"isn't signed with a DSA key");
|
||||
if (!hostIsCodeSigned || !updateIsCodeSigned) {
|
||||
NSString *acsStatus = !hostIsCodeSigned ? @"old app hasn't been signed with app Code Signing" : @"new app isn't signed with app Code Signing";
|
||||
SULog(@"The update archive %@, and the %@. At least one method of signature verification must be valid. The update will be rejected.", dsaStatus, acsStatus);
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSError *error = nil;
|
||||
if (![SUCodeSigningVerifier codeSignatureAtBundleURL:host.bundle.bundleURL matchesSignatureAtBundleURL:newHost.bundle.bundleURL error:&error]) {
|
||||
SULog(@"The update archive %@, and the app is signed with a new Code Signing identity that doesn't match code signing of the original app: %@. At least one method of signature verification must be valid. The update will be rejected.", dsaStatus, error);
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
Vendored
+136
-47
@@ -32,62 +32,148 @@ SU_EXPORT @interface SUUpdater : NSObject
|
||||
|
||||
@property (unsafe_unretained) IBOutlet id<SUUpdaterDelegate> delegate;
|
||||
|
||||
/*!
|
||||
The shared updater for the main bundle.
|
||||
|
||||
This is equivalent to passing [NSBundle mainBundle] to SUUpdater::updaterForBundle:
|
||||
*/
|
||||
+ (SUUpdater *)sharedUpdater;
|
||||
|
||||
/*!
|
||||
The shared updater for a specified bundle.
|
||||
|
||||
If an updater has already been initialized for the provided bundle, that shared instance will be returned.
|
||||
*/
|
||||
+ (SUUpdater *)updaterForBundle:(NSBundle *)bundle;
|
||||
|
||||
/*!
|
||||
Designated initializer for SUUpdater.
|
||||
|
||||
If an updater has already been initialized for the provided bundle, that shared instance will be returned.
|
||||
*/
|
||||
- (instancetype)initForBundle:(NSBundle *)bundle;
|
||||
|
||||
@property (readonly, strong) NSBundle *hostBundle;
|
||||
@property (strong, readonly) NSBundle *sparkleBundle;
|
||||
|
||||
@property BOOL automaticallyChecksForUpdates;
|
||||
|
||||
@property NSTimeInterval updateCheckInterval;
|
||||
|
||||
/*!
|
||||
* The URL of the appcast used to download update information.
|
||||
*
|
||||
* This property must be called on the main thread.
|
||||
*/
|
||||
@property (copy) NSURL *feedURL;
|
||||
Explicitly checks for updates and displays a progress dialog while doing so.
|
||||
|
||||
@property (nonatomic, copy) NSString *userAgentString;
|
||||
This method is meant for a main menu item.
|
||||
Connect any menu item to this action in Interface Builder,
|
||||
and Sparkle will check for updates and report back its findings verbosely
|
||||
when it is invoked.
|
||||
|
||||
@property (copy) NSDictionary *httpHeaders;
|
||||
|
||||
@property BOOL sendsSystemProfile;
|
||||
|
||||
@property BOOL automaticallyDownloadsUpdates;
|
||||
|
||||
@property (nonatomic, copy) NSString *decryptionPassword;
|
||||
|
||||
/*!
|
||||
Explicitly checks for updates and displays a progress dialog while doing so.
|
||||
|
||||
This method is meant for a main menu item.
|
||||
Connect any menu item to this action in Interface Builder,
|
||||
and Sparkle will check for updates and report back its findings verbosely
|
||||
when it is invoked.
|
||||
This will find updates that the user has opted into skipping.
|
||||
*/
|
||||
- (IBAction)checkForUpdates:(id)sender;
|
||||
|
||||
/*!
|
||||
The menu item validation used for the -checkForUpdates: action
|
||||
The menu item validation used for the -checkForUpdates: action
|
||||
*/
|
||||
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
|
||||
|
||||
/*!
|
||||
Checks for updates, but does not display any UI unless an update is found.
|
||||
Checks for updates, but does not display any UI unless an update is found.
|
||||
|
||||
This is meant for programmatically initating a check for updates. That is,
|
||||
it will display no UI unless it actually finds an update, in which case it
|
||||
proceeds as usual.
|
||||
This is meant for programmatically initating a check for updates. That is,
|
||||
it will display no UI unless it actually finds an update, in which case it
|
||||
proceeds as usual.
|
||||
|
||||
If the fully automated updating is turned on, however, this will invoke that
|
||||
behavior, and if an update is found, it will be downloaded and prepped for
|
||||
installation.
|
||||
If automatic downloading of updates it turned on and allowed, however,
|
||||
this will invoke that behavior, and if an update is found, it will be downloaded
|
||||
in the background silently and will be prepped for installation.
|
||||
|
||||
This will not find updates that the user has opted into skipping.
|
||||
*/
|
||||
- (void)checkForUpdatesInBackground;
|
||||
|
||||
/*!
|
||||
A property indicating whether or not to check for updates automatically.
|
||||
|
||||
Setting this property will persist in the host bundle's user defaults.
|
||||
The update schedule cycle will be reset in a short delay after the property's new value is set.
|
||||
This is to allow reverting this property without kicking off a schedule change immediately
|
||||
*/
|
||||
@property BOOL automaticallyChecksForUpdates;
|
||||
|
||||
/*!
|
||||
A property indicating whether or not updates can be automatically downloaded in the background.
|
||||
|
||||
Note that automatic downloading of updates can be disallowed by the developer
|
||||
or by the user's system if silent updates cannot be done (eg: if they require authentication).
|
||||
In this case, -automaticallyDownloadsUpdates will return NO regardless of how this property is set.
|
||||
|
||||
Setting this property will persist in the host bundle's user defaults.
|
||||
*/
|
||||
@property BOOL automaticallyDownloadsUpdates;
|
||||
|
||||
/*!
|
||||
A property indicating the current automatic update check interval.
|
||||
|
||||
Setting this property will persist in the host bundle's user defaults.
|
||||
The update schedule cycle will be reset in a short delay after the property's new value is set.
|
||||
This is to allow reverting this property without kicking off a schedule change immediately
|
||||
*/
|
||||
@property NSTimeInterval updateCheckInterval;
|
||||
|
||||
/*!
|
||||
Begins a "probing" check for updates which will not actually offer to
|
||||
update to that version.
|
||||
|
||||
However, the delegate methods
|
||||
SUUpdaterDelegate::updater:didFindValidUpdate: and
|
||||
SUUpdaterDelegate::updaterDidNotFindUpdate: will be called,
|
||||
so you can use that information in your UI.
|
||||
|
||||
Updates that have been skipped by the user will not be found.
|
||||
*/
|
||||
- (void)checkForUpdateInformation;
|
||||
|
||||
/*!
|
||||
The URL of the appcast used to download update information.
|
||||
|
||||
Setting this property will persist in the host bundle's user defaults.
|
||||
If you don't want persistence, you may want to consider instead implementing
|
||||
SUUpdaterDelegate::feedURLStringForUpdater: or SUUpdaterDelegate::feedParametersForUpdater:sendingSystemProfile:
|
||||
|
||||
This property must be called on the main thread.
|
||||
*/
|
||||
@property (copy) NSURL *feedURL;
|
||||
|
||||
/*!
|
||||
The host bundle that is being updated.
|
||||
*/
|
||||
@property (readonly, strong) NSBundle *hostBundle;
|
||||
|
||||
/*!
|
||||
The bundle this class (SUUpdater) is loaded into.
|
||||
*/
|
||||
@property (strong, readonly) NSBundle *sparkleBundle;
|
||||
|
||||
/*!
|
||||
The user agent used when checking for updates.
|
||||
|
||||
The default implementation can be overrided.
|
||||
*/
|
||||
@property (nonatomic, copy) NSString *userAgentString;
|
||||
|
||||
/*!
|
||||
The HTTP headers used when checking for updates.
|
||||
|
||||
The keys of this dictionary are HTTP header fields (NSString) and values are corresponding values (NSString)
|
||||
*/
|
||||
@property (copy) NSDictionary *httpHeaders;
|
||||
|
||||
/*!
|
||||
A property indicating whether or not the user's system profile information is sent when checking for updates.
|
||||
|
||||
Setting this property will persist in the host bundle's user defaults.
|
||||
*/
|
||||
@property BOOL sendsSystemProfile;
|
||||
|
||||
/*!
|
||||
A property indicating the decryption password used for extracting updates shipped as Apple Disk Images (dmg)
|
||||
*/
|
||||
@property (nonatomic, copy) NSString *decryptionPassword;
|
||||
|
||||
/*!
|
||||
Checks for updates and, if available, immediately downloads and installs them.
|
||||
A progress dialog is shown but the user will never be prompted to read the
|
||||
@@ -95,6 +181,9 @@ SU_EXPORT @interface SUUpdater : NSObject
|
||||
|
||||
You may want to respond to the userDidCancelDownload delegate method in case
|
||||
the user clicks the "Cancel" button while the update is downloading.
|
||||
|
||||
If you are writing a UI-less background application, you probably want to instead use
|
||||
SUUpdaterDelegate::updater:willInstallUpdateOnQuit:immediateInstallationInvocation:
|
||||
*/
|
||||
- (void)installUpdatesIfAvailable;
|
||||
|
||||
@@ -105,17 +194,6 @@ SU_EXPORT @interface SUUpdater : NSObject
|
||||
*/
|
||||
@property (readonly, copy) NSDate *lastUpdateCheckDate;
|
||||
|
||||
/*!
|
||||
Begins a "probing" check for updates which will not actually offer to
|
||||
update to that version.
|
||||
|
||||
However, the delegate methods
|
||||
SUUpdaterDelegate::updater:didFindValidUpdate: and
|
||||
SUUpdaterDelegate::updaterDidNotFindUpdate: will be called,
|
||||
so you can use that information in your UI.
|
||||
*/
|
||||
- (void)checkForUpdateInformation;
|
||||
|
||||
/*!
|
||||
Appropriately schedules or cancels the update checking timer according to
|
||||
the preferences for time interval and automatic checks.
|
||||
@@ -125,6 +203,12 @@ SU_EXPORT @interface SUUpdater : NSObject
|
||||
*/
|
||||
- (void)resetUpdateCycle;
|
||||
|
||||
/*!
|
||||
A property indicating whether or not an update is in progress.
|
||||
|
||||
Note this property is not indicative of whether or not user initiated updates can be performed.
|
||||
Use SUUpdater::validateMenuItem: for that instead.
|
||||
*/
|
||||
@property (readonly) BOOL updateInProgress;
|
||||
|
||||
@end
|
||||
@@ -181,6 +265,9 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey;
|
||||
|
||||
Override this to dynamically specify the entire URL.
|
||||
|
||||
An alternative may be to use SUUpdaterDelegate::feedParametersForUpdater:sendingSystemProfile:
|
||||
and let the server handle what kind of feed to provide.
|
||||
|
||||
\param updater The SUUpdater instance.
|
||||
*/
|
||||
- (NSString *)feedURLStringForUpdater:(SUUpdater *)updater;
|
||||
@@ -347,6 +434,8 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey;
|
||||
|
||||
/*!
|
||||
Called when an update is scheduled to be silently installed on quit.
|
||||
This is after an update has been automatically downloaded in the background.
|
||||
(i.e. SUUpdater::automaticallyDownloadsUpdates is YES)
|
||||
|
||||
\param updater The SUUpdater instance.
|
||||
\param item The appcast item corresponding to the update that is proposed to be installed.
|
||||
|
||||
Vendored
+10
-1
@@ -59,6 +59,15 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
|
||||
static NSMutableDictionary *sharedUpdaters = nil;
|
||||
static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObservationContext";
|
||||
|
||||
#ifdef DEBUG
|
||||
+ (void)load
|
||||
{
|
||||
// Debug builds have different configurations for update check intervals
|
||||
// We're using NSLog instead of SULog here because we don't want to start Sparkle's logger here
|
||||
NSLog(@"WARNING: This is running a Debug build of Sparkle; don't use this in production!");
|
||||
}
|
||||
#endif
|
||||
|
||||
+ (SUUpdater *)sharedUpdater
|
||||
{
|
||||
return [self updaterForBundle:[NSBundle mainBundle]];
|
||||
@@ -122,7 +131,7 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
|
||||
-(void)checkIfConfiguredProperly {
|
||||
BOOL hasPublicDSAKey = [self.host publicDSAKey] != nil;
|
||||
BOOL isMainBundle = [self.host.bundle isEqualTo:[NSBundle mainBundle]];
|
||||
BOOL hostIsCodeSigned = [SUCodeSigningVerifier hostApplicationIsCodeSigned];
|
||||
BOOL hostIsCodeSigned = [SUCodeSigningVerifier bundleAtURLIsCodeSigned:self.host.bundle.bundleURL];
|
||||
NSURL *feedURL = [self feedURL];
|
||||
BOOL servingOverHttps = [[[feedURL scheme] lowercaseString] isEqualToString:@"https"];
|
||||
|
||||
|
||||
@@ -13,12 +13,12 @@ class SUAppcastTest: XCTestCase {
|
||||
|
||||
func testParseAppcast() {
|
||||
let appcast = SUAppcast();
|
||||
let testFile = NSBundle(forClass: SUAppcastTest.self).pathForResource("testappcast", ofType: "xml")!;
|
||||
let testFileUrl = NSURL(fileURLWithPath: testFile);
|
||||
let testFile = Bundle(for: SUAppcastTest.self).path(forResource: "testappcast", ofType: "xml")!;
|
||||
let testFileUrl = URL(fileURLWithPath: testFile);
|
||||
XCTAssertNotNil(testFileUrl);
|
||||
|
||||
do {
|
||||
let items = try appcast.parseAppcastItemsFromXMLFile(testFileUrl) as! [SUAppcastItem];
|
||||
let items = try appcast.parseAppcastItems(fromXMLFile: testFileUrl) as! [SUAppcastItem];
|
||||
|
||||
XCTAssertEqual(4, items.count);
|
||||
|
||||
@@ -41,20 +41,20 @@ class SUAppcastTest: XCTestCase {
|
||||
|
||||
// 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())
|
||||
let bestAppcastItem = SUBasicUpdateDriver.bestItem(fromAppcastItems: items, getDeltaItem: &deltaItem, withHostVersion: "1.0", comparator: SUStandardVersionComparator.default())
|
||||
|
||||
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())
|
||||
SUBasicUpdateDriver.bestItem(fromAppcastItems: items, getDeltaItem: &latestDeltaItem, withHostVersion: "2.0", comparator: SUStandardVersionComparator.default())
|
||||
|
||||
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())
|
||||
SUBasicUpdateDriver.bestItem(fromAppcastItems: items, getDeltaItem: &nonexistantDeltaItem, withHostVersion: "2.1", comparator: SUStandardVersionComparator.default())
|
||||
|
||||
XCTAssertNil(nonexistantDeltaItem)
|
||||
} catch let err as NSError {
|
||||
@@ -65,12 +65,12 @@ class SUAppcastTest: XCTestCase {
|
||||
|
||||
func testNamespaces() {
|
||||
let appcast = SUAppcast();
|
||||
let testFile = NSBundle(forClass: SUAppcastTest.self).pathForResource("testnamespaces", ofType: "xml")!;
|
||||
let testFileUrl = NSURL(fileURLWithPath: testFile);
|
||||
let testFile = Bundle(for: SUAppcastTest.self).path(forResource: "testnamespaces", ofType: "xml")!;
|
||||
let testFileUrl = URL(fileURLWithPath: testFile);
|
||||
XCTAssertNotNil(testFileUrl);
|
||||
|
||||
do {
|
||||
let items = try appcast.parseAppcastItemsFromXMLFile(testFileUrl) as! [SUAppcastItem];
|
||||
let items = try appcast.parseAppcastItems(fromXMLFile: testFileUrl) as! [SUAppcastItem];
|
||||
|
||||
XCTAssertEqual(2, items.count);
|
||||
|
||||
|
||||
@@ -11,19 +11,23 @@
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
#import "SUFileManager.h"
|
||||
|
||||
#define CALCULATOR_PATH @"/Applications/Calculator.app"
|
||||
|
||||
@interface SUCodeSigningVerifierTest : XCTestCase
|
||||
|
||||
@property (copy) NSString *notSignedAppPath;
|
||||
@property (copy) NSString *validSignedAppPath;
|
||||
@property (copy) NSString *invalidSignedAppPath;
|
||||
@property (copy) NSURL *notSignedAppURL;
|
||||
@property (copy) NSURL *validSignedAppURL;
|
||||
@property (copy) NSURL *invalidSignedAppURL;
|
||||
@property (copy) NSURL *calculatorCopyURL;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUCodeSigningVerifierTest
|
||||
|
||||
@synthesize notSignedAppPath = _notSignedAppPath;
|
||||
@synthesize validSignedAppPath = _validSignedAppPath;
|
||||
@synthesize invalidSignedAppPath = _invalidSignedAppPath;
|
||||
@synthesize notSignedAppURL = _notSignedAppURL;
|
||||
@synthesize validSignedAppURL = _validSignedAppURL;
|
||||
@synthesize invalidSignedAppURL = _invalidSignedAppURL;
|
||||
@synthesize calculatorCopyURL = _calculatorCopyURL;
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
@@ -31,30 +35,28 @@
|
||||
|
||||
NSBundle *unitTestBundle = [NSBundle bundleForClass:[self class]];
|
||||
NSString *unitTestBundleIdentifier = unitTestBundle.bundleIdentifier;
|
||||
NSString *zippedAppPath = [unitTestBundle pathForResource:@"SparkleTestCodeSignApp" ofType:@"zip"];
|
||||
|
||||
NSString *zippedAppURL = [unitTestBundle pathForResource:@"SparkleTestCodeSignApp" ofType:@"zip"];
|
||||
|
||||
SUFileManager *fileManager = [SUFileManager defaultManager];
|
||||
|
||||
|
||||
NSError *tempError = nil;
|
||||
NSURL *tempDir = [fileManager makeTemporaryDirectoryWithPreferredName:unitTestBundleIdentifier appropriateForDirectoryURL:[NSURL fileURLWithPath:zippedAppPath] error:&tempError];
|
||||
|
||||
NSURL *tempDir = [fileManager makeTemporaryDirectoryWithPreferredName:unitTestBundleIdentifier appropriateForDirectoryURL:[NSURL fileURLWithPath:zippedAppURL] 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:tempDirPath withIntermediateDirectories:YES attributes:nil error:&error]) {
|
||||
if ([self unzip:zippedAppPath toPath:tempDirPath]) {
|
||||
self.notSignedAppPath = [tempDirPath stringByAppendingPathComponent:@"SparkleTestCodeSignApp.app"];
|
||||
if ([[NSFileManager defaultManager] createDirectoryAtURL:tempDir withIntermediateDirectories:YES attributes:nil error:&error]) {
|
||||
if ([self unzip:zippedAppURL toPath:tempDir.path]) {
|
||||
self.notSignedAppURL = [tempDir URLByAppendingPathComponent:@"SparkleTestCodeSignApp.app"];
|
||||
[self setupValidSignedApp];
|
||||
[self setupCalculatorCopy];
|
||||
[self setupInvalidSignedApp];
|
||||
}
|
||||
else {
|
||||
NSLog(@"Failed to unzip %@", zippedAppPath);
|
||||
NSLog(@"Failed to unzip %@", zippedAppURL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -65,56 +67,82 @@
|
||||
- (void)tearDown
|
||||
{
|
||||
[super tearDown];
|
||||
|
||||
if (self.notSignedAppPath) {
|
||||
NSString *tempDir = [self.notSignedAppPath stringByDeletingLastPathComponent];
|
||||
[[NSFileManager defaultManager] removeItemAtPath:tempDir error:nil];
|
||||
|
||||
if (self.notSignedAppURL) {
|
||||
NSURL *tempDir = [self.notSignedAppURL URLByDeletingLastPathComponent];
|
||||
[[NSFileManager defaultManager] removeItemAtURL:tempDir error:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setupValidSignedApp
|
||||
{
|
||||
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];
|
||||
NSURL *tempDir = [self.notSignedAppURL URLByDeletingLastPathComponent];
|
||||
NSURL *signedAndValid = [tempDir URLByAppendingPathComponent:@"valid-signed.app"];
|
||||
|
||||
[[NSFileManager defaultManager] removeItemAtURL:signedAndValid error:NULL];
|
||||
if (![[NSFileManager defaultManager] copyItemAtURL:self.notSignedAppURL toURL:signedAndValid error:&error]) {
|
||||
XCTFail("Failed to copy %@ to %@ with error: %@", self.notSignedAppURL, signedAndValid, error);
|
||||
}
|
||||
if ([[NSFileManager defaultManager] copyItemAtPath:self.notSignedAppPath toPath:signedAndValid error:&error]) {
|
||||
self.validSignedAppPath = signedAndValid;
|
||||
if (![self codesignAppPath:self.validSignedAppPath]) {
|
||||
NSLog(@"Failed to codesign %@", self.validSignedAppPath);
|
||||
}
|
||||
|
||||
self.validSignedAppURL = signedAndValid;
|
||||
|
||||
if (![self codesignAppURL:self.validSignedAppURL]) {
|
||||
XCTFail(@"Failed to codesign %@", self.validSignedAppURL);
|
||||
}
|
||||
else {
|
||||
NSLog(@"Failed to copy %@ to %@ with error %@", self.notSignedAppPath, signedAndValid, error);
|
||||
}
|
||||
|
||||
- (void)setupCalculatorCopy
|
||||
{
|
||||
NSURL *tempDir = [self.notSignedAppURL URLByDeletingLastPathComponent];
|
||||
NSURL *calculatorCopy = [tempDir URLByAppendingPathComponent:@"calc.app"];
|
||||
|
||||
[[NSFileManager defaultManager] removeItemAtURL:calculatorCopy error:NULL];
|
||||
|
||||
// Make a copy of the signed calculator app so we can match signatures later
|
||||
// Matching signatures on ad-hoc signed apps does *not* work
|
||||
NSError *copyError = nil;
|
||||
// Don't check the return value of this operation - seems like on 10.11 the API can say it fails even though the operation really succeeds,
|
||||
// which sounds like some kind of (SIP / attribute?) bug
|
||||
[[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:CALCULATOR_PATH] toURL:calculatorCopy error:©Error];
|
||||
|
||||
if (![calculatorCopy checkResourceIsReachableAndReturnError:nil]) {
|
||||
XCTFail(@"Copied calculator application does not exist");
|
||||
}
|
||||
|
||||
// Alter the signed copy slightly, this won't invalidate signature matching (although it will invalidate the integrity part of the signature)
|
||||
// Which is what we want. If a user alters an app bundle, we should still be able to update as long as its identity is still valid
|
||||
NSError *removeError = nil;
|
||||
NSURL *calculatorPkgInfo = [[calculatorCopy URLByAppendingPathComponent:@"Contents"] URLByAppendingPathComponent:@"PkgInfo"];
|
||||
XCTAssertNotNil(calculatorPkgInfo);
|
||||
if (![[NSFileManager defaultManager] removeItemAtURL:calculatorPkgInfo error:&removeError]) {
|
||||
XCTFail(@"Failed to remove file in calculator copy with error: %@", removeError);
|
||||
}
|
||||
|
||||
self.calculatorCopyURL = calculatorCopy;
|
||||
}
|
||||
|
||||
- (void)setupInvalidSignedApp
|
||||
{
|
||||
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]) {
|
||||
NSString *fileInAppBundleToRemove = [self.invalidSignedAppPath stringByAppendingPathComponent:@"Contents/Resources/test_app_only_dsa_pub.pem"];
|
||||
if (![[NSFileManager defaultManager] removeItemAtPath:fileInAppBundleToRemove error:&error]) {
|
||||
NSURL *tempDir = [self.notSignedAppURL URLByDeletingLastPathComponent];
|
||||
NSURL *signedAndInvalid = [tempDir URLByAppendingPathComponent:@"invalid-signed.app"];
|
||||
|
||||
[[NSFileManager defaultManager] removeItemAtURL:signedAndInvalid error:NULL];
|
||||
if ([[NSFileManager defaultManager] copyItemAtURL:self.notSignedAppURL toURL:signedAndInvalid error:&error]) {
|
||||
self.invalidSignedAppURL = signedAndInvalid;
|
||||
if ([self codesignAppURL:self.invalidSignedAppURL]) {
|
||||
NSURL *fileInAppBundleToRemove = [self.invalidSignedAppURL URLByAppendingPathComponent:@"Contents/Resources/test_app_only_dsa_pub.pem"];
|
||||
if (![[NSFileManager defaultManager] removeItemAtURL:fileInAppBundleToRemove error:&error]) {
|
||||
NSLog(@"Failed to remove %@ with error %@", fileInAppBundleToRemove, error);
|
||||
}
|
||||
}
|
||||
else {
|
||||
NSLog(@"Failed to codesign %@", self.invalidSignedAppPath);
|
||||
NSLog(@"Failed to codesign %@", self.invalidSignedAppURL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
NSLog(@"Failed to copy %@ to %@ with error %@", self.notSignedAppPath, signedAndInvalid, error);
|
||||
NSLog(@"Failed to copy %@ to %@ with error %@", self.notSignedAppURL, signedAndInvalid, error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +155,7 @@
|
||||
task.launchPath = @"/usr/bin/unzip";
|
||||
task.currentDirectoryPath = destPath;
|
||||
task.arguments = @[zipPath];
|
||||
|
||||
|
||||
[task launch];
|
||||
[task waitUntilExit];
|
||||
success = (task.terminationStatus == 0);
|
||||
@@ -139,7 +167,7 @@
|
||||
return success;
|
||||
}
|
||||
|
||||
- (BOOL)codesignAppPath:(NSString *)appPath
|
||||
- (BOOL)codesignAppURL:(NSURL *)appPath
|
||||
{
|
||||
BOOL success = NO;
|
||||
@try
|
||||
@@ -159,38 +187,61 @@
|
||||
|
||||
- (void)testUnsignedApp
|
||||
{
|
||||
XCTAssertFalse([SUCodeSigningVerifier applicationAtPathIsCodeSigned:self.notSignedAppPath], @"App not expected to be code signed");
|
||||
XCTAssertFalse([SUCodeSigningVerifier bundleAtURLIsCodeSigned:self.notSignedAppURL], @"App not expected to be code signed");
|
||||
|
||||
NSError *error = nil;
|
||||
XCTAssertFalse([SUCodeSigningVerifier codeSignatureIsValidAtPath:self.notSignedAppPath error:&error], @"signature should not be valid as it's not code signed");
|
||||
XCTAssertFalse([SUCodeSigningVerifier codeSignatureIsValidAtBundleURL:self.notSignedAppURL error:&error], @"signature should not be valid as it's not code signed");
|
||||
XCTAssertNotNil(error, @"error should not be nil");
|
||||
}
|
||||
|
||||
- (void)testValidSignedApp
|
||||
{
|
||||
XCTAssertTrue([SUCodeSigningVerifier applicationAtPathIsCodeSigned:self.validSignedAppPath], @"App expected to be code signed");
|
||||
XCTAssertTrue([SUCodeSigningVerifier bundleAtURLIsCodeSigned:self.validSignedAppURL], @"App expected to be code signed");
|
||||
|
||||
NSError *error = nil;
|
||||
XCTAssertTrue([SUCodeSigningVerifier codeSignatureIsValidAtPath:self.validSignedAppPath error:&error], @"signature should be valid");
|
||||
XCTAssertTrue([SUCodeSigningVerifier codeSignatureIsValidAtBundleURL:self.validSignedAppURL error:&error], @"signature should be valid");
|
||||
XCTAssertNil(error, @"error should be nil");
|
||||
}
|
||||
|
||||
- (void)testValidSignedCalculatorApp
|
||||
{
|
||||
NSString *appPath = @"/Applications/Calculator.app";
|
||||
XCTAssertTrue([SUCodeSigningVerifier applicationAtPathIsCodeSigned:appPath], @"App expected to be code signed");
|
||||
NSURL *appPath = [NSURL fileURLWithPath:CALCULATOR_PATH];
|
||||
XCTAssertTrue([SUCodeSigningVerifier bundleAtURLIsCodeSigned:appPath], @"App expected to be code signed");
|
||||
|
||||
NSError *error = nil;
|
||||
XCTAssertTrue([SUCodeSigningVerifier codeSignatureIsValidAtPath:appPath error:&error], @"signature should be valid");
|
||||
XCTAssertTrue([SUCodeSigningVerifier codeSignatureIsValidAtBundleURL:appPath error:&error], @"signature should be valid");
|
||||
XCTAssertNil(error, @"error should be nil");
|
||||
}
|
||||
|
||||
- (void)testValidMatchingSelf
|
||||
{
|
||||
NSError *error = nil;
|
||||
NSURL *appPath = [NSURL fileURLWithPath:CALCULATOR_PATH];
|
||||
|
||||
XCTAssertTrue([SUCodeSigningVerifier codeSignatureAtBundleURL:appPath matchesSignatureAtBundleURL:appPath error:&error], @"Our valid signed app expected to having matching signature to itself");
|
||||
}
|
||||
|
||||
- (void)testValidMatching
|
||||
{
|
||||
// We can't test our own app because matching with ad-hoc signed apps understandably does not succeed
|
||||
NSError *error = nil;
|
||||
NSURL *appPath = [NSURL fileURLWithPath:CALCULATOR_PATH];
|
||||
XCTAssertTrue([SUCodeSigningVerifier codeSignatureAtBundleURL:appPath matchesSignatureAtBundleURL:self.calculatorCopyURL error:&error], @"The calculator app is expected to have matching identity signature to its altered copy");
|
||||
}
|
||||
|
||||
- (void)testInvalidMatching
|
||||
{
|
||||
NSURL *appPath = [NSURL fileURLWithPath:CALCULATOR_PATH];
|
||||
NSError *error = nil;
|
||||
XCTAssertFalse([SUCodeSigningVerifier codeSignatureAtBundleURL:appPath matchesSignatureAtBundleURL:self.validSignedAppURL error:&error], @"Calculator app bundle expected to have different signature than our valid signed app");
|
||||
}
|
||||
|
||||
- (void)testInvalidSignedApp
|
||||
{
|
||||
XCTAssertTrue([SUCodeSigningVerifier applicationAtPathIsCodeSigned:self.invalidSignedAppPath], @"App expected to be code signed, but signature is invalid");
|
||||
XCTAssertTrue([SUCodeSigningVerifier bundleAtURLIsCodeSigned:self.invalidSignedAppURL], @"App expected to be code signed, but signature is invalid");
|
||||
|
||||
NSError *error = nil;
|
||||
XCTAssertFalse([SUCodeSigningVerifier codeSignatureIsValidAtPath:self.invalidSignedAppPath error:&error], @"signature should not be valid");
|
||||
XCTAssertFalse([SUCodeSigningVerifier codeSignatureIsValidAtBundleURL:self.invalidSignedAppURL error:&error], @"signature should not be valid");
|
||||
XCTAssertNotNil(error, @"error should not be nil");
|
||||
}
|
||||
|
||||
|
||||
+162
-162
@@ -10,180 +10,180 @@ import XCTest
|
||||
|
||||
class SUFileManagerTest: XCTestCase
|
||||
{
|
||||
func makeTempFiles(testBlock: (SUFileManager, NSURL, NSURL, NSURL, NSURL, NSURL, NSURL) -> Void)
|
||||
func makeTempFiles(_ testBlock: (SUFileManager, URL, URL, URL, URL, URL, URL) -> Void)
|
||||
{
|
||||
let fileManager = SUFileManager.defaultManager()
|
||||
let fileManager = SUFileManager.default()
|
||||
|
||||
let tempDirectoryURL = try! fileManager.makeTemporaryDirectoryWithPreferredName("Sparkle Unit Test Data", appropriateForDirectoryURL: NSURL(fileURLWithPath: NSHomeDirectory()))
|
||||
let tempDirectoryURL = try! fileManager?.makeTemporaryDirectory(withPreferredName: "Sparkle Unit Test Data", appropriateForDirectoryURL: URL(fileURLWithPath: NSHomeDirectory()))
|
||||
|
||||
defer {
|
||||
try! fileManager.removeItemAtURL(tempDirectoryURL)
|
||||
try! fileManager?.removeItem(at: tempDirectoryURL)
|
||||
}
|
||||
|
||||
let ordinaryFileURL = tempDirectoryURL.URLByAppendingPathComponent("a file written by sparkles unit tests")
|
||||
try! "foo".dataUsingEncoding(NSUTF8StringEncoding)!.writeToURL(ordinaryFileURL, options: .DataWritingAtomic)
|
||||
let ordinaryFileURL = tempDirectoryURL?.appendingPathComponent("a file written by sparkles unit tests")
|
||||
try! "foo".data(using: String.Encoding.utf8)!.write(to: ordinaryFileURL!, options: .atomic)
|
||||
|
||||
let directoryURL = tempDirectoryURL.URLByAppendingPathComponent("a directory written by sparkles unit tests")
|
||||
try! NSFileManager.defaultManager().createDirectoryAtURL(directoryURL, withIntermediateDirectories: false, attributes: nil)
|
||||
let directoryURL = tempDirectoryURL?.appendingPathComponent("a directory written by sparkles unit tests")
|
||||
try! FileManager.default.createDirectory(at: directoryURL!, withIntermediateDirectories: false, attributes: nil)
|
||||
|
||||
let fileInDirectoryURL = directoryURL.URLByAppendingPathComponent("a file inside a directory written by sparkles unit tests")
|
||||
try! "bar baz".dataUsingEncoding(NSUTF8StringEncoding)!.writeToURL(fileInDirectoryURL, options: .DataWritingAtomic)
|
||||
let fileInDirectoryURL = directoryURL?.appendingPathComponent("a file inside a directory written by sparkles unit tests")
|
||||
try! "bar baz".data(using: String.Encoding.utf8)!.write(to: fileInDirectoryURL!, options: .atomic)
|
||||
|
||||
let validSymlinkURL = tempDirectoryURL.URLByAppendingPathComponent("symlink test")
|
||||
try! NSFileManager.defaultManager().createSymbolicLinkAtURL(validSymlinkURL, withDestinationURL: directoryURL)
|
||||
let validSymlinkURL = tempDirectoryURL?.appendingPathComponent("symlink test")
|
||||
try! FileManager.default.createSymbolicLink(at: validSymlinkURL!, withDestinationURL: directoryURL!)
|
||||
|
||||
let invalidSymlinkURL = tempDirectoryURL.URLByAppendingPathComponent("symlink test 2")
|
||||
try! NSFileManager.defaultManager().createSymbolicLinkAtURL(invalidSymlinkURL, withDestinationURL: tempDirectoryURL.URLByAppendingPathComponent("does not exist"))
|
||||
let invalidSymlinkURL = tempDirectoryURL?.appendingPathComponent("symlink test 2")
|
||||
try! FileManager.default.createSymbolicLink(at: invalidSymlinkURL!, withDestinationURL: (tempDirectoryURL?.appendingPathComponent("does not exist"))!)
|
||||
|
||||
testBlock(fileManager, tempDirectoryURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL)
|
||||
testBlock(fileManager!, tempDirectoryURL!, ordinaryFileURL!, directoryURL!, fileInDirectoryURL!, validSymlinkURL!, invalidSymlinkURL!)
|
||||
}
|
||||
|
||||
func testMoveFiles()
|
||||
{
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
|
||||
XCTAssertNil(try? fileManager.moveItemAtURL(ordinaryFileURL, toURL: directoryURL))
|
||||
XCTAssertNil(try? fileManager.moveItemAtURL(ordinaryFileURL, toURL: directoryURL.URLByAppendingPathComponent("foo").URLByAppendingPathComponent("bar")))
|
||||
XCTAssertNil(try? fileManager.moveItemAtURL(rootURL.URLByAppendingPathComponent("does not exist"), toURL: directoryURL))
|
||||
XCTAssertNil(try? fileManager.moveItem(at: ordinaryFileURL, to: directoryURL))
|
||||
XCTAssertNil(try? fileManager.moveItem(at: ordinaryFileURL, to: directoryURL.appendingPathComponent("foo").appendingPathComponent("bar")))
|
||||
XCTAssertNil(try? fileManager.moveItem(at: rootURL.appendingPathComponent("does not exist"), to: directoryURL))
|
||||
|
||||
let newFileURL = (ordinaryFileURL.URLByDeletingLastPathComponent?.URLByAppendingPathComponent("new file"))!
|
||||
try! fileManager.moveItemAtURL(ordinaryFileURL, toURL: newFileURL)
|
||||
XCTAssertFalse(fileManager._itemExistsAtURL(ordinaryFileURL))
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(newFileURL))
|
||||
let newFileURL = (ordinaryFileURL.deletingLastPathComponent().appendingPathComponent("new file"))
|
||||
try! fileManager.moveItem(at: ordinaryFileURL, to: newFileURL)
|
||||
XCTAssertFalse(fileManager._itemExists(at: ordinaryFileURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: newFileURL))
|
||||
|
||||
let newValidSymlinkURL = (ordinaryFileURL.URLByDeletingLastPathComponent?.URLByAppendingPathComponent("new symlink"))!
|
||||
try! fileManager.moveItemAtURL(validSymlinkURL, toURL: newValidSymlinkURL)
|
||||
XCTAssertFalse(fileManager._itemExistsAtURL(validSymlinkURL))
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(newValidSymlinkURL))
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(directoryURL))
|
||||
let newValidSymlinkURL = (ordinaryFileURL.deletingLastPathComponent().appendingPathComponent("new symlink"))
|
||||
try! fileManager.moveItem(at: validSymlinkURL, to: newValidSymlinkURL)
|
||||
XCTAssertFalse(fileManager._itemExists(at: validSymlinkURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: newValidSymlinkURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: directoryURL))
|
||||
|
||||
let newInvalidSymlinkURL = (ordinaryFileURL.URLByDeletingLastPathComponent?.URLByAppendingPathComponent("new invalid symlink"))!
|
||||
try! fileManager.moveItemAtURL(invalidSymlinkURL, toURL: newInvalidSymlinkURL)
|
||||
XCTAssertFalse(fileManager._itemExistsAtURL(invalidSymlinkURL))
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(newValidSymlinkURL))
|
||||
let newInvalidSymlinkURL = (ordinaryFileURL.deletingLastPathComponent().appendingPathComponent("new invalid symlink"))
|
||||
try! fileManager.moveItem(at: invalidSymlinkURL, to: newInvalidSymlinkURL)
|
||||
XCTAssertFalse(fileManager._itemExists(at: invalidSymlinkURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: newValidSymlinkURL))
|
||||
|
||||
let newDirectoryURL = (ordinaryFileURL.URLByDeletingLastPathComponent?.URLByAppendingPathComponent("new directory"))!
|
||||
try! fileManager.moveItemAtURL(directoryURL, toURL: newDirectoryURL)
|
||||
XCTAssertFalse(fileManager._itemExistsAtURL(directoryURL))
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(newDirectoryURL))
|
||||
XCTAssertFalse(fileManager._itemExistsAtURL(fileInDirectoryURL))
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(newDirectoryURL.URLByAppendingPathComponent(fileInDirectoryURL.lastPathComponent!)))
|
||||
let newDirectoryURL = (ordinaryFileURL.deletingLastPathComponent().appendingPathComponent("new directory"))
|
||||
try! fileManager.moveItem(at: directoryURL, to: newDirectoryURL)
|
||||
XCTAssertFalse(fileManager._itemExists(at: directoryURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: newDirectoryURL))
|
||||
XCTAssertFalse(fileManager._itemExists(at: fileInDirectoryURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: newDirectoryURL.appendingPathComponent(fileInDirectoryURL.lastPathComponent)))
|
||||
}
|
||||
}
|
||||
|
||||
func testMoveFilesToTrash()
|
||||
{
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
|
||||
XCTAssertNil(try? fileManager.moveItemAtURLToTrash(rootURL.URLByAppendingPathComponent("does not exist")))
|
||||
XCTAssertNil(try? fileManager.moveItemAtURL(toTrash: rootURL.appendingPathComponent("does not exist")))
|
||||
|
||||
let trashURL = try! NSFileManager.defaultManager().URLForDirectory(.TrashDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: false)
|
||||
let trashURL = try! FileManager.default.url(for: .trashDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
|
||||
|
||||
try! fileManager.moveItemAtURLToTrash(ordinaryFileURL)
|
||||
XCTAssertFalse(fileManager._itemExistsAtURL(ordinaryFileURL))
|
||||
try! fileManager.moveItemAtURL(toTrash: ordinaryFileURL)
|
||||
XCTAssertFalse(fileManager._itemExists(at: ordinaryFileURL))
|
||||
|
||||
let ordinaryFileTrashURL = trashURL.URLByAppendingPathComponent(ordinaryFileURL.lastPathComponent!)
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(ordinaryFileTrashURL))
|
||||
try! fileManager.removeItemAtURL(ordinaryFileTrashURL)
|
||||
let ordinaryFileTrashURL = trashURL.appendingPathComponent(ordinaryFileURL.lastPathComponent)
|
||||
XCTAssertTrue(fileManager._itemExists(at: ordinaryFileTrashURL))
|
||||
try! fileManager.removeItem(at: ordinaryFileTrashURL)
|
||||
|
||||
let validSymlinkTrashURL = trashURL.URLByAppendingPathComponent(validSymlinkURL.lastPathComponent!)
|
||||
try! fileManager.moveItemAtURLToTrash(validSymlinkURL)
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(validSymlinkTrashURL))
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(directoryURL))
|
||||
try! fileManager.removeItemAtURL(validSymlinkTrashURL)
|
||||
let validSymlinkTrashURL = trashURL.appendingPathComponent(validSymlinkURL.lastPathComponent)
|
||||
try! fileManager.moveItemAtURL(toTrash: validSymlinkURL)
|
||||
XCTAssertTrue(fileManager._itemExists(at: validSymlinkTrashURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: directoryURL))
|
||||
try! fileManager.removeItem(at: validSymlinkTrashURL)
|
||||
|
||||
try! fileManager.moveItemAtURLToTrash(directoryURL)
|
||||
XCTAssertFalse(fileManager._itemExistsAtURL(directoryURL))
|
||||
XCTAssertFalse(fileManager._itemExistsAtURL(fileInDirectoryURL))
|
||||
try! fileManager.moveItemAtURL(toTrash: directoryURL)
|
||||
XCTAssertFalse(fileManager._itemExists(at: directoryURL))
|
||||
XCTAssertFalse(fileManager._itemExists(at: fileInDirectoryURL))
|
||||
|
||||
let directoryTrashURL = trashURL.URLByAppendingPathComponent(directoryURL.lastPathComponent!)
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(directoryTrashURL))
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(directoryTrashURL.URLByAppendingPathComponent(fileInDirectoryURL.lastPathComponent!)))
|
||||
let directoryTrashURL = trashURL.appendingPathComponent(directoryURL.lastPathComponent)
|
||||
XCTAssertTrue(fileManager._itemExists(at: directoryTrashURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: directoryTrashURL.appendingPathComponent(fileInDirectoryURL.lastPathComponent)))
|
||||
|
||||
try! fileManager.removeItemAtURL(directoryTrashURL)
|
||||
try! fileManager.removeItem(at: directoryTrashURL)
|
||||
}
|
||||
}
|
||||
|
||||
func testCopyFiles()
|
||||
{
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
|
||||
XCTAssertNil(try? fileManager.copyItemAtURL(ordinaryFileURL, toURL: directoryURL))
|
||||
XCTAssertNil(try? fileManager.copyItemAtURL(ordinaryFileURL, toURL: directoryURL.URLByAppendingPathComponent("foo").URLByAppendingPathComponent("bar")))
|
||||
XCTAssertNil(try? fileManager.copyItemAtURL(rootURL.URLByAppendingPathComponent("does not exist"), toURL: directoryURL))
|
||||
XCTAssertNil(try? fileManager.copyItem(at: ordinaryFileURL, to: directoryURL))
|
||||
XCTAssertNil(try? fileManager.copyItem(at: ordinaryFileURL, to: directoryURL.appendingPathComponent("foo").appendingPathComponent("bar")))
|
||||
XCTAssertNil(try? fileManager.copyItem(at: rootURL.appendingPathComponent("does not exist"), to: directoryURL))
|
||||
|
||||
let newFileURL = (ordinaryFileURL.URLByDeletingLastPathComponent?.URLByAppendingPathComponent("new file"))!
|
||||
try! fileManager.copyItemAtURL(ordinaryFileURL, toURL: newFileURL)
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(ordinaryFileURL))
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(newFileURL))
|
||||
let newFileURL = (ordinaryFileURL.deletingLastPathComponent().appendingPathComponent("new file"))
|
||||
try! fileManager.copyItem(at: ordinaryFileURL, to: newFileURL)
|
||||
XCTAssertTrue(fileManager._itemExists(at: ordinaryFileURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: newFileURL))
|
||||
|
||||
let newSymlinkURL = (ordinaryFileURL.URLByDeletingLastPathComponent?.URLByAppendingPathComponent("new symlink file"))!
|
||||
try! fileManager.copyItemAtURL(invalidSymlinkURL, toURL: newSymlinkURL)
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(newSymlinkURL))
|
||||
let newSymlinkURL = (ordinaryFileURL.deletingLastPathComponent().appendingPathComponent("new symlink file"))
|
||||
try! fileManager.copyItem(at: invalidSymlinkURL, to: newSymlinkURL)
|
||||
XCTAssertTrue(fileManager._itemExists(at: newSymlinkURL))
|
||||
|
||||
let newDirectoryURL = (ordinaryFileURL.URLByDeletingLastPathComponent?.URLByAppendingPathComponent("new directory"))!
|
||||
try! fileManager.copyItemAtURL(directoryURL, toURL: newDirectoryURL)
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(directoryURL))
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(newDirectoryURL))
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(fileInDirectoryURL))
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(newDirectoryURL.URLByAppendingPathComponent(fileInDirectoryURL.lastPathComponent!)))
|
||||
let newDirectoryURL = (ordinaryFileURL.deletingLastPathComponent().appendingPathComponent("new directory"))
|
||||
try! fileManager.copyItem(at: directoryURL, to: newDirectoryURL)
|
||||
XCTAssertTrue(fileManager._itemExists(at: directoryURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: newDirectoryURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: fileInDirectoryURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: newDirectoryURL.appendingPathComponent(fileInDirectoryURL.lastPathComponent)))
|
||||
}
|
||||
}
|
||||
|
||||
func testRemoveFiles()
|
||||
{
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
|
||||
XCTAssertNil(try? fileManager.removeItemAtURL(rootURL.URLByAppendingPathComponent("does not exist")))
|
||||
XCTAssertNil(try? fileManager.removeItem(at: rootURL.appendingPathComponent("does not exist")))
|
||||
|
||||
try! fileManager.removeItemAtURL(ordinaryFileURL)
|
||||
XCTAssertFalse(fileManager._itemExistsAtURL(ordinaryFileURL))
|
||||
try! fileManager.removeItem(at: ordinaryFileURL)
|
||||
XCTAssertFalse(fileManager._itemExists(at: ordinaryFileURL))
|
||||
|
||||
try! fileManager.removeItemAtURL(validSymlinkURL)
|
||||
XCTAssertFalse(fileManager._itemExistsAtURL(validSymlinkURL))
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(directoryURL))
|
||||
try! fileManager.removeItem(at: validSymlinkURL)
|
||||
XCTAssertFalse(fileManager._itemExists(at: validSymlinkURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: directoryURL))
|
||||
|
||||
try! fileManager.removeItemAtURL(directoryURL)
|
||||
XCTAssertFalse(fileManager._itemExistsAtURL(directoryURL))
|
||||
XCTAssertFalse(fileManager._itemExistsAtURL(fileInDirectoryURL))
|
||||
try! fileManager.removeItem(at: directoryURL)
|
||||
XCTAssertFalse(fileManager._itemExists(at: directoryURL))
|
||||
XCTAssertFalse(fileManager._itemExists(at: fileInDirectoryURL))
|
||||
}
|
||||
}
|
||||
|
||||
func testReleaseFilesFromQuarantine()
|
||||
{
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
|
||||
try! fileManager.releaseItemFromQuarantineAtRootURL(ordinaryFileURL)
|
||||
try! fileManager.releaseItemFromQuarantineAtRootURL(directoryURL)
|
||||
try! fileManager.releaseItemFromQuarantineAtRootURL(validSymlinkURL)
|
||||
try! fileManager.releaseItemFromQuarantine(atRootURL: ordinaryFileURL)
|
||||
try! fileManager.releaseItemFromQuarantine(atRootURL: directoryURL)
|
||||
try! fileManager.releaseItemFromQuarantine(atRootURL: validSymlinkURL)
|
||||
|
||||
let quarantineData = "does not really matter what is here".cStringUsingEncoding(NSUTF8StringEncoding)!
|
||||
let quarantineData = "does not really matter what is here".cString(using: String.Encoding.utf8)!
|
||||
let quarantineDataLength = Int(strlen(quarantineData))
|
||||
|
||||
XCTAssertEqual(0, setxattr(ordinaryFileURL.path!, SUAppleQuarantineIdentifier, quarantineData, quarantineDataLength, 0, XATTR_CREATE))
|
||||
XCTAssertGreaterThan(getxattr(ordinaryFileURL.path!, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW), 0)
|
||||
XCTAssertEqual(0, setxattr(ordinaryFileURL.path, SUAppleQuarantineIdentifier, quarantineData, quarantineDataLength, 0, XATTR_CREATE))
|
||||
XCTAssertGreaterThan(getxattr(ordinaryFileURL.path, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW), 0)
|
||||
|
||||
try! fileManager.releaseItemFromQuarantineAtRootURL(ordinaryFileURL)
|
||||
XCTAssertEqual(-1, getxattr(ordinaryFileURL.path!, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW))
|
||||
try! fileManager.releaseItemFromQuarantine(atRootURL: ordinaryFileURL)
|
||||
XCTAssertEqual(-1, getxattr(ordinaryFileURL.path, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW))
|
||||
|
||||
XCTAssertEqual(0, setxattr(directoryURL.path!, SUAppleQuarantineIdentifier, quarantineData, quarantineDataLength, 0, XATTR_CREATE))
|
||||
XCTAssertGreaterThan(getxattr(directoryURL.path!, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW), 0)
|
||||
XCTAssertEqual(0, setxattr(directoryURL.path, SUAppleQuarantineIdentifier, quarantineData, quarantineDataLength, 0, XATTR_CREATE))
|
||||
XCTAssertGreaterThan(getxattr(directoryURL.path, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW), 0)
|
||||
|
||||
XCTAssertEqual(0, setxattr(fileInDirectoryURL.path!, SUAppleQuarantineIdentifier, quarantineData, quarantineDataLength, 0, XATTR_CREATE))
|
||||
XCTAssertGreaterThan(getxattr(fileInDirectoryURL.path!, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW), 0)
|
||||
XCTAssertEqual(0, setxattr(fileInDirectoryURL.path, SUAppleQuarantineIdentifier, quarantineData, quarantineDataLength, 0, XATTR_CREATE))
|
||||
XCTAssertGreaterThan(getxattr(fileInDirectoryURL.path, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW), 0)
|
||||
|
||||
// Extended attributes can't be set on symbolic links currently
|
||||
try! fileManager.releaseItemFromQuarantineAtRootURL(validSymlinkURL)
|
||||
XCTAssertGreaterThan(getxattr(directoryURL.path!, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW), 0)
|
||||
XCTAssertEqual(-1, getxattr(validSymlinkURL.path!, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW))
|
||||
try! fileManager.releaseItemFromQuarantine(atRootURL: validSymlinkURL)
|
||||
XCTAssertGreaterThan(getxattr(directoryURL.path, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW), 0)
|
||||
XCTAssertEqual(-1, getxattr(validSymlinkURL.path, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW))
|
||||
|
||||
try! fileManager.releaseItemFromQuarantineAtRootURL(directoryURL)
|
||||
try! fileManager.releaseItemFromQuarantine(atRootURL: directoryURL)
|
||||
|
||||
XCTAssertEqual(-1, getxattr(directoryURL.path!, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW))
|
||||
XCTAssertEqual(-1, getxattr(fileInDirectoryURL.path!, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW))
|
||||
XCTAssertEqual(-1, getxattr(directoryURL.path, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW))
|
||||
XCTAssertEqual(-1, getxattr(fileInDirectoryURL.path, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW))
|
||||
}
|
||||
}
|
||||
|
||||
func groupIDAtPath(path: String) -> gid_t
|
||||
func groupIDAtPath(_ path: String) -> gid_t
|
||||
{
|
||||
let attributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(path)
|
||||
let groupID = attributes[NSFileGroupOwnerAccountID] as! NSNumber
|
||||
return groupID.unsignedIntValue
|
||||
let attributes = try! FileManager.default.attributesOfItem(atPath: path)
|
||||
let groupID = attributes[FileAttributeKey.groupOwnerAccountID] as! NSNumber
|
||||
return groupID.uint32Value
|
||||
}
|
||||
|
||||
// Only the super user can alter user IDs, so changing user IDs is not tested here
|
||||
@@ -191,126 +191,126 @@ class SUFileManagerTest: XCTestCase
|
||||
func testAlterFilesGroupID()
|
||||
{
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
|
||||
XCTAssertNil(try? fileManager.changeOwnerAndGroupOfItemAtRootURL(ordinaryFileURL, toMatchURL: rootURL.URLByAppendingPathComponent("does not exist")))
|
||||
XCTAssertNil(try? fileManager.changeOwnerAndGroupOfItem(atRootURL: ordinaryFileURL, toMatch: rootURL.appendingPathComponent("does not exist")))
|
||||
|
||||
XCTAssertNil(try? fileManager.changeOwnerAndGroupOfItemAtRootURL(rootURL.URLByAppendingPathComponent("does not exist"), toMatchURL: ordinaryFileURL))
|
||||
XCTAssertNil(try? fileManager.changeOwnerAndGroupOfItem(atRootURL: rootURL.appendingPathComponent("does not exist"), toMatch: ordinaryFileURL))
|
||||
|
||||
let everyoneGroup = getgrnam("everyone")
|
||||
let everyoneGroupID = everyoneGroup.memory.gr_gid
|
||||
let everyoneGroupID = everyoneGroup?.pointee.gr_gid
|
||||
|
||||
let staffGroup = getgrnam("staff")
|
||||
let staffGroupID = staffGroup.memory.gr_gid
|
||||
let staffGroupID = staffGroup?.pointee.gr_gid
|
||||
|
||||
XCTAssertNotEqual(staffGroupID, everyoneGroupID)
|
||||
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(ordinaryFileURL.path!))
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(directoryURL.path!))
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(fileInDirectoryURL.path!))
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(validSymlinkURL.path!))
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(ordinaryFileURL.path))
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(directoryURL.path))
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(fileInDirectoryURL.path))
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(validSymlinkURL.path))
|
||||
|
||||
try! fileManager.changeOwnerAndGroupOfItemAtRootURL(fileInDirectoryURL, toMatchURL: ordinaryFileURL)
|
||||
try! fileManager.changeOwnerAndGroupOfItemAtRootURL(ordinaryFileURL, toMatchURL: ordinaryFileURL)
|
||||
try! fileManager.changeOwnerAndGroupOfItemAtRootURL(validSymlinkURL, toMatchURL: ordinaryFileURL)
|
||||
try! fileManager.changeOwnerAndGroupOfItem(atRootURL: fileInDirectoryURL, toMatch: ordinaryFileURL)
|
||||
try! fileManager.changeOwnerAndGroupOfItem(atRootURL: ordinaryFileURL, toMatch: ordinaryFileURL)
|
||||
try! fileManager.changeOwnerAndGroupOfItem(atRootURL: validSymlinkURL, toMatch: ordinaryFileURL)
|
||||
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(ordinaryFileURL.path!))
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(directoryURL.path!))
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(validSymlinkURL.path!))
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(ordinaryFileURL.path))
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(directoryURL.path))
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(validSymlinkURL.path))
|
||||
|
||||
XCTAssertEqual(0, chown(ordinaryFileURL.path!, getuid(), everyoneGroupID))
|
||||
XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(ordinaryFileURL.path!))
|
||||
XCTAssertEqual(0, chown(ordinaryFileURL.path, getuid(), everyoneGroupID!))
|
||||
XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(ordinaryFileURL.path))
|
||||
|
||||
try! fileManager.changeOwnerAndGroupOfItemAtRootURL(fileInDirectoryURL, toMatchURL: ordinaryFileURL)
|
||||
XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(fileInDirectoryURL.path!))
|
||||
try! fileManager.changeOwnerAndGroupOfItem(atRootURL: fileInDirectoryURL, toMatch: ordinaryFileURL)
|
||||
XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(fileInDirectoryURL.path))
|
||||
|
||||
try! fileManager.changeOwnerAndGroupOfItemAtRootURL(fileInDirectoryURL, toMatchURL: directoryURL)
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(fileInDirectoryURL.path!))
|
||||
try! fileManager.changeOwnerAndGroupOfItem(atRootURL: fileInDirectoryURL, toMatch: directoryURL)
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(fileInDirectoryURL.path))
|
||||
|
||||
try! fileManager.changeOwnerAndGroupOfItemAtRootURL(validSymlinkURL, toMatchURL: ordinaryFileURL)
|
||||
XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(validSymlinkURL.path!))
|
||||
try! fileManager.changeOwnerAndGroupOfItem(atRootURL: validSymlinkURL, toMatch: ordinaryFileURL)
|
||||
XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(validSymlinkURL.path))
|
||||
|
||||
try! fileManager.changeOwnerAndGroupOfItemAtRootURL(directoryURL, toMatchURL: ordinaryFileURL)
|
||||
XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(directoryURL.path!))
|
||||
XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(fileInDirectoryURL.path!))
|
||||
try! fileManager.changeOwnerAndGroupOfItem(atRootURL: directoryURL, toMatch: ordinaryFileURL)
|
||||
XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(directoryURL.path))
|
||||
XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(fileInDirectoryURL.path))
|
||||
}
|
||||
}
|
||||
|
||||
func testUpdateFileModificationTime()
|
||||
{
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
|
||||
XCTAssertNil(try? fileManager.updateModificationAndAccessTimeOfItemAtURL(rootURL.URLByAppendingPathComponent("does not exist")))
|
||||
XCTAssertNil(try? fileManager.updateModificationAndAccessTimeOfItem(at: rootURL.appendingPathComponent("does not exist")))
|
||||
|
||||
let oldOrdinaryFileAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(ordinaryFileURL.path!)
|
||||
let oldDirectoryAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(directoryURL.path!)
|
||||
let oldValidSymlinkAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(validSymlinkURL.path!)
|
||||
let oldOrdinaryFileAttributes = try! FileManager.default.attributesOfItem(atPath: ordinaryFileURL.path)
|
||||
let oldDirectoryAttributes = try! FileManager.default.attributesOfItem(atPath: directoryURL.path)
|
||||
let oldValidSymlinkAttributes = try! FileManager.default.attributesOfItem(atPath: validSymlinkURL.path)
|
||||
|
||||
sleep(1); // wait for clock to advance
|
||||
|
||||
try! fileManager.updateModificationAndAccessTimeOfItemAtURL(ordinaryFileURL)
|
||||
try! fileManager.updateModificationAndAccessTimeOfItemAtURL(directoryURL)
|
||||
try! fileManager.updateModificationAndAccessTimeOfItemAtURL(validSymlinkURL)
|
||||
try! fileManager.updateModificationAndAccessTimeOfItem(at: ordinaryFileURL)
|
||||
try! fileManager.updateModificationAndAccessTimeOfItem(at: directoryURL)
|
||||
try! fileManager.updateModificationAndAccessTimeOfItem(at: validSymlinkURL)
|
||||
|
||||
let newOrdinaryFileAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(ordinaryFileURL.path!)
|
||||
XCTAssertGreaterThan((newOrdinaryFileAttributes[NSFileModificationDate] as! NSDate).timeIntervalSinceDate(oldOrdinaryFileAttributes[NSFileModificationDate] as! NSDate), 0)
|
||||
let newOrdinaryFileAttributes = try! FileManager.default.attributesOfItem(atPath: ordinaryFileURL.path)
|
||||
XCTAssertGreaterThan((newOrdinaryFileAttributes[FileAttributeKey.modificationDate] as! Date).timeIntervalSince(oldOrdinaryFileAttributes[FileAttributeKey.modificationDate] as! Date), 0)
|
||||
|
||||
let newDirectoryAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(directoryURL.path!)
|
||||
XCTAssertGreaterThan((newDirectoryAttributes[NSFileModificationDate] as! NSDate).timeIntervalSinceDate(oldDirectoryAttributes[NSFileModificationDate] as! NSDate), 0)
|
||||
let newDirectoryAttributes = try! FileManager.default.attributesOfItem(atPath: directoryURL.path)
|
||||
XCTAssertGreaterThan((newDirectoryAttributes[FileAttributeKey.modificationDate] as! Date).timeIntervalSince(oldDirectoryAttributes[FileAttributeKey.modificationDate] as! Date), 0)
|
||||
|
||||
let newSymlinkAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(validSymlinkURL.path!)
|
||||
XCTAssertGreaterThan((newSymlinkAttributes[NSFileModificationDate] as! NSDate).timeIntervalSinceDate(oldValidSymlinkAttributes[NSFileModificationDate] as! NSDate), 0)
|
||||
let newSymlinkAttributes = try! FileManager.default.attributesOfItem(atPath: validSymlinkURL.path)
|
||||
XCTAssertGreaterThan((newSymlinkAttributes[FileAttributeKey.modificationDate] as! Date).timeIntervalSince(oldValidSymlinkAttributes[FileAttributeKey.modificationDate] as! Date), 0)
|
||||
}
|
||||
}
|
||||
|
||||
func testFileExists()
|
||||
{
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(ordinaryFileURL))
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(directoryURL))
|
||||
XCTAssertFalse(fileManager._itemExistsAtURL(rootURL.URLByAppendingPathComponent("does not exist")))
|
||||
XCTAssertTrue(fileManager._itemExists(at: ordinaryFileURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: directoryURL))
|
||||
XCTAssertFalse(fileManager._itemExists(at: rootURL.appendingPathComponent("does not exist")))
|
||||
|
||||
var isOrdinaryFileDirectory: ObjCBool = false
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(ordinaryFileURL, isDirectory: &isOrdinaryFileDirectory) && !isOrdinaryFileDirectory)
|
||||
XCTAssertTrue(fileManager._itemExists(at: ordinaryFileURL, isDirectory: &isOrdinaryFileDirectory) && !isOrdinaryFileDirectory.boolValue)
|
||||
|
||||
var isDirectoryADirectory: ObjCBool = false
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(directoryURL, isDirectory: &isDirectoryADirectory) && isDirectoryADirectory)
|
||||
XCTAssertTrue(fileManager._itemExists(at: directoryURL, isDirectory: &isDirectoryADirectory) && isDirectoryADirectory.boolValue)
|
||||
|
||||
XCTAssertFalse(fileManager._itemExistsAtURL(rootURL.URLByAppendingPathComponent("does not exist"), isDirectory: nil))
|
||||
XCTAssertFalse(fileManager._itemExists(at: rootURL.appendingPathComponent("does not exist"), isDirectory: nil))
|
||||
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(validSymlinkURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: validSymlinkURL))
|
||||
|
||||
var validSymlinkIsADirectory: ObjCBool = false
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(validSymlinkURL, isDirectory: &validSymlinkIsADirectory) && !validSymlinkIsADirectory)
|
||||
XCTAssertTrue(fileManager._itemExists(at: validSymlinkURL, isDirectory: &validSymlinkIsADirectory) && !validSymlinkIsADirectory.boolValue)
|
||||
|
||||
// Symlink should still exist even if it doesn't point to a file that exists
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(invalidSymlinkURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: invalidSymlinkURL))
|
||||
|
||||
var invalidSymlinkIsADirectory: ObjCBool = false
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(invalidSymlinkURL, isDirectory: &invalidSymlinkIsADirectory) && !invalidSymlinkIsADirectory)
|
||||
XCTAssertTrue(fileManager._itemExists(at: invalidSymlinkURL, isDirectory: &invalidSymlinkIsADirectory) && !invalidSymlinkIsADirectory.boolValue)
|
||||
}
|
||||
}
|
||||
|
||||
func testMakeDirectory()
|
||||
{
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
|
||||
XCTAssertNil(try? fileManager.makeDirectoryAtURL(ordinaryFileURL))
|
||||
XCTAssertNil(try? fileManager.makeDirectoryAtURL(directoryURL))
|
||||
XCTAssertNil(try? fileManager.makeDirectory(at: ordinaryFileURL))
|
||||
XCTAssertNil(try? fileManager.makeDirectory(at: directoryURL))
|
||||
|
||||
XCTAssertNil(try? fileManager.makeDirectoryAtURL(rootURL.URLByAppendingPathComponent("this should").URLByAppendingPathComponent("be a failure")))
|
||||
XCTAssertNil(try? fileManager.makeDirectory(at: rootURL.appendingPathComponent("this should").appendingPathComponent("be a failure")))
|
||||
|
||||
let newDirectoryURL = rootURL.URLByAppendingPathComponent("new test directory")
|
||||
XCTAssertFalse(fileManager._itemExistsAtURL(newDirectoryURL))
|
||||
try! fileManager.makeDirectoryAtURL(newDirectoryURL)
|
||||
let newDirectoryURL = rootURL.appendingPathComponent("new test directory")
|
||||
XCTAssertFalse(fileManager._itemExists(at: newDirectoryURL))
|
||||
try! fileManager.makeDirectory(at: newDirectoryURL)
|
||||
|
||||
var isDirectory: ObjCBool = false
|
||||
XCTAssertTrue(fileManager._itemExistsAtURL(newDirectoryURL, isDirectory: &isDirectory))
|
||||
XCTAssertTrue(fileManager._itemExists(at: newDirectoryURL, isDirectory: &isDirectory))
|
||||
|
||||
try! fileManager.removeItemAtURL(directoryURL)
|
||||
XCTAssertNil(try? fileManager.makeDirectoryAtURL(validSymlinkURL))
|
||||
try! fileManager.removeItem(at: directoryURL)
|
||||
XCTAssertNil(try? fileManager.makeDirectory(at: validSymlinkURL))
|
||||
}
|
||||
}
|
||||
|
||||
func testAcquireBadAuthorization()
|
||||
{
|
||||
let fileManager = SUFileManager.defaultManager()
|
||||
XCTAssertNil(try? fileManager._acquireAuthorization())
|
||||
let fileManager = SUFileManager.default()
|
||||
XCTAssertNil(try? fileManager?._acquireAuthorization())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// SUSpotlightImporterTest.swift
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 8/27/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
class SUSpotlightImporterTest: XCTestCase
|
||||
{
|
||||
func testUpdatingSpotlightBundles()
|
||||
{
|
||||
let fileManager = SUFileManager.default()
|
||||
let tempDirectoryURL = try! fileManager?.makeTemporaryDirectory(withPreferredName: "Sparkle Unit Test Data", appropriateForDirectoryURL: URL(fileURLWithPath: NSHomeDirectory()))
|
||||
|
||||
let bundleDirectory = tempDirectoryURL?.appendingPathComponent("bundle.app")
|
||||
try! fileManager?.makeDirectory(at: bundleDirectory)
|
||||
|
||||
let innerDirectory = bundleDirectory?.appendingPathComponent("foo")
|
||||
try! fileManager?.makeDirectory(at: innerDirectory)
|
||||
try! Data().write(to: (bundleDirectory?.appendingPathComponent("bar"))!, options: .atomicWrite)
|
||||
|
||||
let importerDirectory = innerDirectory?.appendingPathComponent("baz.mdimporter")
|
||||
|
||||
try! fileManager?.makeDirectory(at: importerDirectory)
|
||||
try! fileManager?.makeDirectory(at: innerDirectory?.appendingPathComponent("flag"))
|
||||
|
||||
try! Data().write(to: (importerDirectory?.appendingPathComponent("file"))!, options: .atomicWrite)
|
||||
|
||||
let oldFooDirectoryAttributes = try! FileManager.default.attributesOfItem(atPath: innerDirectory!.path)
|
||||
let oldBarFileAttributes = try! FileManager.default.attributesOfItem(atPath: bundleDirectory!.appendingPathComponent("bar").path)
|
||||
let oldImporterAttributes = try! FileManager.default.attributesOfItem(atPath: importerDirectory!.path)
|
||||
let oldFlagAttributes = try! FileManager.default.attributesOfItem(atPath: innerDirectory!.appendingPathComponent("flag").path)
|
||||
let oldFileInImporterAttributes = try! FileManager.default.attributesOfItem(atPath: importerDirectory!.appendingPathComponent("file").path)
|
||||
|
||||
sleep(1) // wait for clock to advance
|
||||
|
||||
// Update spotlight bundles
|
||||
SUBinaryDeltaUnarchiver.updateSpotlightImporters(atBundlePath: bundleDirectory!.path)
|
||||
|
||||
let newFooDirectoryAttributes = try! FileManager.default.attributesOfItem(atPath: innerDirectory!.path)
|
||||
XCTAssertEqual((newFooDirectoryAttributes[FileAttributeKey.modificationDate] as! Date).timeIntervalSince(oldFooDirectoryAttributes[FileAttributeKey.modificationDate] as! Date), 0)
|
||||
|
||||
let newBarFileAttributes = try! FileManager.default.attributesOfItem(atPath: bundleDirectory!.appendingPathComponent("bar").path)
|
||||
XCTAssertEqual((newBarFileAttributes[FileAttributeKey.modificationDate] as! Date).timeIntervalSince(oldBarFileAttributes[FileAttributeKey.modificationDate] as! Date), 0)
|
||||
|
||||
let newImporterAttributes = try! FileManager.default.attributesOfItem(atPath: importerDirectory!.path)
|
||||
XCTAssertGreaterThan((newImporterAttributes[FileAttributeKey.modificationDate] as! Date).timeIntervalSince(oldImporterAttributes[FileAttributeKey.modificationDate] as! Date), 0)
|
||||
|
||||
let newFlagAttributes = try! FileManager.default.attributesOfItem(atPath: innerDirectory!.appendingPathComponent("flag").path)
|
||||
XCTAssertEqual((newFlagAttributes[FileAttributeKey.modificationDate] as! Date).timeIntervalSince(oldFlagAttributes[FileAttributeKey.modificationDate] as! Date), 0)
|
||||
|
||||
let newFileInImporterAttributes = try! FileManager.default.attributesOfItem(atPath: importerDirectory!.appendingPathComponent("file").path)
|
||||
XCTAssertEqual((newFileInImporterAttributes[FileAttributeKey.modificationDate] as! Date).timeIntervalSince(oldFileInImporterAttributes[FileAttributeKey.modificationDate] as! Date), 0)
|
||||
|
||||
try! fileManager?.removeItem(at: tempDirectoryURL)
|
||||
}
|
||||
}
|
||||
@@ -14,52 +14,52 @@ class SUUnarchiverTest: XCTestCase, SUUnarchiverDelegate
|
||||
var unarchivedExpectation: XCTestExpectation? = nil
|
||||
var unarchivedResult: Bool = false
|
||||
|
||||
func unarchiver(unarchiver: SUUnarchiver!, extractedProgress progress: Double)
|
||||
func unarchiver(_ unarchiver: SUUnarchiver!, extractedProgress progress: Double)
|
||||
{
|
||||
}
|
||||
|
||||
func unarchiverDidFail(unarchiver: SUUnarchiver!)
|
||||
func unarchiverDidFail(_ unarchiver: SUUnarchiver!)
|
||||
{
|
||||
self.unarchivedResult = false
|
||||
self.unarchivedExpectation!.fulfill()
|
||||
}
|
||||
|
||||
func unarchiverDidFinish(unarchiver: SUUnarchiver!)
|
||||
func unarchiverDidFinish(_ unarchiver: SUUnarchiver!)
|
||||
{
|
||||
self.unarchivedResult = true
|
||||
self.unarchivedExpectation!.fulfill()
|
||||
}
|
||||
|
||||
func unarchiveTestAppWithExtension(archiveExtension: String)
|
||||
func unarchiveTestAppWithExtension(_ archiveExtension: String)
|
||||
{
|
||||
let appName = "SparkleTestCodeSignApp"
|
||||
let archiveResourceURL = NSBundle(forClass: self.dynamicType).URLForResource(appName, withExtension: archiveExtension)!
|
||||
let archiveResourceURL = Bundle(for: type(of: self)).url(forResource: appName, withExtension: archiveExtension)!
|
||||
|
||||
let fileManager = NSFileManager.defaultManager()
|
||||
let fileManager = FileManager.default
|
||||
|
||||
let tempDirectoryURL = try! fileManager.URLForDirectory(.ItemReplacementDirectory, inDomain: .UserDomainMask, appropriateForURL: NSURL(fileURLWithPath: NSHomeDirectory()), create: true)
|
||||
let tempDirectoryURL = try! fileManager.url(for: .itemReplacementDirectory, in: .userDomainMask, appropriateFor: URL(fileURLWithPath: NSHomeDirectory()), create: true)
|
||||
defer {
|
||||
try! fileManager.removeItemAtURL(tempDirectoryURL)
|
||||
try! fileManager.removeItem(at: tempDirectoryURL)
|
||||
}
|
||||
|
||||
let tempArchiveURL = tempDirectoryURL.URLByAppendingPathComponent(archiveResourceURL.lastPathComponent!)
|
||||
let extractedAppURL = tempDirectoryURL.URLByAppendingPathComponent(appName).URLByAppendingPathExtension("app")
|
||||
let tempArchiveURL = tempDirectoryURL.appendingPathComponent(archiveResourceURL.lastPathComponent)
|
||||
let extractedAppURL = tempDirectoryURL.appendingPathComponent(appName).appendingPathExtension("app")
|
||||
|
||||
try! fileManager.copyItemAtURL(archiveResourceURL, toURL: tempArchiveURL)
|
||||
try! fileManager.copyItem(at: archiveResourceURL, to: tempArchiveURL)
|
||||
|
||||
self.unarchivedExpectation = super.expectationWithDescription("Unarchived Application (format: \(archiveExtension))")
|
||||
self.unarchivedExpectation = super.expectation(description: "Unarchived Application (format: \(archiveExtension))")
|
||||
|
||||
let unarchiver = SUUnarchiver(forPath: tempArchiveURL.path!, updatingHostBundlePath: nil, withPassword: self.password)
|
||||
let unarchiver = SUUnarchiver(forPath: tempArchiveURL.path, updatingHostBundlePath: nil, withPassword: self.password)
|
||||
|
||||
unarchiver.delegate = self
|
||||
unarchiver.start()
|
||||
unarchiver?.delegate = self
|
||||
unarchiver?.start()
|
||||
|
||||
super.waitForExpectationsWithTimeout(7.0, handler: nil)
|
||||
super.waitForExpectations(timeout: 7.0, handler: nil)
|
||||
|
||||
XCTAssertTrue(self.unarchivedResult)
|
||||
XCTAssertTrue(fileManager.fileExistsAtPath(extractedAppURL.path!))
|
||||
XCTAssertTrue(fileManager.fileExists(atPath: extractedAppURL.path))
|
||||
|
||||
XCTAssertEqual("6a60ab31430cfca8fb499a884f4a29f73e59b472", hashOfTree(extractedAppURL.path!))
|
||||
XCTAssertEqual("6a60ab31430cfca8fb499a884f4a29f73e59b472", hashOfTree(extractedAppURL.path))
|
||||
}
|
||||
|
||||
func testUnarchivingZip()
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
//
|
||||
|
||||
#import "SUUnarchiver.h"
|
||||
#import "SUBinaryDeltaUnarchiver.h"
|
||||
#import "SUPipedUnarchiver.h"
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
#import "SUFileManager.h"
|
||||
@@ -35,3 +36,8 @@ static const char *SUAppleQuarantineIdentifier = "com.apple.quarantine";
|
||||
- (NSArray *)parseAppcastItemsFromXMLFile:(NSURL *)appcastFile error:(NSError *__autoreleasing*)errorp;
|
||||
@end
|
||||
|
||||
@interface SUBinaryDeltaUnarchiver (Private)
|
||||
|
||||
+ (void)updateSpotlightImportersAtBundlePath:(NSString *)targetPath;
|
||||
|
||||
@end
|
||||
@@ -10,14 +10,14 @@ import XCTest
|
||||
|
||||
class SUTestApplicationTest: XCTestCase
|
||||
{
|
||||
var testApplicationURL: NSURL? = nil
|
||||
var testApplicationBackupURL: NSURL? = nil
|
||||
var tempDirectoryURL: NSURL? = nil
|
||||
var testApplicationURL: URL? = nil
|
||||
var testApplicationBackupURL: URL? = nil
|
||||
var tempDirectoryURL: URL? = nil
|
||||
|
||||
func runningTestApplication() -> NSRunningApplication
|
||||
{
|
||||
// TODO: don't hardcode bundle ID?
|
||||
let runningApplications = NSRunningApplication.runningApplicationsWithBundleIdentifier("org.sparkle-project.SparkleTestApp")
|
||||
let runningApplications = NSRunningApplication.runningApplications(withBundleIdentifier: "org.sparkle-project.SparkleTestApp")
|
||||
XCTAssertEqual(runningApplications.count, 1, "More than one or zero running instances of the Test Application are found")
|
||||
return runningApplications[0]
|
||||
}
|
||||
@@ -35,11 +35,11 @@ class SUTestApplicationTest: XCTestCase
|
||||
// When a successful test is over we'll revert the update
|
||||
let testApplicationURL = self.runningTestApplication().bundleURL!
|
||||
|
||||
let tempDirectoryURL = try! NSFileManager.defaultManager().URLForDirectory(.ItemReplacementDirectory, inDomain: NSSearchPathDomainMask.UserDomainMask, appropriateForURL: testApplicationURL, create: true)
|
||||
let tempDirectoryURL = try! FileManager.default.url(for: .itemReplacementDirectory, in: FileManager.SearchPathDomainMask.userDomainMask, appropriateFor: testApplicationURL, create: true)
|
||||
|
||||
let testApplicationBackupURL = tempDirectoryURL.URLByAppendingPathComponent(testApplicationURL.lastPathComponent!)
|
||||
let testApplicationBackupURL = tempDirectoryURL.appendingPathComponent(testApplicationURL.lastPathComponent)
|
||||
|
||||
try! NSFileManager.defaultManager().copyItemAtURL(testApplicationURL, toURL: testApplicationBackupURL)
|
||||
try! FileManager.default.copyItem(at: testApplicationURL, to: testApplicationBackupURL)
|
||||
|
||||
self.testApplicationURL = testApplicationURL
|
||||
self.testApplicationBackupURL = testApplicationBackupURL
|
||||
@@ -58,16 +58,16 @@ class SUTestApplicationTest: XCTestCase
|
||||
// Revert our update with the original test application
|
||||
|
||||
var resultingURL: NSURL? = nil
|
||||
try! NSFileManager.defaultManager().replaceItemAtURL(self.testApplicationURL!, withItemAtURL: self.testApplicationBackupURL!, backupItemName: nil, options: .UsingNewMetadataOnly, resultingItemURL: &resultingURL)
|
||||
try! FileManager.default.replaceItem(at: self.testApplicationURL!, withItemAt: self.testApplicationBackupURL!, backupItemName: nil, options: .usingNewMetadataOnly, resultingItemURL: &resultingURL)
|
||||
|
||||
do {
|
||||
try NSFileManager.defaultManager().removeItemAtURL(self.tempDirectoryURL!)
|
||||
try FileManager.default.removeItem(at: self.tempDirectoryURL!)
|
||||
} catch let error as NSError {
|
||||
NSLog("Failed to remove temporary directory \(self.tempDirectoryURL) with error: \(error)")
|
||||
}
|
||||
|
||||
// The URL we get back from NSFileManager should be the same..
|
||||
XCTAssertEqual(self.testApplicationURL, resultingURL, "Test application was replaced, but at a different location")
|
||||
XCTAssertEqual(self.testApplicationURL, resultingURL as URL?, "Test application was replaced, but at a different location")
|
||||
|
||||
super.tearDown()
|
||||
}
|
||||
@@ -91,7 +91,7 @@ class SUTestApplicationTest: XCTestCase
|
||||
|
||||
// Our new updated app should be launched now. Test if it's the active app
|
||||
// We used to run into timing issues where the updated app sometimes may not show up as the frontmost one
|
||||
XCTAssertTrue(self.runningTestApplication().active)
|
||||
XCTAssertTrue(self.runningTestApplication().isActive)
|
||||
|
||||
// Grab another XCUIApplication instance rather than using the old one, just in case
|
||||
let updatedApp = XCUIApplication()
|
||||
|
||||
Reference in new issue
Block a user