Ben Copsey

Merge branch 'master' into authheader

@@ -2293,15 +2293,19 @@ static BOOL isiPhoneOS2; @@ -2293,15 +2293,19 @@ static BOOL isiPhoneOS2;
2293 + (void)removeCredentialsForHost:(NSString *)host port:(int)port protocol:(NSString *)protocol realm:(NSString *)realm 2293 + (void)removeCredentialsForHost:(NSString *)host port:(int)port protocol:(NSString *)protocol realm:(NSString *)realm
2294 { 2294 {
2295 NSURLProtectionSpace *protectionSpace = [[[NSURLProtectionSpace alloc] initWithHost:host port:port protocol:protocol realm:realm authenticationMethod:NSURLAuthenticationMethodDefault] autorelease]; 2295 NSURLProtectionSpace *protectionSpace = [[[NSURLProtectionSpace alloc] initWithHost:host port:port protocol:protocol realm:realm authenticationMethod:NSURLAuthenticationMethodDefault] autorelease];
2296 - NSURLCredentialStorage *storage = [NSURLCredentialStorage sharedCredentialStorage]; 2296 + NSURLCredential *credential = [[NSURLCredentialStorage sharedCredentialStorage] defaultCredentialForProtectionSpace:protectionSpace];
2297 - [storage removeCredential:[storage defaultCredentialForProtectionSpace:protectionSpace] forProtectionSpace:protectionSpace]; 2297 + if (credential) {
  2298 + [[NSURLCredentialStorage sharedCredentialStorage] removeCredential:credential forProtectionSpace:protectionSpace];
  2299 + }
2298 } 2300 }
2299 2301
2300 + (void)removeCredentialsForProxy:(NSString *)host port:(int)port realm:(NSString *)realm 2302 + (void)removeCredentialsForProxy:(NSString *)host port:(int)port realm:(NSString *)realm
2301 { 2303 {
2302 NSURLProtectionSpace *protectionSpace = [[[NSURLProtectionSpace alloc] initWithProxyHost:host port:port type:NSURLProtectionSpaceHTTPProxy realm:realm authenticationMethod:NSURLAuthenticationMethodDefault] autorelease]; 2304 NSURLProtectionSpace *protectionSpace = [[[NSURLProtectionSpace alloc] initWithProxyHost:host port:port type:NSURLProtectionSpaceHTTPProxy realm:realm authenticationMethod:NSURLAuthenticationMethodDefault] autorelease];
2303 - NSURLCredentialStorage *storage = [NSURLCredentialStorage sharedCredentialStorage]; 2305 + NSURLCredential *credential = [[NSURLCredentialStorage sharedCredentialStorage] defaultCredentialForProtectionSpace:protectionSpace];
2304 - [storage removeCredential:[storage defaultCredentialForProtectionSpace:protectionSpace] forProtectionSpace:protectionSpace]; 2306 + if (credential) {
  2307 + [[NSURLCredentialStorage sharedCredentialStorage] removeCredential:credential forProtectionSpace:protectionSpace];
  2308 + }
2305 } 2309 }
2306 2310
2307 2311
@@ -23,6 +23,7 @@ @@ -23,6 +23,7 @@
23 - (void)testDownloadProgress; 23 - (void)testDownloadProgress;
24 - (void)testUploadProgress; 24 - (void)testUploadProgress;
25 - (void)testCookies; 25 - (void)testCookies;
  26 +- (void)testRemoveCredentialsFromKeychain;
26 - (void)testBasicAuthentication; 27 - (void)testBasicAuthentication;
27 - (void)testDigestAuthentication; 28 - (void)testDigestAuthentication;
28 - (void)testNTLMHandshake; 29 - (void)testNTLMHandshake;
@@ -40,4 +41,5 @@ @@ -40,4 +41,5 @@
40 - (void)testThrottlingDownloadBandwidth; 41 - (void)testThrottlingDownloadBandwidth;
41 - (void)testThrottlingUploadBandwidth; 42 - (void)testThrottlingUploadBandwidth;
42 - (void)testMainThreadDelegateAuthenticationFailure; 43 - (void)testMainThreadDelegateAuthenticationFailure;
  44 +
43 @end 45 @end
@@ -461,6 +461,14 @@ @@ -461,6 +461,14 @@
461 GHAssertTrue(success,@"Cookie presented to the server when it should have been removed"); 461 GHAssertTrue(success,@"Cookie presented to the server when it should have been removed");
462 } 462 }
463 463
  464 +// Test fix for a crash if you tried to remove credentials that didn't exist
  465 +- (void)testRemoveCredentialsFromKeychain
  466 +{
  467 + [ASIHTTPRequest removeCredentialsForHost:@"apple.com" port:0 protocol:@"http" realm:@"Nothing to see here"];
  468 + [ASIHTTPRequest removeCredentialsForProxy:@"apple.com" port:0 realm:@"Nothing to see here"];
  469 +
  470 +}
  471 +
464 472
465 - (void)testBasicAuthentication 473 - (void)testBasicAuthentication
466 { 474 {