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!
Showing
3 changed files
with
27 additions
and
2 deletions
@@ -23,7 +23,7 @@ | @@ -23,7 +23,7 @@ | ||
23 | 23 | ||
24 | 24 | ||
25 | // Automatically set on build | 25 | // Automatically set on build |
26 | -NSString *ASIHTTPRequestVersion = @"v1.6.2-11 2010-05-26"; | 26 | +NSString *ASIHTTPRequestVersion = @"v1.6.2-12 2010-05-26"; |
27 | 27 | ||
28 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; | 28 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; |
29 | 29 | ||
@@ -2901,7 +2901,7 @@ static BOOL isiPhoneOS2; | @@ -2901,7 +2901,7 @@ static BOOL isiPhoneOS2; | ||
2901 | NSURL *theURL = [theCredentials objectForKey:@"URL"]; | 2901 | NSURL *theURL = [theCredentials objectForKey:@"URL"]; |
2902 | 2902 | ||
2903 | // Port can be nil! | 2903 | // Port can be nil! |
2904 | - if ([[theURL host] isEqualToString:[requestURL host]] && ([theURL port] == [requestURL port] || [[theURL port] isEqualToNumber:[requestURL port]]) && [[theURL scheme] isEqualToString:[requestURL scheme]]) { | 2904 | + if ([[theURL host] isEqualToString:[requestURL host]] && ([theURL port] == [requestURL port] || ([requestURL port] && [[theURL port] isEqualToNumber:[requestURL port]])) && [[theURL scheme] isEqualToString:[requestURL scheme]]) { |
2905 | if (![self responseStatusCode] || (![theCredentials objectForKey:@"AuthenticationRealm"] || [[theCredentials objectForKey:@"AuthenticationRealm"] isEqualToString:[self authenticationRealm]])) { | 2905 | if (![self responseStatusCode] || (![theCredentials objectForKey:@"AuthenticationRealm"] || [[theCredentials objectForKey:@"AuthenticationRealm"] isEqualToString:[self authenticationRealm]])) { |
2906 | [sessionCredentialsLock unlock]; | 2906 | [sessionCredentialsLock unlock]; |
2907 | return theCredentials; | 2907 | return theCredentials; |
@@ -64,6 +64,7 @@ | @@ -64,6 +64,7 @@ | ||
64 | - (void)testAutomaticRetry; | 64 | - (void)testAutomaticRetry; |
65 | - (void)testCloseConnection; | 65 | - (void)testCloseConnection; |
66 | - (void)testPersistentConnectionTimeout; | 66 | - (void)testPersistentConnectionTimeout; |
67 | +- (void)testNilPortCredentialsMatching; | ||
67 | 68 | ||
68 | @property (retain, nonatomic) NSMutableData *responseData; | 69 | @property (retain, nonatomic) NSMutableData *responseData; |
69 | @end | 70 | @end |
@@ -1579,5 +1579,29 @@ | @@ -1579,5 +1579,29 @@ | ||
1579 | [[self responseData] appendData:data]; | 1579 | [[self responseData] appendData:data]; |
1580 | } | 1580 | } |
1581 | 1581 | ||
1582 | +- (void)testNilPortCredentialsMatching | ||
1583 | +{ | ||
1584 | + // Test for http://github.com/pokeb/asi-http-request/issues#issue/39 | ||
1585 | + [ASIHTTPRequest clearSession]; | ||
1586 | + ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com:80/ASIHTTPRequest/tests/basic-authentication"]]; | ||
1587 | + [request setUsername:@"secret_username"]; | ||
1588 | + [request setPassword:@"secret_password"]; | ||
1589 | + [request startSynchronous]; | ||
1590 | + | ||
1591 | + request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/basic-authentication"]]; | ||
1592 | + [request startSynchronous]; | ||
1593 | + | ||
1594 | + // Now let's test the other way around | ||
1595 | + [ASIHTTPRequest clearSession]; | ||
1596 | + | ||
1597 | + request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com:/ASIHTTPRequest/tests/basic-authentication"]]; | ||
1598 | + [request setUsername:@"secret_username"]; | ||
1599 | + [request setPassword:@"secret_password"]; | ||
1600 | + [request startSynchronous]; | ||
1601 | + | ||
1602 | + request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com:80/ASIHTTPRequest/tests/basic-authentication"]]; | ||
1603 | + [request startSynchronous]; | ||
1604 | +} | ||
1605 | + | ||
1582 | @synthesize responseData; | 1606 | @synthesize responseData; |
1583 | @end | 1607 | @end |
-
Please register or login to post a comment