Skip to content

Commit

Permalink
Fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Sep 3, 2016
1 parent c7a7704 commit 1195d4b
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions Tests/SUCodeSigningVerifierTest.m
Expand Up @@ -77,31 +77,30 @@ - (void)tearDown
- (void)setupValidSignedApp
{
NSError *error = nil;
NSString *tempDir = [self.notSignedAppURL URLByDeletingLastPathComponent];
NSString *signedAndValid = [tempDir URLByAppendingPathComponent:@"valid-signed.app"];
NSURL *tempDir = [self.notSignedAppURL URLByDeletingLastPathComponent];
NSURL *signedAndValid = [tempDir URLByAppendingPathComponent:@"valid-signed.app"];

if ([[NSFileManager defaultManager] fileExistsAtURL:signedAndValid]) {
if ([[NSFileManager defaultManager] fileExistsAtPath:signedAndValid.path]) {
[[NSFileManager defaultManager] removeItemAtURL:signedAndValid error:NULL];
}

if (![[NSFileManager defaultManager] copyItemAtURL:self.notSignedAppURL toPath:signedAndValid error:&error]) {
if (![[NSFileManager defaultManager] copyItemAtURL:self.notSignedAppURL toURL:signedAndValid error:&error]) {
XCTFail("Failed to copy %@ to %@ with error: %@", self.notSignedAppURL, signedAndValid, error);
}

self.validSignedAppURL = signedAndValid;
self.validSignedAppURL = [NSURL fileURLWithPath:signedAndValid];


if (![self codesignAppURL:self.validSignedAppURL]) {
XCTFail(@"Failed to codesign %@", self.validSignedAppURL);
}
}

- (void)setupCalculatorCopy
{
NSString *tempDir = [self.notSignedAppURL URLByDeletingLastPathComponent];
NSString *calculatorCopy = [tempDir URLByAppendingPathComponent:@"calc.app"];
NSURL *tempDir = [self.notSignedAppURL URLByDeletingLastPathComponent];
NSURL *calculatorCopy = [tempDir URLByAppendingPathComponent:@"calc.app"];

if ([[NSFileManager defaultManager] fileExistsAtURL:calculatorCopy]) {
if ([[NSFileManager defaultManager] fileExistsAtPath:calculatorCopy.path]) {
[[NSFileManager defaultManager] removeItemAtURL:calculatorCopy error:NULL];
}

Expand All @@ -110,9 +109,9 @@ - (void)setupCalculatorCopy
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:CALCULATOR_PATH toPath:calculatorCopy error:&copyError];
[[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:CALCULATOR_PATH] toURL:calculatorCopy error:&copyError];

if (![[NSFileManager defaultManager] fileExistsAtURL:calculatorCopy]) {
if (![[NSFileManager defaultManager] fileExistsAtPath:calculatorCopy.path]) {
XCTFail(@"Copied calculator application does not exist");
}

Expand All @@ -129,16 +128,16 @@ - (void)setupCalculatorCopy
- (void)setupInvalidSignedApp
{
NSError *error = nil;
NSString *tempDir = [self.notSignedAppURL URLByDeletingLastPathComponent];
NSString *signedAndInvalid = [tempDir URLByAppendingPathComponent:@"invalid-signed.app"];
NSURL *tempDir = [self.notSignedAppURL URLByDeletingLastPathComponent];
NSURL *signedAndInvalid = [tempDir URLByAppendingPathComponent:@"invalid-signed.app"];

if ([[NSFileManager defaultManager] fileExistsAtURL:signedAndInvalid]) {
if ([[NSFileManager defaultManager] fileExistsAtPath:signedAndInvalid.path]) {
[[NSFileManager defaultManager] removeItemAtURL:signedAndInvalid error:NULL];
}
if ([[NSFileManager defaultManager] copyItemAtURL:self.notSignedAppURL toPath:signedAndInvalid error:&error]) {
if ([[NSFileManager defaultManager] copyItemAtURL:self.notSignedAppURL toURL:signedAndInvalid error:&error]) {
self.invalidSignedAppURL = signedAndInvalid;
if ([self codesignAppURL:self.invalidSignedAppURL]) {
NSString *fileInAppBundleToRemove = [self.invalidSignedAppURL URLByAppendingPathComponent:@"Contents/Resources/test_app_only_dsa_pub.pem"];
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);
}
Expand Down Expand Up @@ -173,7 +172,7 @@ - (BOOL)unzip:(NSString *)zipPath toPath:(NSString *)destPath
return success;
}

- (BOOL)codesignAppURL:(NSString *)appPath
- (BOOL)codesignAppURL:(NSURL *)appPath
{
BOOL success = NO;
@try
Expand Down

0 comments on commit 1195d4b

Please sign in to comment.