Ben Copsey

Stop using APIs marked as depracated in Snow Leopard

Update NTLM test ready to apply fix
@@ -258,12 +258,19 @@ static NSRecursiveLock *delegateAuthenticationLock = nil; @@ -258,12 +258,19 @@ static NSRecursiveLock *delegateAuthenticationLock = nil;
258 [self setPostBodyWriteStream:nil]; 258 [self setPostBodyWriteStream:nil];
259 } 259 }
260 260
  261 + NSError *err = nil;
  262 + NSString *path;
261 if ([self shouldCompressRequestBody]) { 263 if ([self shouldCompressRequestBody]) {
262 [self setCompressedPostBodyFilePath:[NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]]]; 264 [self setCompressedPostBodyFilePath:[NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]]];
263 [ASIHTTPRequest compressDataFromFile:[self postBodyFilePath] toFile:[self compressedPostBodyFilePath]]; 265 [ASIHTTPRequest compressDataFromFile:[self postBodyFilePath] toFile:[self compressedPostBodyFilePath]];
264 - [self setPostLength:[[[NSFileManager defaultManager] fileAttributesAtPath:[self compressedPostBodyFilePath] traverseLink:NO] fileSize]]; 266 + path = [self compressedPostBodyFilePath];
265 } else { 267 } else {
266 - [self setPostLength:[[[NSFileManager defaultManager] fileAttributesAtPath:[self postBodyFilePath] traverseLink:NO] fileSize]]; 268 + path = [self postBodyFilePath];
  269 + }
  270 + [self setPostLength:[[[NSFileManager defaultManager] attributesOfItemAtPath:path error:&err] fileSize]];
  271 + if (err) {
  272 + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to get attributes for file at path '@%'",path],NSLocalizedDescriptionKey,error,NSUnderlyingErrorKey,nil]]];
  273 + return;
267 } 274 }
268 275
269 // Otherwise, we have an in-memory request body 276 // Otherwise, we have an in-memory request body
@@ -482,7 +489,12 @@ static NSRecursiveLock *delegateAuthenticationLock = nil; @@ -482,7 +489,12 @@ static NSRecursiveLock *delegateAuthenticationLock = nil;
482 489
483 // Should this request resume an existing download? 490 // Should this request resume an existing download?
484 if ([self allowResumeForFileDownloads] && [self downloadDestinationPath] && [self temporaryFileDownloadPath] && [[NSFileManager defaultManager] fileExistsAtPath:[self temporaryFileDownloadPath]]) { 491 if ([self allowResumeForFileDownloads] && [self downloadDestinationPath] && [self temporaryFileDownloadPath] && [[NSFileManager defaultManager] fileExistsAtPath:[self temporaryFileDownloadPath]]) {
485 - [self setPartialDownloadSize:[[[NSFileManager defaultManager] fileAttributesAtPath:[self temporaryFileDownloadPath] traverseLink:NO] fileSize]]; 492 + NSError *err = nil;
  493 + [self setPartialDownloadSize:[[[NSFileManager defaultManager] attributesOfItemAtPath:[self temporaryFileDownloadPath] error:&err] fileSize]];
  494 + if (err) {
  495 + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to get attributes for file at path '@%'",temporaryFileDownloadPath],NSLocalizedDescriptionKey,error,NSUnderlyingErrorKey,nil]]];
  496 + return;
  497 + }
486 [self addRequestHeader:@"Range" value:[NSString stringWithFormat:@"bytes=%llu-",[self partialDownloadSize]]]; 498 [self addRequestHeader:@"Range" value:[NSString stringWithFormat:@"bytes=%llu-",[self partialDownloadSize]]];
487 } 499 }
488 500
@@ -770,7 +782,12 @@ static NSRecursiveLock *delegateAuthenticationLock = nil; @@ -770,7 +782,12 @@ static NSRecursiveLock *delegateAuthenticationLock = nil;
770 782
771 // If we haven't said we might want to resume, let's remove the temporary file too 783 // If we haven't said we might want to resume, let's remove the temporary file too
772 if (![self allowResumeForFileDownloads]) { 784 if (![self allowResumeForFileDownloads]) {
773 - [[NSFileManager defaultManager] removeItemAtPath:temporaryFileDownloadPath error:NULL]; 785 + NSError *err = nil;
  786 + [[NSFileManager defaultManager] removeItemAtPath:temporaryFileDownloadPath error:&err];
  787 + if (err) {
  788 + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to remove temporary file at path '@%'",temporaryFileDownloadPath],NSLocalizedDescriptionKey,error,NSUnderlyingErrorKey,nil]]];
  789 + return;
  790 + }
774 } 791 }
775 } 792 }
776 793
@@ -791,7 +808,7 @@ static NSRecursiveLock *delegateAuthenticationLock = nil; @@ -791,7 +808,7 @@ static NSRecursiveLock *delegateAuthenticationLock = nil;
791 NSError *removeError = nil; 808 NSError *removeError = nil;
792 [[NSFileManager defaultManager] removeItemAtPath:temporaryFileDownloadPath error:&removeError]; 809 [[NSFileManager defaultManager] removeItemAtPath:temporaryFileDownloadPath error:&removeError];
793 if (removeError) { 810 if (removeError) {
794 - [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to delete file at %@ with error: %@",temporaryFileDownloadPath,removeError],NSLocalizedDescriptionKey,removeError,NSUnderlyingErrorKey,nil]]]; 811 + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to delete file at path '%@'",temporaryFileDownloadPath],NSLocalizedDescriptionKey,removeError,NSUnderlyingErrorKey,nil]]];
795 } 812 }
796 [self setTemporaryFileDownloadPath:nil]; 813 [self setTemporaryFileDownloadPath:nil];
797 } 814 }
@@ -803,7 +820,7 @@ static NSRecursiveLock *delegateAuthenticationLock = nil; @@ -803,7 +820,7 @@ static NSRecursiveLock *delegateAuthenticationLock = nil;
803 NSError *removeError = nil; 820 NSError *removeError = nil;
804 [[NSFileManager defaultManager] removeItemAtPath:[self postBodyFilePath] error:&removeError]; 821 [[NSFileManager defaultManager] removeItemAtPath:[self postBodyFilePath] error:&removeError];
805 if (removeError) { 822 if (removeError) {
806 - [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to delete file at %@ with error: %@",[self postBodyFilePath],removeError],NSLocalizedDescriptionKey,removeError,NSUnderlyingErrorKey,nil]]]; 823 + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to delete file at path '%@'",[self postBodyFilePath]],NSLocalizedDescriptionKey,removeError,NSUnderlyingErrorKey,nil]]];
807 } 824 }
808 [self setPostBodyFilePath:nil]; 825 [self setPostBodyFilePath:nil];
809 } 826 }
@@ -811,7 +828,7 @@ static NSRecursiveLock *delegateAuthenticationLock = nil; @@ -811,7 +828,7 @@ static NSRecursiveLock *delegateAuthenticationLock = nil;
811 NSError *removeError = nil; 828 NSError *removeError = nil;
812 [[NSFileManager defaultManager] removeItemAtPath:[self compressedPostBodyFilePath] error:&removeError]; 829 [[NSFileManager defaultManager] removeItemAtPath:[self compressedPostBodyFilePath] error:&removeError];
813 if (removeError) { 830 if (removeError) {
814 - [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to delete file at %@ with error: %@",[self compressedPostBodyFilePath],removeError],NSLocalizedDescriptionKey,removeError,NSUnderlyingErrorKey,nil]]]; 831 + [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to delete file at path '%@'",[self compressedPostBodyFilePath]],NSLocalizedDescriptionKey,removeError,NSUnderlyingErrorKey,nil]]];
815 } 832 }
816 [self setCompressedPostBodyFilePath:nil]; 833 [self setCompressedPostBodyFilePath:nil];
817 } 834 }
@@ -21,7 +21,7 @@ typedef enum _ASIS3ErrorType { @@ -21,7 +21,7 @@ typedef enum _ASIS3ErrorType {
21 21
22 } ASIS3ErrorType; 22 } ASIS3ErrorType;
23 23
24 -@interface ASIS3Request : ASIHTTPRequest { 24 +@interface ASIS3Request : ASIHTTPRequest <NSXMLParserDelegate> {
25 25
26 // Your S3 access key. Set it on the request, or set it globally using [ASIS3Request setSharedAccessKey:] 26 // Your S3 access key. Set it on the request, or set it globally using [ASIS3Request setSharedAccessKey:]
27 NSString *accessKey; 27 NSString *accessKey;
@@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
25 - (void)testCookies; 25 - (void)testCookies;
26 - (void)testBasicAuthentication; 26 - (void)testBasicAuthentication;
27 - (void)testDigestAuthentication; 27 - (void)testDigestAuthentication;
28 -//- (void)testNTLMAuthentication; 28 +- (void)testNTLMHandshake;
29 - (void)testCharacterEncoding; 29 - (void)testCharacterEncoding;
30 - (void)testCompressedResponse; 30 - (void)testCompressedResponse;
31 - (void)testCompressedResponseDownloadToFile; 31 - (void)testCompressedResponseDownloadToFile;
@@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
11 #import "ASINSStringAdditions.h" 11 #import "ASINSStringAdditions.h"
12 #import "ASINetworkQueue.h" 12 #import "ASINetworkQueue.h"
13 #import "ASIFormDataRequest.h" 13 #import "ASIFormDataRequest.h"
  14 +#import <SystemConfiguration/SystemConfiguration.h>
14 15
15 // Used for subclass test 16 // Used for subclass test
16 @interface ASIHTTPRequestSubclass : ASIHTTPRequest {} 17 @interface ASIHTTPRequestSubclass : ASIHTTPRequest {}
@@ -252,7 +253,7 @@ @@ -252,7 +253,7 @@
252 //BOOL success = (![[NSFileManager defaultManager] fileExistsAtPath:tempPath]); 253 //BOOL success = (![[NSFileManager defaultManager] fileExistsAtPath:tempPath]);
253 //GHAssertTrue(success,@"Failed to remove file from temporary location"); 254 //GHAssertTrue(success,@"Failed to remove file from temporary location");
254 255
255 - BOOL success = [[NSString stringWithContentsOfURL:[NSURL fileURLWithPath:path]] isEqualToString:@"This is the expected content for the first string"]; 256 + BOOL success = [[NSString stringWithContentsOfURL:[NSURL fileURLWithPath:path] encoding:NSUTF8StringEncoding error:NULL] isEqualToString:@"This is the expected content for the first string"];
256 GHAssertTrue(success,@"Failed to download data to a file"); 257 GHAssertTrue(success,@"Failed to download data to a file");
257 258
258 } 259 }
@@ -577,43 +578,38 @@ @@ -577,43 +578,38 @@
577 GHAssertTrue(success,@"Failed to clear credentials"); 578 GHAssertTrue(success,@"Failed to clear credentials");
578 } 579 }
579 580
580 -// If you want to run this test, uncomment, and set your hostname, username, password and domain below. 581 +- (void)testNTLMHandshake
581 -//- (void)testNTLMAuthentication 582 +{
582 -//{ 583 + // This test connects to a script that masquerades as an NTLM server
583 -// NSString *theURL = @""; 584 + // It tests that the handshake seems sane, but doesn't actually authenticate
584 -// NSString *username = @""; 585 +
585 -// NSString *password = @""; 586 + [ASIHTTPRequest clearSession];
586 -// NSString *domain = @""; 587 +
587 -// 588 + NSURL *url = [NSURL URLWithString:@"http://asi/ASIHTTPRequest/tests/pretend-ntlm-handshake"];
588 -// if ([theURL isEqualToString:@""] || [username isEqualToString:@""] || [password isEqualToString:@""]) { 589 +
589 -// GHAssertFalse(true,@"Skipping NTLM test because no server details were supplied"); 590 + ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
590 -// } 591 + [request setUseKeychainPersistance:NO];
591 -// 592 + [request setUseSessionPersistance:NO];
592 -// [ASIHTTPRequest clearSession]; 593 + [request start];
593 -// 594 + BOOL success = [[request error] code] == ASIAuthenticationErrorType;
594 -// NSURL *url = [[[NSURL alloc] initWithString:theURL] autorelease]; 595 + GHAssertTrue(success,@"Failed to generate permission denied error with no credentials");
595 -// ASIHTTPRequest *request; 596 +
596 -// BOOL success; 597 +
597 -// NSError *err; 598 + request = [ASIHTTPRequest requestWithURL:url];
598 -// 599 + [request setUseSessionPersistance:YES];
599 -// request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; 600 + [request setUseKeychainPersistance:NO];
600 -// [request setUseKeychainPersistance:NO]; 601 + [request setUsername:@"king"];
601 -// [request setUseSessionPersistance:NO]; 602 + [request setPassword:@"fink"];
602 -// [request start]; 603 + [request setDomain:@"Castle.Kingdom"];
603 -// success = [[request error] code] == ASIAuthenticationErrorType; 604 + [request start];
604 -// GHAssertTrue(success,@"Failed to generate permission denied error with no credentials"); 605 +
605 -// 606 + GHAssertNil([request error],@"Got an error when credentials were supplied");
606 -// 607 +
607 -// request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; 608 + NSString *computerName = [(NSString *)SCDynamicStoreCopyComputerName(NULL,NULL) autorelease];
608 -// [request setUseSessionPersistance:YES]; 609 +
609 -// [request setUseKeychainPersistance:NO]; 610 + success = [[request responseString] isEqualToString:[NSString stringWithFormat:@"You are %@ from %@/%@",@"king",@"Castle.Kingdom",computerName]];
610 -// [request setUsername:username]; 611 + GHAssertTrue(success,@"Failed to send credentials correctly?");
611 -// [request setPassword:password]; 612 +}
612 -// [request setDomain:domain];  
613 -// [request start];  
614 -// err = [request error];  
615 -// GHAssertNil(err,@"Got an error when correct credentials were supplied");  
616 -//}  
617 613
618 - (void)testCompressedResponse 614 - (void)testCompressedResponse
619 { 615 {
@@ -660,7 +656,7 @@ @@ -660,7 +656,7 @@
660 BOOL success = ([request contentLength] == 68); 656 BOOL success = ([request contentLength] == 68);
661 GHAssertTrue(success,@"Failed to download a segment of the data"); 657 GHAssertTrue(success,@"Failed to download a segment of the data");
662 658
663 - NSString *content = [NSString stringWithContentsOfFile:downloadPath]; 659 + NSString *content = [NSString stringWithContentsOfFile:downloadPath encoding:NSUTF8StringEncoding error:NULL];
664 660
665 NSString *newPartialContent = [content substringFromIndex:95]; 661 NSString *newPartialContent = [content substringFromIndex:95];
666 success = ([newPartialContent isEqualToString:@"This is the content we ought to be getting if we start from byte 95."]); 662 success = ([newPartialContent isEqualToString:@"This is the content we ought to be getting if we start from byte 95."]);
@@ -507,8 +507,12 @@ IMPORTANT @@ -507,8 +507,12 @@ IMPORTANT
507 [networkQueue setQueueDidFinishSelector:@selector(queueFinished:)]; 507 [networkQueue setQueueDidFinishSelector:@selector(queueFinished:)];
508 508
509 complete = NO; 509 complete = NO;
510 - progress = 0; 510 + progress = 0;
511 - unsigned long long downloadedSoFar = [[[NSFileManager defaultManager] fileAttributesAtPath:temporaryPath traverseLink:NO] fileSize]; 511 +
  512 + NSError *err = nil;
  513 + unsigned long long downloadedSoFar = [[[NSFileManager defaultManager] attributesOfItemAtPath:temporaryPath error:&err] fileSize];
  514 + GHAssertNil(err,@"Got an error obtaining attributes on the file, this shouldn't happen");
  515 +
512 BOOL success = (downloadedSoFar > 0); 516 BOOL success = (downloadedSoFar > 0);
513 GHAssertTrue(success,@"Failed to download part of the file, so we can't proceed with this test"); 517 GHAssertTrue(success,@"Failed to download part of the file, so we can't proceed with this test");
514 518
@@ -525,7 +529,8 @@ IMPORTANT @@ -525,7 +529,8 @@ IMPORTANT
525 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]]; 529 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
526 } 530 }
527 531
528 - unsigned long long amountDownloaded = [[[NSFileManager defaultManager] fileAttributesAtPath:downloadPath traverseLink:NO] fileSize]; 532 + unsigned long long amountDownloaded = [[[NSFileManager defaultManager] attributesOfItemAtPath:downloadPath error:&err] fileSize];
  533 + GHAssertNil(err,@"Got an error obtaining attributes on the file, this shouldn't happen");
529 success = (amountDownloaded == 9145357); 534 success = (amountDownloaded == 9145357);
530 GHAssertTrue(success,@"Failed to complete the download"); 535 GHAssertTrue(success,@"Failed to complete the download");
531 536
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 { 15 {
16 NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"ASIHTTPRequest Test Files"]; 16 NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"ASIHTTPRequest Test Files"];
17 if (![[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:NULL]) { 17 if (![[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:NULL]) {
18 - [[NSFileManager defaultManager] createDirectoryAtPath:path attributes:nil]; 18 + [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:NO attributes:nil error:NULL];
19 } 19 }
20 return path; 20 return path;
21 } 21 }
This diff was suppressed by a .gitattributes entry.