Fix various issues with cookie stuff, expiry dates should be working now
Showing
4 changed files
with
110 additions
and
92 deletions
@@ -14,7 +14,7 @@ | @@ -14,7 +14,7 @@ | ||
14 | { | 14 | { |
15 | NSString *prop = [property lowercaseString]; | 15 | NSString *prop = [property lowercaseString]; |
16 | if ([prop isEqualToString:@"expires"]) { | 16 | if ([prop isEqualToString:@"expires"]) { |
17 | - //[self setExpires:[NSDate dateFrom | 17 | + [self setExpires:[NSDate dateWithNaturalLanguageString:newValue]]; |
18 | return; | 18 | return; |
19 | } else if ([prop isEqualToString:@"domain"]) { | 19 | } else if ([prop isEqualToString:@"domain"]) { |
20 | [self setDomain:newValue]; | 20 | [self setDomain:newValue]; |
@@ -24,102 +24,120 @@ More tests needed for: | @@ -24,102 +24,120 @@ More tests needed for: | ||
24 | - Session persistence | 24 | - Session persistence |
25 | */ | 25 | */ |
26 | 26 | ||
27 | -//- (void)testBasicDownload | 27 | +- (void)testBasicDownload |
28 | -//{ | 28 | +{ |
29 | -// //Grab data | 29 | + //Grab data |
30 | -// NSURL *url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com"] autorelease]; | 30 | + NSURL *url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com"] autorelease]; |
31 | -// ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | 31 | + ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; |
32 | -// [request start]; | 32 | + [request start]; |
33 | -// NSString *html = [request dataString]; | 33 | + NSString *html = [request dataString]; |
34 | -// STAssertNotNil(html,@"Basic synchronous request failed"); | 34 | + STAssertNotNil(html,@"Basic synchronous request failed"); |
35 | -// | 35 | + |
36 | -// //Check we're getting the correct response headers | 36 | + //Check we're getting the correct response headers |
37 | -// NSString *pingBackHeader = [[request responseHeaders] objectForKey:@"X-Pingback"]; | 37 | + NSString *pingBackHeader = [[request responseHeaders] objectForKey:@"X-Pingback"]; |
38 | -// BOOL success = [pingBackHeader isEqualToString:@"http://allseeing-i.com/Ping-Back"]; | 38 | + BOOL success = [pingBackHeader isEqualToString:@"http://allseeing-i.com/Ping-Back"]; |
39 | -// STAssertTrue(success,@"Failed to populate response headers"); | 39 | + STAssertTrue(success,@"Failed to populate response headers"); |
40 | -// | 40 | + |
41 | -// //Check we're getting back the correct status code | 41 | + //Check we're getting back the correct status code |
42 | -// url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/a-page-that-does-not-exist"] autorelease]; | 42 | + url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/a-page-that-does-not-exist"] autorelease]; |
43 | -// request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | 43 | + request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; |
44 | -// [request start]; | 44 | + [request start]; |
45 | -// success = ([request responseStatusCode] == 404); | 45 | + success = ([request responseStatusCode] == 404); |
46 | -// STAssertTrue(success,@"Didn't get correct status code"); | 46 | + STAssertTrue(success,@"Didn't get correct status code"); |
47 | -// | 47 | + |
48 | -// //Check data | 48 | + //Check data |
49 | -// NSRange notFound = NSMakeRange(NSNotFound, 0); | 49 | + NSRange notFound = NSMakeRange(NSNotFound, 0); |
50 | -// success = !NSEqualRanges([html rangeOfString:@"All-Seeing Interactive"],notFound); | 50 | + success = !NSEqualRanges([html rangeOfString:@"All-Seeing Interactive"],notFound); |
51 | -// STAssertTrue(success,@"Failed to download the correct data"); | 51 | + STAssertTrue(success,@"Failed to download the correct data"); |
52 | -// | 52 | + |
53 | -// //Attempt to grab from bad url (astonishingly, there is a website at http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com !) | 53 | + //Attempt to grab from bad url (astonishingly, there is a website at http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com !) |
54 | -// url = [[[NSURL alloc] initWithString:@"http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaab.com"] autorelease]; | 54 | + url = [[[NSURL alloc] initWithString:@"http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaab.com"] autorelease]; |
55 | -// request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | 55 | + request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; |
56 | -// [request start]; | 56 | + [request start]; |
57 | -// NSError *error = [request error]; | 57 | + NSError *error = [request error]; |
58 | -// 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)"); | 58 | + 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)"); |
59 | -//} | 59 | +} |
60 | -// | 60 | + |
61 | -//- (void)testOperationQueue | 61 | +- (void)testOperationQueue |
62 | -//{ | 62 | +{ |
63 | -// NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease]; | 63 | + NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease]; |
64 | -// | 64 | + |
65 | -// NSURL *url; | 65 | + NSURL *url; |
66 | -// url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/first"] autorelease]; | 66 | + url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/first"] autorelease]; |
67 | -// ASIHTTPRequest *request1 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | 67 | + ASIHTTPRequest *request1 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; |
68 | -// [queue addOperation:request1]; | 68 | + [queue addOperation:request1]; |
69 | -// | 69 | + |
70 | -// url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/second"] autorelease]; | 70 | + url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/second"] autorelease]; |
71 | -// ASIHTTPRequest *request2 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | 71 | + ASIHTTPRequest *request2 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; |
72 | -// [queue addOperation:request2]; | 72 | + [queue addOperation:request2]; |
73 | -// | 73 | + |
74 | -// url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/third"] autorelease]; | 74 | + url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/third"] autorelease]; |
75 | -// ASIHTTPRequest *request3 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | 75 | + ASIHTTPRequest *request3 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; |
76 | -// [queue addOperation:request3]; | 76 | + [queue addOperation:request3]; |
77 | -// | 77 | + |
78 | -// url = [[[NSURL alloc] initWithString:@"http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaab.com"] autorelease]; | 78 | + url = [[[NSURL alloc] initWithString:@"http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaab.com"] autorelease]; |
79 | -// ASIHTTPRequest *request4 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | 79 | + ASIHTTPRequest *request4 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; |
80 | -// [queue addOperation:request4]; | 80 | + [queue addOperation:request4]; |
81 | -// | 81 | + |
82 | -// url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/broken"] autorelease]; | 82 | + url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/broken"] autorelease]; |
83 | -// ASIHTTPRequest *request5 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | 83 | + ASIHTTPRequest *request5 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; |
84 | -// [queue addOperation:request5]; | 84 | + [queue addOperation:request5]; |
85 | -// | 85 | + |
86 | -// [queue waitUntilAllOperationsAreFinished]; | 86 | + [queue waitUntilAllOperationsAreFinished]; |
87 | -// | 87 | + |
88 | -// BOOL success; | 88 | + BOOL success; |
89 | -// | 89 | + |
90 | -// success = ([request1 error] == nil); | 90 | + success = ([request1 error] == nil); |
91 | -// STAssertTrue(success,@"Request 1 failed"); | 91 | + STAssertTrue(success,@"Request 1 failed"); |
92 | -// | 92 | + |
93 | -// success = [[request1 dataString] isEqualToString:@"This is the expected content for the first string"]; | 93 | + success = [[request1 dataString] isEqualToString:@"This is the expected content for the first string"]; |
94 | -// STAssertTrue(success,@"Failed to download the correct data for request 1"); | 94 | + STAssertTrue(success,@"Failed to download the correct data for request 1"); |
95 | -// | 95 | + |
96 | -// success = ([request2 error] == nil); | 96 | + success = ([request2 error] == nil); |
97 | -// STAssertTrue(success,@"Request 2 failed"); | 97 | + STAssertTrue(success,@"Request 2 failed"); |
98 | -// | 98 | + |
99 | -// success = [[request2 dataString] isEqualToString:@"This is the expected content for the second string"]; | 99 | + success = [[request2 dataString] isEqualToString:@"This is the expected content for the second string"]; |
100 | -// STAssertTrue(success,@"Failed to download the correct data for request 2"); | 100 | + STAssertTrue(success,@"Failed to download the correct data for request 2"); |
101 | -// | 101 | + |
102 | -// success = ([request3 error] == nil); | 102 | + success = ([request3 error] == nil); |
103 | -// STAssertTrue(success,@"Request 3 failed"); | 103 | + STAssertTrue(success,@"Request 3 failed"); |
104 | -// | 104 | + |
105 | -// success = [[request3 dataString] isEqualToString:@"This is the expected content for the third string"]; | 105 | + success = [[request3 dataString] isEqualToString:@"This is the expected content for the third string"]; |
106 | -// STAssertTrue(success,@"Failed to download the correct data for request 3"); | 106 | + STAssertTrue(success,@"Failed to download the correct data for request 3"); |
107 | -// | 107 | + |
108 | -// success = ([request4 error] != nil); | 108 | + success = ([request4 error] != nil); |
109 | -// 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)"); | 109 | + 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)"); |
110 | -// | 110 | + |
111 | -// success = ([request5 error] == nil); | 111 | + success = ([request5 error] == nil); |
112 | -// STAssertTrue(success,@"Request 5 failed"); | 112 | + STAssertTrue(success,@"Request 5 failed"); |
113 | -// | 113 | + |
114 | -// success = ([request5 responseStatusCode] == 404); | 114 | + success = ([request5 responseStatusCode] == 404); |
115 | -// STAssertTrue(success,@"Failed to obtain the correct status code for request 5"); | 115 | + STAssertTrue(success,@"Failed to obtain the correct status code for request 5"); |
116 | -// | 116 | + |
117 | -//} | 117 | +} |
118 | 118 | ||
119 | - (void)testCookies | 119 | - (void)testCookies |
120 | { | 120 | { |
121 | BOOL success; | 121 | BOOL success; |
122 | 122 | ||
123 | + //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 | ||
124 | + NSString *dte = @"Sun, 06 Nov 1994 08:49:37 GMT"; | ||
125 | + | ||
126 | + NSDate *date = [NSDate dateWithNaturalLanguageString:dte]; | ||
127 | + NSDate *referenceDate = [NSDate dateWithString:@"1994-11-06 08:49:37 +0000"]; | ||
128 | + success = [date isEqualToDate:referenceDate]; | ||
129 | + STAssertTrue(success,@"Date parse 1 failed"); | ||
130 | + | ||
131 | + dte = @"Sunday, 06-Nov-94 08:49:37 GMT"; | ||
132 | + date = [NSDate dateWithNaturalLanguageString:dte]; | ||
133 | + success = [date isEqualToDate:referenceDate]; | ||
134 | + STAssertTrue(success,@"Date parse 2 failed"); | ||
135 | + | ||
136 | + dte = @"Sun Nov 6 08:49:37 1994"; | ||
137 | + date = [NSDate dateWithNaturalLanguageString:dte]; | ||
138 | + success = [date isEqualToDate:referenceDate]; | ||
139 | + STAssertTrue(success,@"Date parse 3 failed"); | ||
140 | + | ||
123 | NSURL *url = [[[NSURL alloc] initWithString:@"http://asi/asi-http-request/tests/set_cookie"] autorelease]; | 141 | NSURL *url = [[[NSURL alloc] initWithString:@"http://asi/asi-http-request/tests/set_cookie"] autorelease]; |
124 | ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | 142 | ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; |
125 | [request setUseCookiePersistance:YES]; | 143 | [request setUseCookiePersistance:YES]; |
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
-
Please register or login to post a comment