Ben Copsey

Added tests for proxies

... ... @@ -546,8 +546,8 @@ static NSError *ASITooMuchRedirectionError;
NSDictionary *settings = [proxies objectAtIndex:0];
[self setProxyHost:[settings objectForKey:(NSString *)kCFProxyHostNameKey]];
[self setProxyPort:[[settings objectForKey:(NSString *)kCFProxyPortNumberKey] intValue]];
NSLog(@"%@",proxySettings);
NSLog(@"%@",[proxies objectAtIndex:0]);
//NSLog(@"%@",proxySettings);
//NSLog(@"%@",[proxies objectAtIndex:0]);
}
}
if ([self proxyHost] && [self proxyPort]) {
... ...
... ... @@ -228,6 +228,10 @@ static NSString *bucket = @"";
// The file should still be accessible by any HTTP client that supports gzipped responses (eg browsers, NSURLConnection, etc)
- (void)testGZippedContent
{
BOOL success = (![secretAccessKey isEqualToString:@""] && ![accessKey isEqualToString:@""] && ![bucket isEqualToString:@""]);
GHAssertTrue(success,@"You need to supply your S3 access details to run the gzipped put test (see the top of ASIS3RequestTests.m)");
// Create the file
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";
NSString *filePath = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:@"testfile.txt"];
... ... @@ -240,7 +244,7 @@ static NSString *bucket = @"";
[request setShouldCompressRequestBody:YES];
[request setAccessPolicy:ASIS3AccessPolicyPublicRead]; // We'll make it public
[request start];
BOOL success = [[request responseString] isEqualToString:@""];
success = [[request responseString] isEqualToString:@""];
GHAssertTrue(success,@"Failed to PUT the gzipped file");
// GET the file
... ...
//
// ProxyTests.h
// Mac
//
// Created by Ben Copsey on 02/08/2009.
// Copyright 2009 All-Seeing Interactive. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ASITestCase.h"
@class ASINetworkQueue;
// Proxy tests must be run separately from other tests, using the proxy you specify
// Some tests require an authenticating proxy to function
@interface ProxyTests : ASITestCase {
ASINetworkQueue *queue;
BOOL complete;
}
- (void)testProxy;
- (void)testProxyAutodetect;
- (void)testProxyWithSuppliedAuthenticationCredentials;
@property (retain) ASINetworkQueue *queue;
@property (assign) BOOL complete;
@end
... ...
//
// ProxyTests.m
// Mac
//
// Created by Ben Copsey on 02/08/2009.
// Copyright 2009 All-Seeing Interactive. All rights reserved.
//
#import "ProxyTests.h"
#import "ASIHTTPRequest.h"
#import "ASINetworkQueue.h"
// Fill in these to run the proxy tests
static NSString *proxyHost = @"";
static int proxyPort = 0;
static NSString *proxyUsername = @"";
static NSString *proxyPassword = @"";
@implementation ProxyTests
- (void)testProxy
{
BOOL success = (![proxyHost isEqualToString:@""] && proxyPort > 0);
GHAssertTrue(success,@"You need to supply the details of your proxy to run the proxy autodetect test");
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com"]];
[request setProxyHost:proxyHost];
[request setProxyPort:proxyPort];
[request start];
// Check data is as expected
NSRange notFound = NSMakeRange(NSNotFound, 0);
success = !NSEqualRanges([[request responseString] rangeOfString:@"All-Seeing Interactive"],notFound);
GHAssertTrue(success,@"Failed to download the correct data, navigating the proxy");
}
- (void)testProxyAutodetect
{
BOOL success = (![proxyHost isEqualToString:@""] && proxyPort > 0);
GHAssertTrue(success,@"You need to supply the details of your proxy to run the proxy autodetect test");
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com"]];
[request start];
success = ([request proxyHost] && [request proxyPort]);
GHAssertTrue(success,@"Failed to detect the proxy");
}
- (void)testProxyWithSuppliedAuthenticationCredentials
{
BOOL success = (![proxyHost isEqualToString:@""] && proxyPort > 0 && ![proxyUsername isEqualToString:@""] && ![proxyPassword isEqualToString:@""]);
GHAssertTrue(success,@"You need to supply the details of your authenticating proxy to run the proxy authentication test");
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com"]];
[request setProxyHost:proxyHost];
[request setProxyPort:proxyPort];
[request setProxyUsername:proxyUsername];
[request setProxyPassword:proxyPassword];
[request start];
// Check data is as expected
NSRange notFound = NSMakeRange(NSNotFound, 0);
success = !NSEqualRanges([[request responseString] rangeOfString:@"All-Seeing Interactive"],notFound);
GHAssertTrue(success,@"Failed to download the correct data, navigating the proxy");
}
- (void)testProxyWithDelegateSupplyingCredentials
{
[self setComplete:NO];
BOOL success = (![proxyHost isEqualToString:@""] && proxyPort > 0 && ![proxyUsername isEqualToString:@""] && ![proxyPassword isEqualToString:@""]);
GHAssertTrue(success,@"You need to supply the details of your authenticating proxy to run the proxy authentication test");
[[self queue] cancelAllOperations];
[self setQueue:[ASINetworkQueue queue]];
[[self queue] setDelegate:self];
[[self queue] setRequestDidFinishSelector:@selector(requestFinished:)];
[[self queue] setRequestDidFailSelector:@selector(requestFailed:)];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com"]];
[[self queue] addOperation:request];
[queue go];
while (![self complete]) {
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
}
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
[self setComplete:YES];
// Check data is as expected
NSRange notFound = NSMakeRange(NSNotFound, 0);
BOOL success = !NSEqualRanges([[request responseString] rangeOfString:@"All-Seeing Interactive"],notFound);
GHAssertTrue(success,@"Failed to download the correct data, navigating the proxy");
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
[self setComplete:YES];
GHAssertTrue(0,@"Request failed when it shouldn't have done so");
}
- (void)proxyAuthorizationNeededForRequest:(ASIHTTPRequest *)request
{
[request setProxyUsername:proxyUsername];
[request setProxyPassword:proxyPassword];
[request retryWithAuthentication];
}
- (void)testDoubleAuthentication
{
[self setComplete:NO];
BOOL success = (![proxyHost isEqualToString:@""] && proxyPort > 0 && ![proxyUsername isEqualToString:@""] && ![proxyPassword isEqualToString:@""]);
GHAssertTrue(success,@"You need to supply the details of your authenticating proxy to run the proxy authentication test");
[[self queue] cancelAllOperations];
[self setQueue:[ASINetworkQueue queue]];
[[self queue] setDelegate:self];
[[self queue] setRequestDidFinishSelector:@selector(requestDone:)];
[[self queue] setRequestDidFailSelector:@selector(requestFailed:)];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/basic-authentication"]];
[[self queue] addOperation:request];
[queue go];
while (![self complete]) {
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
}
}
- (void)requestDone:(ASIHTTPRequest *)request
{
[self setComplete:YES];
}
- (void)authorizationNeededForRequest:(ASIHTTPRequest *)request
{
[request setUsername:@"secret_username"];
[request setPassword:@"secret_password"];
[request retryWithAuthentication];
}
@synthesize queue;
@synthesize complete;
@end
... ...
This diff was suppressed by a .gitattributes entry.
... ... @@ -69,7 +69,6 @@
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
... ...