Ben Copsey

Fix a problem that could occur in searching for credentials when mixing urls con…

…taining a port with ones that don't -  Closes gh-39
Many thanks to Luke Redpath for tracking this down!
... ... @@ -23,7 +23,7 @@
// Automatically set on build
NSString *ASIHTTPRequestVersion = @"v1.6.2-11 2010-05-26";
NSString *ASIHTTPRequestVersion = @"v1.6.2-12 2010-05-26";
NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain";
... ... @@ -2901,7 +2901,7 @@ static BOOL isiPhoneOS2;
NSURL *theURL = [theCredentials objectForKey:@"URL"];
// Port can be nil!
if ([[theURL host] isEqualToString:[requestURL host]] && ([theURL port] == [requestURL port] || [[theURL port] isEqualToNumber:[requestURL port]]) && [[theURL scheme] isEqualToString:[requestURL scheme]]) {
if ([[theURL host] isEqualToString:[requestURL host]] && ([theURL port] == [requestURL port] || ([requestURL port] && [[theURL port] isEqualToNumber:[requestURL port]])) && [[theURL scheme] isEqualToString:[requestURL scheme]]) {
if (![self responseStatusCode] || (![theCredentials objectForKey:@"AuthenticationRealm"] || [[theCredentials objectForKey:@"AuthenticationRealm"] isEqualToString:[self authenticationRealm]])) {
[sessionCredentialsLock unlock];
return theCredentials;
... ...
... ... @@ -64,6 +64,7 @@
- (void)testAutomaticRetry;
- (void)testCloseConnection;
- (void)testPersistentConnectionTimeout;
- (void)testNilPortCredentialsMatching;
@property (retain, nonatomic) NSMutableData *responseData;
@end
... ...
... ... @@ -1579,5 +1579,29 @@
[[self responseData] appendData:data];
}
- (void)testNilPortCredentialsMatching
{
// Test for http://github.com/pokeb/asi-http-request/issues#issue/39
[ASIHTTPRequest clearSession];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com:80/ASIHTTPRequest/tests/basic-authentication"]];
[request setUsername:@"secret_username"];
[request setPassword:@"secret_password"];
[request startSynchronous];
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/basic-authentication"]];
[request startSynchronous];
// Now let's test the other way around
[ASIHTTPRequest clearSession];
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com:/ASIHTTPRequest/tests/basic-authentication"]];
[request setUsername:@"secret_username"];
[request setPassword:@"secret_password"];
[request startSynchronous];
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com:80/ASIHTTPRequest/tests/basic-authentication"]];
[request startSynchronous];
}
@synthesize responseData;
@end
\ No newline at end of file
... ...