Added new test for NTLM to ensure the delegate gets multiple chances to supply c…
…redentials (this was working, but I wasn't sure) Fiddle with progress tests again in an effort more reliable (Argh, performSelectorOnMainThread:withObject:waitUntilDone:NO])
Showing
3 changed files
with
66 additions
and
7 deletions
@@ -585,7 +585,7 @@ | @@ -585,7 +585,7 @@ | ||
585 | 585 | ||
586 | [ASIHTTPRequest clearSession]; | 586 | [ASIHTTPRequest clearSession]; |
587 | 587 | ||
588 | - NSURL *url = [NSURL URLWithString:@"http://asi/ASIHTTPRequest/tests/pretend-ntlm-handshake"]; | 588 | + NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/pretend-ntlm-handshake"]; |
589 | 589 | ||
590 | ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; | 590 | ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; |
591 | [request setUseKeychainPersistance:NO]; | 591 | [request setUseKeychainPersistance:NO]; |
@@ -766,7 +766,6 @@ | @@ -766,7 +766,6 @@ | ||
766 | [request appendPostData:data]; | 766 | [request appendPostData:data]; |
767 | [request start]; | 767 | [request start]; |
768 | 768 | ||
769 | - NSLog(@"%@",[request responseData]); | ||
770 | success = [[request responseString] isEqualToString:content]; | 769 | success = [[request responseString] isEqualToString:content]; |
771 | GHAssertTrue(success,@"Failed to compress the body, or server failed to decompress it"); | 770 | GHAssertTrue(success,@"Failed to compress the body, or server failed to decompress it"); |
772 | 771 |
@@ -36,6 +36,8 @@ IMPORTANT | @@ -36,6 +36,8 @@ IMPORTANT | ||
36 | int authenticationPromptCount; | 36 | int authenticationPromptCount; |
37 | 37 | ||
38 | ASINetworkQueue *postQueue; | 38 | ASINetworkQueue *postQueue; |
39 | + | ||
40 | + ASINetworkQueue *testNTLMQueue; | ||
39 | } | 41 | } |
40 | 42 | ||
41 | - (void)testFailure; | 43 | - (void)testFailure; |
@@ -68,5 +70,6 @@ IMPORTANT | @@ -68,5 +70,6 @@ IMPORTANT | ||
68 | @property (retain) ASINetworkQueue *releaseTestQueue; | 70 | @property (retain) ASINetworkQueue *releaseTestQueue; |
69 | @property (retain) ASINetworkQueue *cancelQueue; | 71 | @property (retain) ASINetworkQueue *cancelQueue; |
70 | @property (retain) ASINetworkQueue *postQueue; | 72 | @property (retain) ASINetworkQueue *postQueue; |
73 | +@property (retain) ASINetworkQueue *testNTLMQueue; | ||
71 | 74 | ||
72 | @end | 75 | @end |
@@ -10,6 +10,7 @@ | @@ -10,6 +10,7 @@ | ||
10 | #import "ASIHTTPRequest.h" | 10 | #import "ASIHTTPRequest.h" |
11 | #import "ASINetworkQueue.h" | 11 | #import "ASINetworkQueue.h" |
12 | #import "ASIFormDataRequest.h" | 12 | #import "ASIFormDataRequest.h" |
13 | +#import <SystemConfiguration/SystemConfiguration.h> | ||
13 | 14 | ||
14 | /* | 15 | /* |
15 | IMPORTANT | 16 | IMPORTANT |
@@ -82,7 +83,8 @@ IMPORTANT | @@ -82,7 +83,8 @@ IMPORTANT | ||
82 | while (!complete) { | 83 | while (!complete) { |
83 | [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]]; | 84 | [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]]; |
84 | } | 85 | } |
85 | - [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]]; | 86 | + |
87 | + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; | ||
86 | BOOL success = (progress > 0.95); | 88 | BOOL success = (progress > 0.95); |
87 | GHAssertTrue(success,@"Failed to increment progress properly"); | 89 | GHAssertTrue(success,@"Failed to increment progress properly"); |
88 | 90 | ||
@@ -114,6 +116,11 @@ IMPORTANT | @@ -114,6 +116,11 @@ IMPORTANT | ||
114 | 116 | ||
115 | } | 117 | } |
116 | 118 | ||
119 | +- (void)uploadFailed:(ASIHTTPRequest *)request | ||
120 | +{ | ||
121 | + GHFail(@"Failed to upload some data, cannot continue with this test"); | ||
122 | +} | ||
123 | + | ||
117 | - (void)testUploadProgress | 124 | - (void)testUploadProgress |
118 | { | 125 | { |
119 | complete = NO; | 126 | complete = NO; |
@@ -123,6 +130,7 @@ IMPORTANT | @@ -123,6 +130,7 @@ IMPORTANT | ||
123 | [networkQueue setUploadProgressDelegate:self]; | 130 | [networkQueue setUploadProgressDelegate:self]; |
124 | [networkQueue setDelegate:self]; | 131 | [networkQueue setDelegate:self]; |
125 | [networkQueue setShowAccurateProgress:NO]; | 132 | [networkQueue setShowAccurateProgress:NO]; |
133 | + [networkQueue setRequestDidFailSelector:@selector(uploadFailed:)]; | ||
126 | [networkQueue setQueueDidFinishSelector:@selector(queueFinished:)]; | 134 | [networkQueue setQueueDidFinishSelector:@selector(queueFinished:)]; |
127 | 135 | ||
128 | NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com/ignore"]; | 136 | NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com/ignore"]; |
@@ -143,7 +151,7 @@ IMPORTANT | @@ -143,7 +151,7 @@ IMPORTANT | ||
143 | while (!complete) { | 151 | while (!complete) { |
144 | [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]]; | 152 | [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]]; |
145 | } | 153 | } |
146 | - [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]]; | 154 | + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; |
147 | BOOL success = (progress > 0.95); | 155 | BOOL success = (progress > 0.95); |
148 | GHAssertTrue(success,@"Failed to increment progress properly"); | 156 | GHAssertTrue(success,@"Failed to increment progress properly"); |
149 | 157 | ||
@@ -167,7 +175,7 @@ IMPORTANT | @@ -167,7 +175,7 @@ IMPORTANT | ||
167 | while (!complete) { | 175 | while (!complete) { |
168 | [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]]; | 176 | [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]]; |
169 | } | 177 | } |
170 | - [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]]; | 178 | + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; |
171 | success = (progress > 0.95); | 179 | success = (progress > 0.95); |
172 | GHAssertTrue(success,@"Failed to increment progress properly"); | 180 | GHAssertTrue(success,@"Failed to increment progress properly"); |
173 | 181 | ||
@@ -389,7 +397,17 @@ IMPORTANT | @@ -389,7 +397,17 @@ IMPORTANT | ||
389 | - (void)authenticationNeededForRequest:(ASIHTTPRequest *)request | 397 | - (void)authenticationNeededForRequest:(ASIHTTPRequest *)request |
390 | { | 398 | { |
391 | // We're using this method in multiple tests, so the code here is to act appropriatly for each one | 399 | // We're using this method in multiple tests, so the code here is to act appropriatly for each one |
392 | - if ([[[request userInfo] objectForKey:@"test"] isEqualToString:@"reuse"]) { | 400 | + |
401 | + if ([[[request userInfo] objectForKey:@"test"] isEqualToString:@"ntlm"]) { | ||
402 | + authenticationPromptCount++; | ||
403 | + if (authenticationPromptCount == 5) { | ||
404 | + [request setUsername:@"king"]; | ||
405 | + [request setPassword:@"crown"]; | ||
406 | + [request setDomain:@"CASTLE.KINGDOM"]; | ||
407 | + } | ||
408 | + [request retryUsingSuppliedCredentials]; | ||
409 | + | ||
410 | + } else if ([[[request userInfo] objectForKey:@"test"] isEqualToString:@"reuse"]) { | ||
393 | authenticationPromptCount++; | 411 | authenticationPromptCount++; |
394 | BOOL success = (authenticationPromptCount == 1); | 412 | BOOL success = (authenticationPromptCount == 1); |
395 | GHAssertTrue(success,@"Delegate was asked for credentials more than once"); | 413 | GHAssertTrue(success,@"Delegate was asked for credentials more than once"); |
@@ -458,7 +476,7 @@ IMPORTANT | @@ -458,7 +476,7 @@ IMPORTANT | ||
458 | [networkQueue waitUntilAllOperationsAreFinished]; | 476 | [networkQueue waitUntilAllOperationsAreFinished]; |
459 | 477 | ||
460 | // Give the queue time to notify us | 478 | // Give the queue time to notify us |
461 | - [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]]; | 479 | + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; |
462 | 480 | ||
463 | // This test may fail if you are using a proxy and it returns a page when you try to connect to a bad port. | 481 | // This test may fail if you are using a proxy and it returns a page when you try to connect to a bad port. |
464 | GHAssertTrue(!request_succeeded && request_didfail,@"Request to resource without listener succeeded but should have failed"); | 482 | GHAssertTrue(!request_succeeded && request_didfail,@"Request to resource without listener succeeded but should have failed"); |
@@ -878,10 +896,49 @@ IMPORTANT | @@ -878,10 +896,49 @@ IMPORTANT | ||
878 | [[self postQueue] go]; | 896 | [[self postQueue] go]; |
879 | } | 897 | } |
880 | 898 | ||
899 | +- (void)testNTLMMultipleFailure | ||
900 | +{ | ||
901 | + authenticationPromptCount = 0; | ||
902 | + [ASIHTTPRequest clearSession]; | ||
903 | + [[self testNTLMQueue] cancelAllOperations]; | ||
904 | + [self setTestNTLMQueue:[ASINetworkQueue queue]]; | ||
905 | + | ||
906 | + ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/pretend-ntlm-handshake"]]; | ||
907 | + [request setUseKeychainPersistance:NO]; | ||
908 | + [request setUseSessionPersistance:NO]; | ||
909 | + [request setUserInfo:[NSDictionary dictionaryWithObject:@"ntlm" forKey:@"test"]]; | ||
910 | + | ||
911 | + [[self testNTLMQueue] setRequestDidFinishSelector:@selector(ntlmDone:)]; | ||
912 | + [[self testNTLMQueue] setRequestDidFailSelector:@selector(ntlmFailed:)]; | ||
913 | + [[self testNTLMQueue] setDelegate:self]; | ||
914 | + [[self testNTLMQueue] addOperation:request]; | ||
915 | + [[self testNTLMQueue] go]; | ||
916 | +} | ||
917 | + | ||
918 | +- (void)ntlmFailed:(ASIHTTPRequest *)request | ||
919 | +{ | ||
920 | + GHFail(@"Failed to provide NTLM credentials (error was :%@)",[request error]); | ||
921 | +} | ||
922 | + | ||
923 | +- (void)ntlmDone:(ASIHTTPRequest *)request | ||
924 | +{ | ||
925 | + GHAssertNil([request error],@"Got an error when credentials were supplied"); | ||
926 | + | ||
927 | + // Ok, so I assume that not everyone will have a hostname in the form 'Ben-Copseys-MacBook-Pro.local', but anyway... | ||
928 | + NSString *hostName = [NSString stringWithFormat:@"%@.local",[(NSString *)SCDynamicStoreCopyLocalHostName(NULL) autorelease]]; | ||
929 | + | ||
930 | + NSString *expectedResponse = [NSString stringWithFormat:@"You are %@ from %@/%@",@"king",[@"Castle.Kingdom" uppercaseString],hostName]; | ||
931 | + BOOL success = [[request responseString] isEqualToString:expectedResponse]; | ||
932 | + GHAssertTrue(success,@"Failed to send credentials correctly? (Expected: '%@', got '%@')",expectedResponse,[request responseString]); | ||
933 | + | ||
934 | +} | ||
935 | + | ||
881 | @synthesize immediateCancelQueue; | 936 | @synthesize immediateCancelQueue; |
882 | @synthesize failedRequests; | 937 | @synthesize failedRequests; |
883 | @synthesize finishedRequests; | 938 | @synthesize finishedRequests; |
884 | @synthesize releaseTestQueue; | 939 | @synthesize releaseTestQueue; |
885 | @synthesize cancelQueue; | 940 | @synthesize cancelQueue; |
886 | @synthesize postQueue; | 941 | @synthesize postQueue; |
942 | +@synthesize testNTLMQueue; | ||
943 | + | ||
887 | @end | 944 | @end |
-
Please register or login to post a comment