Showing
4 changed files
with
123 additions
and
8 deletions
| @@ -21,5 +21,7 @@ | @@ -21,5 +21,7 @@ | ||
| 21 | - (void)testDownloadProgress; | 21 | - (void)testDownloadProgress; |
| 22 | - (void)testUploadProgress; | 22 | - (void)testUploadProgress; |
| 23 | - (void)testCookies; | 23 | - (void)testCookies; |
| 24 | +- (void)testBasicAuthentication; | ||
| 25 | +- (void)testDigestAuthentication; | ||
| 24 | 26 | ||
| 25 | @end | 27 | @end |
| @@ -14,14 +14,6 @@ | @@ -14,14 +14,6 @@ | ||
| 14 | 14 | ||
| 15 | @implementation ASIHTTPRequestTests | 15 | @implementation ASIHTTPRequestTests |
| 16 | 16 | ||
| 17 | -/* | ||
| 18 | -More tests needed for: | ||
| 19 | - - Delegates - success and failure | ||
| 20 | - - Authentication | ||
| 21 | - - Keychains | ||
| 22 | - - Session persistence | ||
| 23 | -*/ | ||
| 24 | - | ||
| 25 | 17 | ||
| 26 | 18 | ||
| 27 | - (void)testBasicDownload | 19 | - (void)testBasicDownload |
| @@ -245,5 +237,124 @@ More tests needed for: | @@ -245,5 +237,124 @@ More tests needed for: | ||
| 245 | } | 237 | } |
| 246 | 238 | ||
| 247 | 239 | ||
| 240 | +- (void)testBasicAuthentication | ||
| 241 | +{ | ||
| 242 | + | ||
| 243 | + NSURL *url = [[[NSURL alloc] initWithString:@"http://asi/asi-http-request/tests/basic-authentication"] autorelease]; | ||
| 244 | + ASIHTTPRequest *request; | ||
| 245 | + BOOL success; | ||
| 246 | + NSError *err; | ||
| 247 | + | ||
| 248 | + request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | ||
| 249 | + [request setUseKeychainPersistance:NO]; | ||
| 250 | + [request start]; | ||
| 251 | + success = ([[[[request error] userInfo] objectForKey:@"Description"] isEqualToString:@"Your username and password were incorrect."]); | ||
| 252 | + STAssertTrue(success,@"Failed to generate permission denied error with no credentials"); | ||
| 253 | + | ||
| 254 | + request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | ||
| 255 | + [request setUseKeychainPersistance:NO]; | ||
| 256 | + [request setUsername:@"wrong"]; | ||
| 257 | + [request setPassword:@"wrong"]; | ||
| 258 | + [request start]; | ||
| 259 | + success = ([[[[request error] userInfo] objectForKey:@"Description"] isEqualToString:@"Your username and password were incorrect."]); | ||
| 260 | + STAssertTrue(success,@"Failed to generate permission denied error with wrong credentials"); | ||
| 261 | + | ||
| 262 | + request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | ||
| 263 | + [request setUseSessionPersistance:YES]; | ||
| 264 | + [request setUseKeychainPersistance:YES]; | ||
| 265 | + [request setUsername:@"secret_username"]; | ||
| 266 | + [request setPassword:@"secret_password"]; | ||
| 267 | + [request start]; | ||
| 268 | + err = [request error]; | ||
| 269 | + STAssertNil(err,@"Failed to supply correct username and password"); | ||
| 270 | + | ||
| 271 | + request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | ||
| 272 | + [request setUseSessionPersistance:NO]; | ||
| 273 | + [request setUseKeychainPersistance:NO]; | ||
| 274 | + [request start]; | ||
| 275 | + success = ([[[[request error] userInfo] objectForKey:@"Description"] isEqualToString:@"Your username and password were incorrect."]); | ||
| 276 | + STAssertTrue(success,@"Reused credentials when we shouldn't have"); | ||
| 277 | + | ||
| 278 | + request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | ||
| 279 | + [request setUseSessionPersistance:YES]; | ||
| 280 | + [request setUseKeychainPersistance:NO]; | ||
| 281 | + [request start]; | ||
| 282 | + err = [request error]; | ||
| 283 | + STAssertNil(err,@"Failed to reuse credentials"); | ||
| 284 | + | ||
| 285 | + [ASIHTTPRequest clearSession]; | ||
| 286 | + | ||
| 287 | + request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | ||
| 288 | + [request setUseKeychainPersistance:NO]; | ||
| 289 | + [request start]; | ||
| 290 | + success = ([[[[request error] userInfo] objectForKey:@"Description"] isEqualToString:@"Your username and password were incorrect."]); | ||
| 291 | + STAssertTrue(success,@"Failed to clear credentials"); | ||
| 292 | + | ||
| 293 | + //This test may show a dialog! | ||
| 294 | + request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | ||
| 295 | + [request setUseKeychainPersistance:YES]; | ||
| 296 | + [request start]; | ||
| 297 | + err = [request error]; | ||
| 298 | + STAssertNil(err,@"Failed to use stored credentials"); | ||
| 299 | +} | ||
| 300 | + | ||
| 301 | + | ||
| 302 | + | ||
| 303 | +- (void)testDigestAuthentication | ||
| 304 | +{ | ||
| 305 | + [ASIHTTPRequest clearSession]; | ||
| 306 | + | ||
| 307 | + NSURL *url = [[[NSURL alloc] initWithString:@"http://asi/asi-http-request/tests/digest-authentication"] autorelease]; | ||
| 308 | + ASIHTTPRequest *request; | ||
| 309 | + BOOL success; | ||
| 310 | + NSError *err; | ||
| 311 | + | ||
| 312 | + request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | ||
| 313 | + [request setUseKeychainPersistance:NO]; | ||
| 314 | + [request start]; | ||
| 315 | + success = ([[[[request error] userInfo] objectForKey:@"Description"] isEqualToString:@"Your username and password were incorrect."]); | ||
| 316 | + STAssertTrue(success,@"Failed to generate permission denied error with no credentials"); | ||
| 317 | + | ||
| 318 | + request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | ||
| 319 | + [request setUseKeychainPersistance:NO]; | ||
| 320 | + [request setUsername:@"wrong"]; | ||
| 321 | + [request setPassword:@"wrong"]; | ||
| 322 | + [request start]; | ||
| 323 | + success = ([[[[request error] userInfo] objectForKey:@"Description"] isEqualToString:@"Your username and password were incorrect."]); | ||
| 324 | + STAssertTrue(success,@"Failed to generate permission denied error with wrong credentials"); | ||
| 325 | + | ||
| 326 | + request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | ||
| 327 | + [request setUseSessionPersistance:YES]; | ||
| 328 | + [request setUseKeychainPersistance:YES]; | ||
| 329 | + [request setUsername:@"secret_username"]; | ||
| 330 | + [request setPassword:@"secret_password"]; | ||
| 331 | + [request start]; | ||
| 332 | + err = [request error]; | ||
| 333 | + STAssertNil(err,@"Failed to supply correct username and password"); | ||
| 334 | + | ||
| 335 | + request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | ||
| 336 | + [request setUseSessionPersistance:NO]; | ||
| 337 | + [request setUseKeychainPersistance:NO]; | ||
| 338 | + [request start]; | ||
| 339 | + success = ([[[[request error] userInfo] objectForKey:@"Description"] isEqualToString:@"Your username and password were incorrect."]); | ||
| 340 | + STAssertTrue(success,@"Reused credentials when we shouldn't have"); | ||
| 341 | + | ||
| 342 | + request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | ||
| 343 | + [request setUseSessionPersistance:YES]; | ||
| 344 | + [request setUseKeychainPersistance:NO]; | ||
| 345 | + [request start]; | ||
| 346 | + err = [request error]; | ||
| 347 | + STAssertNil(err,@"Failed to reuse credentials"); | ||
| 348 | + | ||
| 349 | + [ASIHTTPRequest clearSession]; | ||
| 350 | + | ||
| 351 | + request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | ||
| 352 | + [request setUseKeychainPersistance:NO]; | ||
| 353 | + [request start]; | ||
| 354 | + success = ([[[[request error] userInfo] objectForKey:@"Description"] isEqualToString:@"Your username and password were incorrect."]); | ||
| 355 | + STAssertTrue(success,@"Failed to clear credentials"); | ||
| 356 | + | ||
| 357 | +} | ||
| 358 | + | ||
| 248 | 359 | ||
| 249 | @end | 360 | @end |
This diff was suppressed by a .gitattributes entry.
-
Please register or login to post a comment