Permalink
Browse files

Added tests for Basic and Digest authentication

  • Loading branch information...
1 parent 4ae9142 commit cfb68f81d27369d2c94a7a84a95d85a8da45af88 @pokeb pokeb committed Nov 10, 2008
Showing with 127 additions and 10 deletions.
  1. +2 −0 ASIFormDataRequestTests.m
  2. +2 −0 ASIHTTPRequestTests.h
  3. +119 −8 ASIHTTPRequestTests.m
  4. +4 −2 asi-http-request.xcodeproj/project.pbxproj
@@ -32,5 +32,7 @@ - (void)testPostWithFileUpload
BOOL success = ([[request dataString] isEqualToString:[NSString stringWithFormat:@"post_var: %@\r\nfile_name: %@\r\nfile_size: %hu",@"foo",@"bigfile",size]]);
STAssertTrue(success,@"Failed to upload the correct data");
}
+
+
@end
View
@@ -21,5 +21,7 @@
- (void)testDownloadProgress;
- (void)testUploadProgress;
- (void)testCookies;
+- (void)testBasicAuthentication;
+- (void)testDigestAuthentication;
@end
View
@@ -14,14 +14,6 @@
@implementation ASIHTTPRequestTests
-/*
-More tests needed for:
- - Delegates - success and failure
- - Authentication
- - Keychains
- - Session persistence
-*/
-
- (void)testBasicDownload
@@ -245,5 +237,124 @@ - (void)testCookies
}
+- (void)testBasicAuthentication
+{
+
+ NSURL *url = [[[NSURL alloc] initWithString:@"http://asi/asi-http-request/tests/basic-authentication"] autorelease];
+ ASIHTTPRequest *request;
+ BOOL success;
+ NSError *err;
+
+ request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
+ [request setUseKeychainPersistance:NO];
+ [request start];
+ success = ([[[[request error] userInfo] objectForKey:@"Description"] isEqualToString:@"Your username and password were incorrect."]);
+ STAssertTrue(success,@"Failed to generate permission denied error with no credentials");
+
+ request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
+ [request setUseKeychainPersistance:NO];
+ [request setUsername:@"wrong"];
+ [request setPassword:@"wrong"];
+ [request start];
+ success = ([[[[request error] userInfo] objectForKey:@"Description"] isEqualToString:@"Your username and password were incorrect."]);
+ STAssertTrue(success,@"Failed to generate permission denied error with wrong credentials");
+
+ request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
+ [request setUseSessionPersistance:YES];
+ [request setUseKeychainPersistance:YES];
+ [request setUsername:@"secret_username"];
+ [request setPassword:@"secret_password"];
+ [request start];
+ err = [request error];
+ STAssertNil(err,@"Failed to supply correct username and password");
+
+ request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
+ [request setUseSessionPersistance:NO];
+ [request setUseKeychainPersistance:NO];
+ [request start];
+ success = ([[[[request error] userInfo] objectForKey:@"Description"] isEqualToString:@"Your username and password were incorrect."]);
+ STAssertTrue(success,@"Reused credentials when we shouldn't have");
+
+ request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
+ [request setUseSessionPersistance:YES];
+ [request setUseKeychainPersistance:NO];
+ [request start];
+ err = [request error];
+ STAssertNil(err,@"Failed to reuse credentials");
+
+ [ASIHTTPRequest clearSession];
+
+ request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
+ [request setUseKeychainPersistance:NO];
+ [request start];
+ success = ([[[[request error] userInfo] objectForKey:@"Description"] isEqualToString:@"Your username and password were incorrect."]);
+ STAssertTrue(success,@"Failed to clear credentials");
+
+ //This test may show a dialog!
+ request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
+ [request setUseKeychainPersistance:YES];
+ [request start];
+ err = [request error];
+ STAssertNil(err,@"Failed to use stored credentials");
+}
+
+
+
+- (void)testDigestAuthentication
+{
+ [ASIHTTPRequest clearSession];
+
+ NSURL *url = [[[NSURL alloc] initWithString:@"http://asi/asi-http-request/tests/digest-authentication"] autorelease];
+ ASIHTTPRequest *request;
+ BOOL success;
+ NSError *err;
+
+ request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
+ [request setUseKeychainPersistance:NO];
+ [request start];
+ success = ([[[[request error] userInfo] objectForKey:@"Description"] isEqualToString:@"Your username and password were incorrect."]);
+ STAssertTrue(success,@"Failed to generate permission denied error with no credentials");
+
+ request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
+ [request setUseKeychainPersistance:NO];
+ [request setUsername:@"wrong"];
+ [request setPassword:@"wrong"];
+ [request start];
+ success = ([[[[request error] userInfo] objectForKey:@"Description"] isEqualToString:@"Your username and password were incorrect."]);
+ STAssertTrue(success,@"Failed to generate permission denied error with wrong credentials");
+
+ request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
+ [request setUseSessionPersistance:YES];
+ [request setUseKeychainPersistance:YES];
+ [request setUsername:@"secret_username"];
+ [request setPassword:@"secret_password"];
+ [request start];
+ err = [request error];
+ STAssertNil(err,@"Failed to supply correct username and password");
+
+ request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
+ [request setUseSessionPersistance:NO];
+ [request setUseKeychainPersistance:NO];
+ [request start];
+ success = ([[[[request error] userInfo] objectForKey:@"Description"] isEqualToString:@"Your username and password were incorrect."]);
+ STAssertTrue(success,@"Reused credentials when we shouldn't have");
+
+ request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
+ [request setUseSessionPersistance:YES];
+ [request setUseKeychainPersistance:NO];
+ [request start];
+ err = [request error];
+ STAssertNil(err,@"Failed to reuse credentials");
+
+ [ASIHTTPRequest clearSession];
+
+ request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
+ [request setUseKeychainPersistance:NO];
+ [request start];
+ success = ([[[[request error] userInfo] objectForKey:@"Description"] isEqualToString:@"Your username and password were incorrect."]);
+ STAssertTrue(success,@"Failed to clear credentials");
+
+}
+
@end
@@ -444,6 +444,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/asi-http-request.app/Contents/MacOS/asi-http-request";
COPY_PHASE_STRIP = NO;
FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks";
GCC_DYNAMIC_NO_PIC = NO;
@@ -463,7 +464,7 @@
);
PREBINDING = NO;
PRODUCT_NAME = Tests;
- TEST_HOST = "";
+ TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = octest;
};
name = Debug;
@@ -472,6 +473,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/asi-http-request.app/Contents/MacOS/asi-http-request";
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks";
@@ -490,7 +492,7 @@
);
PREBINDING = NO;
PRODUCT_NAME = Tests;
- TEST_HOST = "";
+ TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = octest;
ZERO_LINK = NO;
};

0 comments on commit cfb68f8

Please sign in to comment.