Skip to content

Commit

Permalink
Fix various issues with cookie stuff, expiry dates should be working now
Browse files Browse the repository at this point in the history
  • Loading branch information
pokeb committed Aug 25, 2008
1 parent bc988ee commit ec7e960
Show file tree
Hide file tree
Showing 4 changed files with 1,210 additions and 3,180 deletions.
2 changes: 1 addition & 1 deletion ASIHTTPCookie.m
Expand Up @@ -14,7 +14,7 @@ - (void)setValue:(NSString *)newValue forProperty:(NSString *)property
{ {
NSString *prop = [property lowercaseString]; NSString *prop = [property lowercaseString];
if ([prop isEqualToString:@"expires"]) { if ([prop isEqualToString:@"expires"]) {
//[self setExpires:[NSDate dateFrom [self setExpires:[NSDate dateWithNaturalLanguageString:newValue]];
return; return;
} else if ([prop isEqualToString:@"domain"]) { } else if ([prop isEqualToString:@"domain"]) {
[self setDomain:newValue]; [self setDomain:newValue];
Expand Down
200 changes: 109 additions & 91 deletions ASIHTTPRequestTests.m
Expand Up @@ -24,102 +24,120 @@ @implementation ASIHTTPRequestTests
- Session persistence - Session persistence
*/ */


//- (void)testBasicDownload - (void)testBasicDownload
//{ {
// //Grab data //Grab data
// NSURL *url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com"] autorelease]; NSURL *url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com"] autorelease];
// ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
// [request start]; [request start];
// NSString *html = [request dataString]; NSString *html = [request dataString];
// STAssertNotNil(html,@"Basic synchronous request failed"); STAssertNotNil(html,@"Basic synchronous request failed");
//
// //Check we're getting the correct response headers //Check we're getting the correct response headers
// NSString *pingBackHeader = [[request responseHeaders] objectForKey:@"X-Pingback"]; NSString *pingBackHeader = [[request responseHeaders] objectForKey:@"X-Pingback"];
// BOOL success = [pingBackHeader isEqualToString:@"http://allseeing-i.com/Ping-Back"]; BOOL success = [pingBackHeader isEqualToString:@"http://allseeing-i.com/Ping-Back"];
// STAssertTrue(success,@"Failed to populate response headers"); STAssertTrue(success,@"Failed to populate response headers");
//
// //Check we're getting back the correct status code //Check we're getting back the correct status code
// url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/a-page-that-does-not-exist"] autorelease]; url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/a-page-that-does-not-exist"] autorelease];
// request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
// [request start]; [request start];
// success = ([request responseStatusCode] == 404); success = ([request responseStatusCode] == 404);
// STAssertTrue(success,@"Didn't get correct status code"); STAssertTrue(success,@"Didn't get correct status code");
//
// //Check data //Check data
// NSRange notFound = NSMakeRange(NSNotFound, 0); NSRange notFound = NSMakeRange(NSNotFound, 0);
// success = !NSEqualRanges([html rangeOfString:@"All-Seeing Interactive"],notFound); success = !NSEqualRanges([html rangeOfString:@"All-Seeing Interactive"],notFound);
// STAssertTrue(success,@"Failed to download the correct data"); STAssertTrue(success,@"Failed to download the correct data");
//
// //Attempt to grab from bad url (astonishingly, there is a website at http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com !) //Attempt to grab from bad url (astonishingly, there is a website at http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com !)
// url = [[[NSURL alloc] initWithString:@"http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaab.com"] autorelease]; url = [[[NSURL alloc] initWithString:@"http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaab.com"] autorelease];
// request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
// [request start]; [request start];
// NSError *error = [request error]; NSError *error = [request error];
// STAssertNotNil(error,@"Failed to generate an error for a bad host - this test may fail when your DNS server redirects you to another page when it can't find a domain name (eg OpenDNS)"); STAssertNotNil(error,@"Failed to generate an error for a bad host - this test may fail when your DNS server redirects you to another page when it can't find a domain name (eg OpenDNS)");
//} }
//
//- (void)testOperationQueue - (void)testOperationQueue
//{ {
// NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease]; NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
//
// NSURL *url; NSURL *url;
// url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/first"] autorelease]; url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/first"] autorelease];
// ASIHTTPRequest *request1 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; ASIHTTPRequest *request1 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
// [queue addOperation:request1]; [queue addOperation:request1];
//
// url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/second"] autorelease]; url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/second"] autorelease];
// ASIHTTPRequest *request2 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; ASIHTTPRequest *request2 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
// [queue addOperation:request2]; [queue addOperation:request2];
//
// url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/third"] autorelease]; url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/third"] autorelease];
// ASIHTTPRequest *request3 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; ASIHTTPRequest *request3 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
// [queue addOperation:request3]; [queue addOperation:request3];
//
// url = [[[NSURL alloc] initWithString:@"http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaab.com"] autorelease]; url = [[[NSURL alloc] initWithString:@"http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaab.com"] autorelease];
// ASIHTTPRequest *request4 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; ASIHTTPRequest *request4 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
// [queue addOperation:request4]; [queue addOperation:request4];
//
// url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/broken"] autorelease]; url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/broken"] autorelease];
// ASIHTTPRequest *request5 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; ASIHTTPRequest *request5 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
// [queue addOperation:request5]; [queue addOperation:request5];
//
// [queue waitUntilAllOperationsAreFinished]; [queue waitUntilAllOperationsAreFinished];
//
// BOOL success; BOOL success;
//
// success = ([request1 error] == nil); success = ([request1 error] == nil);
// STAssertTrue(success,@"Request 1 failed"); STAssertTrue(success,@"Request 1 failed");
//
// success = [[request1 dataString] isEqualToString:@"This is the expected content for the first string"]; success = [[request1 dataString] isEqualToString:@"This is the expected content for the first string"];
// STAssertTrue(success,@"Failed to download the correct data for request 1"); STAssertTrue(success,@"Failed to download the correct data for request 1");
//
// success = ([request2 error] == nil); success = ([request2 error] == nil);
// STAssertTrue(success,@"Request 2 failed"); STAssertTrue(success,@"Request 2 failed");
//
// success = [[request2 dataString] isEqualToString:@"This is the expected content for the second string"]; success = [[request2 dataString] isEqualToString:@"This is the expected content for the second string"];
// STAssertTrue(success,@"Failed to download the correct data for request 2"); STAssertTrue(success,@"Failed to download the correct data for request 2");
//
// success = ([request3 error] == nil); success = ([request3 error] == nil);
// STAssertTrue(success,@"Request 3 failed"); STAssertTrue(success,@"Request 3 failed");
//
// success = [[request3 dataString] isEqualToString:@"This is the expected content for the third string"]; success = [[request3 dataString] isEqualToString:@"This is the expected content for the third string"];
// STAssertTrue(success,@"Failed to download the correct data for request 3"); STAssertTrue(success,@"Failed to download the correct data for request 3");
//
// success = ([request4 error] != nil); success = ([request4 error] != nil);
// STAssertTrue(success,@"Request 4 succeed when it should have failed - this test may fail when your DNS server redirects you to another page when it can't find a domain name (eg OpenDNS)"); STAssertTrue(success,@"Request 4 succeed when it should have failed - this test may fail when your DNS server redirects you to another page when it can't find a domain name (eg OpenDNS)");
//
// success = ([request5 error] == nil); success = ([request5 error] == nil);
// STAssertTrue(success,@"Request 5 failed"); STAssertTrue(success,@"Request 5 failed");
//
// success = ([request5 responseStatusCode] == 404); success = ([request5 responseStatusCode] == 404);
// STAssertTrue(success,@"Failed to obtain the correct status code for request 5"); STAssertTrue(success,@"Failed to obtain the correct status code for request 5");
//
//} }


- (void)testCookies - (void)testCookies
{ {
BOOL success; BOOL success;


//Firstly, let's make sure cocoa still parses cookie dates correctly using the three examples at http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3
NSString *dte = @"Sun, 06 Nov 1994 08:49:37 GMT";

NSDate *date = [NSDate dateWithNaturalLanguageString:dte];
NSDate *referenceDate = [NSDate dateWithString:@"1994-11-06 08:49:37 +0000"];
success = [date isEqualToDate:referenceDate];
STAssertTrue(success,@"Date parse 1 failed");

dte = @"Sunday, 06-Nov-94 08:49:37 GMT";
date = [NSDate dateWithNaturalLanguageString:dte];
success = [date isEqualToDate:referenceDate];
STAssertTrue(success,@"Date parse 2 failed");

dte = @"Sun Nov 6 08:49:37 1994";
date = [NSDate dateWithNaturalLanguageString:dte];
success = [date isEqualToDate:referenceDate];
STAssertTrue(success,@"Date parse 3 failed");

NSURL *url = [[[NSURL alloc] initWithString:@"http://asi/asi-http-request/tests/set_cookie"] autorelease]; NSURL *url = [[[NSURL alloc] initWithString:@"http://asi/asi-http-request/tests/set_cookie"] autorelease];
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[request setUseCookiePersistance:YES]; [request setUseCookiePersistance:YES];
Expand Down

0 comments on commit ec7e960

Please sign in to comment.