Ben Copsey

Added tests for proxies

@@ -546,8 +546,8 @@ static NSError *ASITooMuchRedirectionError; @@ -546,8 +546,8 @@ static NSError *ASITooMuchRedirectionError;
546 NSDictionary *settings = [proxies objectAtIndex:0]; 546 NSDictionary *settings = [proxies objectAtIndex:0];
547 [self setProxyHost:[settings objectForKey:(NSString *)kCFProxyHostNameKey]]; 547 [self setProxyHost:[settings objectForKey:(NSString *)kCFProxyHostNameKey]];
548 [self setProxyPort:[[settings objectForKey:(NSString *)kCFProxyPortNumberKey] intValue]]; 548 [self setProxyPort:[[settings objectForKey:(NSString *)kCFProxyPortNumberKey] intValue]];
549 - NSLog(@"%@",proxySettings); 549 + //NSLog(@"%@",proxySettings);
550 - NSLog(@"%@",[proxies objectAtIndex:0]); 550 + //NSLog(@"%@",[proxies objectAtIndex:0]);
551 } 551 }
552 } 552 }
553 if ([self proxyHost] && [self proxyPort]) { 553 if ([self proxyHost] && [self proxyPort]) {
@@ -228,6 +228,10 @@ static NSString *bucket = @""; @@ -228,6 +228,10 @@ static NSString *bucket = @"";
228 // The file should still be accessible by any HTTP client that supports gzipped responses (eg browsers, NSURLConnection, etc) 228 // The file should still be accessible by any HTTP client that supports gzipped responses (eg browsers, NSURLConnection, etc)
229 - (void)testGZippedContent 229 - (void)testGZippedContent
230 { 230 {
  231 +
  232 + BOOL success = (![secretAccessKey isEqualToString:@""] && ![accessKey isEqualToString:@""] && ![bucket isEqualToString:@""]);
  233 + GHAssertTrue(success,@"You need to supply your S3 access details to run the gzipped put test (see the top of ASIS3RequestTests.m)");
  234 +
231 // Create the file 235 // Create the file
232 NSString *text = @"This is my content This is my content This is my content This is my content This is my content This is my content"; 236 NSString *text = @"This is my content This is my content This is my content This is my content This is my content This is my content";
233 NSString *filePath = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:@"testfile.txt"]; 237 NSString *filePath = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:@"testfile.txt"];
@@ -240,7 +244,7 @@ static NSString *bucket = @""; @@ -240,7 +244,7 @@ static NSString *bucket = @"";
240 [request setShouldCompressRequestBody:YES]; 244 [request setShouldCompressRequestBody:YES];
241 [request setAccessPolicy:ASIS3AccessPolicyPublicRead]; // We'll make it public 245 [request setAccessPolicy:ASIS3AccessPolicyPublicRead]; // We'll make it public
242 [request start]; 246 [request start];
243 - BOOL success = [[request responseString] isEqualToString:@""]; 247 + success = [[request responseString] isEqualToString:@""];
244 GHAssertTrue(success,@"Failed to PUT the gzipped file"); 248 GHAssertTrue(success,@"Failed to PUT the gzipped file");
245 249
246 // GET the file 250 // GET the file
  1 +//
  2 +// ProxyTests.h
  3 +// Mac
  4 +//
  5 +// Created by Ben Copsey on 02/08/2009.
  6 +// Copyright 2009 All-Seeing Interactive. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +#import "ASITestCase.h"
  11 +@class ASINetworkQueue;
  12 +
  13 +// Proxy tests must be run separately from other tests, using the proxy you specify
  14 +// Some tests require an authenticating proxy to function
  15 +
  16 +@interface ProxyTests : ASITestCase {
  17 + ASINetworkQueue *queue;
  18 + BOOL complete;
  19 +}
  20 +- (void)testProxy;
  21 +- (void)testProxyAutodetect;
  22 +- (void)testProxyWithSuppliedAuthenticationCredentials;
  23 +
  24 +@property (retain) ASINetworkQueue *queue;
  25 +@property (assign) BOOL complete;
  26 +
  27 +@end
  1 +//
  2 +// ProxyTests.m
  3 +// Mac
  4 +//
  5 +// Created by Ben Copsey on 02/08/2009.
  6 +// Copyright 2009 All-Seeing Interactive. All rights reserved.
  7 +//
  8 +
  9 +#import "ProxyTests.h"
  10 +#import "ASIHTTPRequest.h"
  11 +#import "ASINetworkQueue.h"
  12 +
  13 +// Fill in these to run the proxy tests
  14 +static NSString *proxyHost = @"";
  15 +static int proxyPort = 0;
  16 +static NSString *proxyUsername = @"";
  17 +static NSString *proxyPassword = @"";
  18 +
  19 +@implementation ProxyTests
  20 +
  21 +- (void)testProxy
  22 +{
  23 + BOOL success = (![proxyHost isEqualToString:@""] && proxyPort > 0);
  24 + GHAssertTrue(success,@"You need to supply the details of your proxy to run the proxy autodetect test");
  25 +
  26 + ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com"]];
  27 + [request setProxyHost:proxyHost];
  28 + [request setProxyPort:proxyPort];
  29 + [request start];
  30 +
  31 + // Check data is as expected
  32 + NSRange notFound = NSMakeRange(NSNotFound, 0);
  33 + success = !NSEqualRanges([[request responseString] rangeOfString:@"All-Seeing Interactive"],notFound);
  34 + GHAssertTrue(success,@"Failed to download the correct data, navigating the proxy");
  35 +}
  36 +
  37 +- (void)testProxyAutodetect
  38 +{
  39 + BOOL success = (![proxyHost isEqualToString:@""] && proxyPort > 0);
  40 + GHAssertTrue(success,@"You need to supply the details of your proxy to run the proxy autodetect test");
  41 +
  42 + ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com"]];
  43 + [request start];
  44 +
  45 + success = ([request proxyHost] && [request proxyPort]);
  46 + GHAssertTrue(success,@"Failed to detect the proxy");
  47 +}
  48 +
  49 +
  50 +- (void)testProxyWithSuppliedAuthenticationCredentials
  51 +{
  52 + BOOL success = (![proxyHost isEqualToString:@""] && proxyPort > 0 && ![proxyUsername isEqualToString:@""] && ![proxyPassword isEqualToString:@""]);
  53 + GHAssertTrue(success,@"You need to supply the details of your authenticating proxy to run the proxy authentication test");
  54 +
  55 + ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com"]];
  56 + [request setProxyHost:proxyHost];
  57 + [request setProxyPort:proxyPort];
  58 + [request setProxyUsername:proxyUsername];
  59 + [request setProxyPassword:proxyPassword];
  60 + [request start];
  61 +
  62 + // Check data is as expected
  63 + NSRange notFound = NSMakeRange(NSNotFound, 0);
  64 + success = !NSEqualRanges([[request responseString] rangeOfString:@"All-Seeing Interactive"],notFound);
  65 + GHAssertTrue(success,@"Failed to download the correct data, navigating the proxy");
  66 +}
  67 +
  68 +- (void)testProxyWithDelegateSupplyingCredentials
  69 +{
  70 + [self setComplete:NO];
  71 + BOOL success = (![proxyHost isEqualToString:@""] && proxyPort > 0 && ![proxyUsername isEqualToString:@""] && ![proxyPassword isEqualToString:@""]);
  72 + GHAssertTrue(success,@"You need to supply the details of your authenticating proxy to run the proxy authentication test");
  73 +
  74 + [[self queue] cancelAllOperations];
  75 + [self setQueue:[ASINetworkQueue queue]];
  76 + [[self queue] setDelegate:self];
  77 + [[self queue] setRequestDidFinishSelector:@selector(requestFinished:)];
  78 + [[self queue] setRequestDidFailSelector:@selector(requestFailed:)];
  79 +
  80 + ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com"]];
  81 + [[self queue] addOperation:request];
  82 +
  83 + [queue go];
  84 +
  85 + while (![self complete]) {
  86 + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
  87 + }
  88 +}
  89 +
  90 +- (void)requestFinished:(ASIHTTPRequest *)request
  91 +{
  92 + [self setComplete:YES];
  93 + // Check data is as expected
  94 + NSRange notFound = NSMakeRange(NSNotFound, 0);
  95 + BOOL success = !NSEqualRanges([[request responseString] rangeOfString:@"All-Seeing Interactive"],notFound);
  96 + GHAssertTrue(success,@"Failed to download the correct data, navigating the proxy");
  97 +}
  98 +
  99 +- (void)requestFailed:(ASIHTTPRequest *)request
  100 +{
  101 + [self setComplete:YES];
  102 + GHAssertTrue(0,@"Request failed when it shouldn't have done so");
  103 +}
  104 +
  105 +- (void)proxyAuthorizationNeededForRequest:(ASIHTTPRequest *)request
  106 +{
  107 + [request setProxyUsername:proxyUsername];
  108 + [request setProxyPassword:proxyPassword];
  109 + [request retryWithAuthentication];
  110 +}
  111 +
  112 +
  113 +- (void)testDoubleAuthentication
  114 +{
  115 + [self setComplete:NO];
  116 + BOOL success = (![proxyHost isEqualToString:@""] && proxyPort > 0 && ![proxyUsername isEqualToString:@""] && ![proxyPassword isEqualToString:@""]);
  117 + GHAssertTrue(success,@"You need to supply the details of your authenticating proxy to run the proxy authentication test");
  118 +
  119 + [[self queue] cancelAllOperations];
  120 + [self setQueue:[ASINetworkQueue queue]];
  121 + [[self queue] setDelegate:self];
  122 + [[self queue] setRequestDidFinishSelector:@selector(requestDone:)];
  123 + [[self queue] setRequestDidFailSelector:@selector(requestFailed:)];
  124 +
  125 + ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/basic-authentication"]];
  126 + [[self queue] addOperation:request];
  127 +
  128 + [queue go];
  129 +
  130 + while (![self complete]) {
  131 + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
  132 + }
  133 +}
  134 +
  135 +- (void)requestDone:(ASIHTTPRequest *)request
  136 +{
  137 + [self setComplete:YES];
  138 +}
  139 +
  140 +- (void)authorizationNeededForRequest:(ASIHTTPRequest *)request
  141 +{
  142 + [request setUsername:@"secret_username"];
  143 + [request setPassword:@"secret_password"];
  144 + [request retryWithAuthentication];
  145 +}
  146 +
  147 +
  148 +@synthesize queue;
  149 +@synthesize complete;
  150 +@end
This diff was suppressed by a .gitattributes entry.
@@ -69,7 +69,6 @@ @@ -69,7 +69,6 @@
69 69
70 70
71 71
72 -  
73 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 72 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
74 { 73 {
75 if (buttonIndex == 1) { 74 if (buttonIndex == 1) {