|
@@ -25,24 +25,25 @@
|
|
|
#import "AFSecurityPolicy.h"
|
|
|
|
|
|
@interface AFHTTPSessionManagerTests : AFTestCase
|
|
|
-@property (readwrite, nonatomic, strong) AFHTTPSessionManager *manager;
|
|
|
+@property (readwrite, nonatomic, strong) AFHTTPSessionManager *sessionManager;
|
|
|
@end
|
|
|
|
|
|
@implementation AFHTTPSessionManagerTests
|
|
|
|
|
|
- (void)setUp {
|
|
|
[super setUp];
|
|
|
- self.manager = [[AFHTTPSessionManager alloc] initWithBaseURL:self.baseURL];
|
|
|
+ self.sessionManager = [[AFHTTPSessionManager alloc] initWithBaseURL:self.baseURL];
|
|
|
}
|
|
|
|
|
|
- (void)tearDown {
|
|
|
- [self.manager invalidateSessionCancelingTasks:YES];
|
|
|
+ [self.sessionManager invalidateSessionCancelingTasks:YES resetSession:NO];
|
|
|
+ self.sessionManager = nil;
|
|
|
[super tearDown];
|
|
|
}
|
|
|
|
|
|
#pragma mark - init
|
|
|
-- (void)testSharedManagerIsNotEqualToInitdManager {
|
|
|
- XCTAssertFalse([[AFHTTPSessionManager manager] isEqual:self.manager]);
|
|
|
+- (void)testSharedManagerIsNotEqualToInitedManager {
|
|
|
+ XCTAssertFalse([[AFHTTPSessionManager manager] isEqual:self.sessionManager]);
|
|
|
}
|
|
|
|
|
|
#pragma mark - misc
|
|
@@ -54,7 +55,7 @@
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
|
|
|
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/get" relativeToURL:self.baseURL]];
|
|
|
- NSURLSessionDataTask *task = [self.manager dataTaskWithRequest:request uploadProgress:nil downloadProgress:nil
|
|
|
+ NSURLSessionDataTask *task = [self.sessionManager dataTaskWithRequest:request uploadProgress:nil downloadProgress:nil
|
|
|
completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
|
|
|
blockResponseObject = responseObject;
|
|
|
blockError = error;
|
|
@@ -76,7 +77,7 @@
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
|
|
|
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/status/404" relativeToURL:self.baseURL]];
|
|
|
- NSURLSessionDataTask *task = [self.manager dataTaskWithRequest:request uploadProgress:nil downloadProgress:nil
|
|
|
+ NSURLSessionDataTask *task = [self.sessionManager dataTaskWithRequest:request uploadProgress:nil downloadProgress:nil
|
|
|
completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
|
|
|
blockError = error;
|
|
|
[expectation fulfill];
|
|
@@ -97,13 +98,13 @@
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
|
|
|
NSURLRequest *redirectRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/redirect/1" relativeToURL:self.baseURL]];
|
|
|
- NSURLSessionDataTask *redirectTask = [self.manager dataTaskWithRequest:redirectRequest uploadProgress:nil downloadProgress:nil
|
|
|
+ NSURLSessionDataTask *redirectTask = [self.sessionManager dataTaskWithRequest:redirectRequest uploadProgress:nil downloadProgress:nil
|
|
|
completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
|
|
|
blockError = error;
|
|
|
[expectation fulfill];
|
|
|
}];
|
|
|
|
|
|
- [self.manager setTaskWillPerformHTTPRedirectionBlock:^NSURLRequest *(NSURLSession *session, NSURLSessionTask *task, NSURLResponse *response, NSURLRequest *request) {
|
|
|
+ [self.sessionManager setTaskWillPerformHTTPRedirectionBlock:^NSURLRequest *(NSURLSession *session, NSURLSessionTask *task, NSURLResponse *response, NSURLRequest *request) {
|
|
|
if (response) {
|
|
|
success = YES;
|
|
|
}
|
|
@@ -126,14 +127,14 @@
|
|
|
__block NSURL *downloadFilePath = nil;
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
|
|
|
- [self.manager setDownloadTaskDidFinishDownloadingBlock:^NSURL *(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, NSURL *location) {
|
|
|
+ [self.sessionManager setDownloadTaskDidFinishDownloadingBlock:^NSURL *(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, NSURL *location) {
|
|
|
managerDownloadFinishedBlockExecuted = YES;
|
|
|
NSURL *dirURL = [[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject];
|
|
|
return [dirURL URLByAppendingPathComponent:@"t1.file"];
|
|
|
}];
|
|
|
|
|
|
NSURLSessionDownloadTask *downloadTask;
|
|
|
- downloadTask = [self.manager
|
|
|
+ downloadTask = [self.sessionManager
|
|
|
downloadTaskWithRequest:[NSURLRequest requestWithURL:self.baseURL]
|
|
|
progress:nil
|
|
|
destination:nil
|
|
@@ -155,7 +156,7 @@
|
|
|
__block NSURL *downloadFilePath = nil;
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
|
|
|
- NSURLSessionDownloadTask *downloadTask = [self.manager downloadTaskWithRequest:[NSURLRequest requestWithURL:self.baseURL]
|
|
|
+ NSURLSessionDownloadTask *downloadTask = [self.sessionManager downloadTaskWithRequest:[NSURLRequest requestWithURL:self.baseURL]
|
|
|
progress:nil
|
|
|
destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
|
|
|
destinationBlockExecuted = YES;
|
|
@@ -177,7 +178,7 @@
|
|
|
- (void)testThatSerializationErrorGeneratesErrorAndNullTaskForGET {
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Serialization should fail"];
|
|
|
|
|
|
- [self.manager.requestSerializer setQueryStringSerializationWithBlock:^NSString * _Nonnull(NSURLRequest * _Nonnull request, id _Nonnull parameters, NSError * _Nullable __autoreleasing * _Nullable error) {
|
|
|
+ [self.sessionManager.requestSerializer setQueryStringSerializationWithBlock:^NSString * _Nonnull(NSURLRequest * _Nonnull request, id _Nonnull parameters, NSError * _Nullable __autoreleasing * _Nullable error) {
|
|
|
if (error != NULL) {
|
|
|
*error = [NSError errorWithDomain:@"Custom" code:-1 userInfo:nil];
|
|
|
}
|
|
@@ -185,9 +186,10 @@
|
|
|
}];
|
|
|
|
|
|
NSURLSessionTask *nilTask;
|
|
|
- nilTask = [self.manager
|
|
|
+ nilTask = [self.sessionManager
|
|
|
GET:@"test"
|
|
|
parameters:@{@"key":@"value"}
|
|
|
+ headers:nil
|
|
|
progress:nil
|
|
|
success:nil
|
|
|
failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
|
@@ -205,12 +207,12 @@
|
|
|
}
|
|
|
|
|
|
- (void)testCanBeEncoded {
|
|
|
- NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self.manager];
|
|
|
+ NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self.sessionManager];
|
|
|
XCTAssertNotNil(data);
|
|
|
}
|
|
|
|
|
|
- (void)testCanBeDecoded {
|
|
|
- NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self.manager];
|
|
|
+ NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self.sessionManager];
|
|
|
AFHTTPSessionManager *newManager = [NSKeyedUnarchiver unarchiveObjectWithData:data];
|
|
|
XCTAssertNotNil(newManager.securityPolicy);
|
|
|
XCTAssertNotNil(newManager.requestSerializer);
|
|
@@ -223,7 +225,7 @@
|
|
|
#pragma mark - NSCopying
|
|
|
|
|
|
- (void)testCanBeCopied {
|
|
|
- AFHTTPSessionManager *copyManager = [self.manager copy];
|
|
|
+ AFHTTPSessionManager *copyManager = [self.sessionManager copy];
|
|
|
XCTAssertNotNil(copyManager);
|
|
|
}
|
|
|
|
|
@@ -231,9 +233,10 @@
|
|
|
|
|
|
- (void)testDownloadProgressIsReportedForGET {
|
|
|
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"Progress Should equal 1.0"];
|
|
|
- [self.manager
|
|
|
+ [self.sessionManager
|
|
|
GET:@"image"
|
|
|
parameters:nil
|
|
|
+ headers:nil
|
|
|
progress:^(NSProgress * _Nonnull downloadProgress) {
|
|
|
if (downloadProgress.fractionCompleted == 1.0) {
|
|
|
[expectation fulfill];
|
|
@@ -252,9 +255,10 @@
|
|
|
|
|
|
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"Progress Should equal 1.0"];
|
|
|
|
|
|
- [self.manager
|
|
|
+ [self.sessionManager
|
|
|
POST:@"post"
|
|
|
parameters:payload
|
|
|
+ headers:nil
|
|
|
progress:^(NSProgress * _Nonnull uploadProgress) {
|
|
|
if (uploadProgress.fractionCompleted == 1.0) {
|
|
|
[expectation fulfill];
|
|
@@ -273,9 +277,10 @@
|
|
|
|
|
|
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"Progress Should equal 1.0"];
|
|
|
|
|
|
- [self.manager
|
|
|
+ [self.sessionManager
|
|
|
POST:@"post"
|
|
|
parameters:nil
|
|
|
+ headers:nil
|
|
|
constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
|
|
|
[formData appendPartWithFileData:[payload dataUsingEncoding:NSUTF8StringEncoding] name:@"AFNetworking" fileName:@"AFNetworking" mimeType:@"text/html"];
|
|
|
}
|
|
@@ -289,13 +294,83 @@
|
|
|
[self waitForExpectationsWithCommonTimeout];
|
|
|
}
|
|
|
|
|
|
+# pragma mark - Deprecated Progress
|
|
|
+
|
|
|
+- (void)testDownloadProgressIsReportedForDeprecatedGET {
|
|
|
+ __weak XCTestExpectation *expectation = [self expectationWithDescription:@"Progress Should equal 1.0"];
|
|
|
+#pragma clang diagnostic push
|
|
|
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
|
+ [self.sessionManager
|
|
|
+ GET:@"image"
|
|
|
+ parameters:nil
|
|
|
+ progress:^(NSProgress * _Nonnull downloadProgress) {
|
|
|
+ if (downloadProgress.fractionCompleted == 1.0) {
|
|
|
+ [expectation fulfill];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ success:nil
|
|
|
+ failure:nil];
|
|
|
+#pragma clang diagnostic pop
|
|
|
+ [self waitForExpectationsWithCommonTimeout];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)testUploadProgressIsReportedForDeprecatedPOST {
|
|
|
+ NSMutableString *payload = [NSMutableString stringWithString:@"AFNetworking"];
|
|
|
+ while ([payload lengthOfBytesUsingEncoding:NSUTF8StringEncoding] < 20000) {
|
|
|
+ [payload appendString:@"AFNetworking"];
|
|
|
+ }
|
|
|
+
|
|
|
+ __weak XCTestExpectation *expectation = [self expectationWithDescription:@"Progress Should equal 1.0"];
|
|
|
+#pragma clang diagnostic push
|
|
|
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
|
+ [self.sessionManager
|
|
|
+ POST:@"post"
|
|
|
+ parameters:payload
|
|
|
+ progress:^(NSProgress * _Nonnull uploadProgress) {
|
|
|
+ if (uploadProgress.fractionCompleted == 1.0) {
|
|
|
+ [expectation fulfill];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ success:nil
|
|
|
+ failure:nil];
|
|
|
+#pragma clang diagnostic pop
|
|
|
+ [self waitForExpectationsWithCommonTimeout];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)testUploadProgressIsReportedForStreamingDeprecatedPost {
|
|
|
+ NSMutableString *payload = [NSMutableString stringWithString:@"AFNetworking"];
|
|
|
+ while ([payload lengthOfBytesUsingEncoding:NSUTF8StringEncoding] < 20000) {
|
|
|
+ [payload appendString:@"AFNetworking"];
|
|
|
+ }
|
|
|
+
|
|
|
+ __weak XCTestExpectation *expectation = [self expectationWithDescription:@"Progress Should equal 1.0"];
|
|
|
+#pragma clang diagnostic push
|
|
|
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
|
+ [self.sessionManager
|
|
|
+ POST:@"post"
|
|
|
+ parameters:nil
|
|
|
+ constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
|
|
|
+ [formData appendPartWithFileData:[payload dataUsingEncoding:NSUTF8StringEncoding] name:@"AFNetworking" fileName:@"AFNetworking" mimeType:@"text/html"];
|
|
|
+ }
|
|
|
+ progress:^(NSProgress * _Nonnull uploadProgress) {
|
|
|
+ if (uploadProgress.fractionCompleted == 1.0) {
|
|
|
+ [expectation fulfill];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ success:nil
|
|
|
+ failure:nil];
|
|
|
+#pragma clang diagnostic pop
|
|
|
+ [self waitForExpectationsWithCommonTimeout];
|
|
|
+}
|
|
|
+
|
|
|
# pragma mark - HTTP Status Codes
|
|
|
|
|
|
- (void)testThatSuccessBlockIsCalledFor200 {
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
- [self.manager
|
|
|
+ [self.sessionManager
|
|
|
GET:@"status/200"
|
|
|
parameters:nil
|
|
|
+ headers:nil
|
|
|
progress:nil
|
|
|
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
[expectation fulfill];
|
|
@@ -306,9 +381,10 @@
|
|
|
|
|
|
- (void)testThatFailureBlockIsCalledFor404 {
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
- [self.manager
|
|
|
+ [self.sessionManager
|
|
|
GET:@"status/404"
|
|
|
parameters:nil
|
|
|
+ headers:nil
|
|
|
progress:nil
|
|
|
success:nil
|
|
|
failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nullable error) {
|
|
@@ -320,9 +396,10 @@
|
|
|
- (void)testThatResponseObjectIsEmptyFor204 {
|
|
|
__block id urlResponseObject = nil;
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
- [self.manager
|
|
|
+ [self.sessionManager
|
|
|
GET:@"status/204"
|
|
|
parameters:nil
|
|
|
+ headers:nil
|
|
|
progress:nil
|
|
|
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
urlResponseObject = responseObject;
|
|
@@ -337,9 +414,10 @@
|
|
|
|
|
|
- (void)testGET {
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
- [self.manager
|
|
|
+ [self.sessionManager
|
|
|
GET:@"get"
|
|
|
parameters:nil
|
|
|
+ headers:nil
|
|
|
progress:nil
|
|
|
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
XCTAssertNotNil(responseObject);
|
|
@@ -351,9 +429,10 @@
|
|
|
|
|
|
- (void)testHEAD {
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
- [self.manager
|
|
|
+ [self.sessionManager
|
|
|
HEAD:@"get"
|
|
|
parameters:nil
|
|
|
+ headers:nil
|
|
|
success:^(NSURLSessionDataTask * _Nonnull task) {
|
|
|
XCTAssertNotNil(task);
|
|
|
[expectation fulfill];
|
|
@@ -364,11 +443,13 @@
|
|
|
|
|
|
- (void)testPOST {
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
- [self.manager
|
|
|
+ [self.sessionManager
|
|
|
POST:@"post"
|
|
|
parameters:@{@"key":@"value"}
|
|
|
+ headers:@{@"field":@"value"}
|
|
|
progress:nil
|
|
|
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
+ XCTAssertTrue([task.originalRequest.allHTTPHeaderFields[@"field"] isEqualToString:@"value"]);
|
|
|
XCTAssertTrue([responseObject[@"form"][@"key"] isEqualToString:@"value"]);
|
|
|
[expectation fulfill];
|
|
|
}
|
|
@@ -378,9 +459,10 @@
|
|
|
|
|
|
- (void)testPOSTWithConstructingBody {
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
- [self.manager
|
|
|
+ [self.sessionManager
|
|
|
POST:@"post"
|
|
|
parameters:@{@"key":@"value"}
|
|
|
+ headers:@{@"field":@"value"}
|
|
|
constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
|
|
|
[formData appendPartWithFileData:[@"Data" dataUsingEncoding:NSUTF8StringEncoding]
|
|
|
name:@"DataName"
|
|
@@ -389,6 +471,7 @@
|
|
|
}
|
|
|
progress:nil
|
|
|
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
+ XCTAssertTrue([task.originalRequest.allHTTPHeaderFields[@"field"] isEqualToString:@"value"]);
|
|
|
XCTAssertTrue([responseObject[@"files"][@"DataName"] isEqualToString:@"Data"]);
|
|
|
XCTAssertTrue([responseObject[@"form"][@"key"] isEqualToString:@"value"]);
|
|
|
[expectation fulfill];
|
|
@@ -399,10 +482,12 @@
|
|
|
|
|
|
- (void)testPUT {
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
- [self.manager
|
|
|
+ [self.sessionManager
|
|
|
PUT:@"put"
|
|
|
parameters:@{@"key":@"value"}
|
|
|
+ headers:@{@"field":@"value"}
|
|
|
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
+ XCTAssertTrue([task.originalRequest.allHTTPHeaderFields[@"field"] isEqualToString:@"value"]);
|
|
|
XCTAssertTrue([responseObject[@"form"][@"key"] isEqualToString:@"value"]);
|
|
|
[expectation fulfill];
|
|
|
}
|
|
@@ -412,10 +497,12 @@
|
|
|
|
|
|
- (void)testDELETE {
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
- [self.manager
|
|
|
+ [self.sessionManager
|
|
|
DELETE:@"delete"
|
|
|
parameters:@{@"key":@"value"}
|
|
|
+ headers:@{@"field":@"value"}
|
|
|
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
+ XCTAssertTrue([task.originalRequest.allHTTPHeaderFields[@"field"] isEqualToString:@"value"]);
|
|
|
XCTAssertTrue([responseObject[@"args"][@"key"] isEqualToString:@"value"]);
|
|
|
[expectation fulfill];
|
|
|
}
|
|
@@ -425,10 +512,12 @@
|
|
|
|
|
|
- (void)testPATCH {
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
- [self.manager
|
|
|
+ [self.sessionManager
|
|
|
PATCH:@"patch"
|
|
|
parameters:@{@"key":@"value"}
|
|
|
+ headers:@{@"field":@"value"}
|
|
|
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
+ XCTAssertTrue([task.originalRequest.allHTTPHeaderFields[@"field"] isEqualToString:@"value"]);
|
|
|
XCTAssertTrue([responseObject[@"form"][@"key"] isEqualToString:@"value"]);
|
|
|
[expectation fulfill];
|
|
|
}
|
|
@@ -439,11 +528,11 @@
|
|
|
|
|
|
#pragma mark - Deprecated Rest Interface
|
|
|
|
|
|
-- (void)testDeprecatedGET {
|
|
|
+- (void)testDeprecatedGETWithoutProgress {
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
#pragma clang diagnostic push
|
|
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
|
- [self.manager
|
|
|
+ [self.sessionManager
|
|
|
GET:@"get"
|
|
|
parameters:nil
|
|
|
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
@@ -455,11 +544,11 @@
|
|
|
[self waitForExpectationsWithCommonTimeout];
|
|
|
}
|
|
|
|
|
|
-- (void)testDeprecatedPOST {
|
|
|
+- (void)testDeprecatedPOSTWithoutProgress {
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
#pragma clang diagnostic push
|
|
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
|
- [self.manager
|
|
|
+ [self.sessionManager
|
|
|
POST:@"post"
|
|
|
parameters:@{@"key":@"value"}
|
|
|
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
@@ -471,11 +560,11 @@
|
|
|
[self waitForExpectationsWithCommonTimeout];
|
|
|
}
|
|
|
|
|
|
-- (void)testDeprecatedPOSTWithConstructingBody {
|
|
|
+- (void)testDeprecatedPOSTWithoutProgressWithConstructingBody {
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
#pragma clang diagnostic push
|
|
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
|
- [self.manager
|
|
|
+ [self.sessionManager
|
|
|
POST:@"post"
|
|
|
parameters:@{@"key":@"value"}
|
|
|
constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
|
|
@@ -494,14 +583,138 @@
|
|
|
[self waitForExpectationsWithCommonTimeout];
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+- (void)testDeprecatedGETWithoutHeaders {
|
|
|
+ XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
+#pragma clang diagnostic push
|
|
|
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
|
+ [self.sessionManager
|
|
|
+ GET:@"get"
|
|
|
+ parameters:nil
|
|
|
+ progress:nil
|
|
|
+ success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
+ XCTAssertNotNil(responseObject);
|
|
|
+ [expectation fulfill];
|
|
|
+ }
|
|
|
+ failure:nil];
|
|
|
+#pragma clang diagnostic pop
|
|
|
+ [self waitForExpectationsWithCommonTimeout];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)testDeprecatedHEADWithoutHeaders {
|
|
|
+ XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
+#pragma clang diagnostic push
|
|
|
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
|
+ [self.sessionManager
|
|
|
+ HEAD:@"get"
|
|
|
+ parameters:nil
|
|
|
+ success:^(NSURLSessionDataTask * _Nonnull task) {
|
|
|
+ XCTAssertNotNil(task);
|
|
|
+ [expectation fulfill];
|
|
|
+ }
|
|
|
+ failure:nil];
|
|
|
+#pragma clang diagnostic pop
|
|
|
+ [self waitForExpectationsWithCommonTimeout];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)testDeprecatedPOSTWithoutHeaders {
|
|
|
+ XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
+#pragma clang diagnostic push
|
|
|
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
|
+ [self.sessionManager
|
|
|
+ POST:@"post"
|
|
|
+ parameters:@{@"key":@"value"}
|
|
|
+ progress:nil
|
|
|
+ success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
+ XCTAssertTrue([responseObject[@"form"][@"key"] isEqualToString:@"value"]);
|
|
|
+ [expectation fulfill];
|
|
|
+ }
|
|
|
+ failure:nil];
|
|
|
+#pragma clang diagnostic pop
|
|
|
+ [self waitForExpectationsWithCommonTimeout];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)testDeprecatedPOSTWithoutHeadersWithConstructingBody {
|
|
|
+ XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
+#pragma clang diagnostic push
|
|
|
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
|
+ [self.sessionManager
|
|
|
+ POST:@"post"
|
|
|
+ parameters:@{@"key":@"value"}
|
|
|
+ constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
|
|
|
+ [formData appendPartWithFileData:[@"Data" dataUsingEncoding:NSUTF8StringEncoding]
|
|
|
+ name:@"DataName"
|
|
|
+ fileName:@"DataFileName"
|
|
|
+ mimeType:@"data"];
|
|
|
+ }
|
|
|
+ progress:nil
|
|
|
+ success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
+ XCTAssertTrue([responseObject[@"files"][@"DataName"] isEqualToString:@"Data"]);
|
|
|
+ XCTAssertTrue([responseObject[@"form"][@"key"] isEqualToString:@"value"]);
|
|
|
+ [expectation fulfill];
|
|
|
+ }
|
|
|
+ failure:nil];
|
|
|
+#pragma clang diagnostic pop
|
|
|
+ [self waitForExpectationsWithCommonTimeout];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)testDeprecatedPUTWithoutHeaders {
|
|
|
+ XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
+#pragma clang diagnostic push
|
|
|
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
|
+ [self.sessionManager
|
|
|
+ PUT:@"put"
|
|
|
+ parameters:@{@"key":@"value"}
|
|
|
+ success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
+ XCTAssertTrue([responseObject[@"form"][@"key"] isEqualToString:@"value"]);
|
|
|
+ [expectation fulfill];
|
|
|
+ }
|
|
|
+ failure:nil];
|
|
|
+#pragma clang diagnostic pop
|
|
|
+ [self waitForExpectationsWithCommonTimeout];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)testDeprecatedDELETEWithoutHeaders {
|
|
|
+ XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
+#pragma clang diagnostic push
|
|
|
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
|
+ [self.sessionManager
|
|
|
+ DELETE:@"delete"
|
|
|
+ parameters:@{@"key":@"value"}
|
|
|
+ success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
+ XCTAssertTrue([responseObject[@"args"][@"key"] isEqualToString:@"value"]);
|
|
|
+ [expectation fulfill];
|
|
|
+ }
|
|
|
+ failure:nil];
|
|
|
+#pragma clang diagnostic pop
|
|
|
+ [self waitForExpectationsWithCommonTimeout];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)testDeprecatedPATCHWithoutHeaders {
|
|
|
+ XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
|
|
|
+#pragma clang diagnostic push
|
|
|
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
|
+ [self.sessionManager
|
|
|
+ PATCH:@"patch"
|
|
|
+ parameters:@{@"key":@"value"}
|
|
|
+ success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
+ XCTAssertTrue([responseObject[@"form"][@"key"] isEqualToString:@"value"]);
|
|
|
+ [expectation fulfill];
|
|
|
+ }
|
|
|
+ failure:nil];
|
|
|
+#pragma clang diagnostic pop
|
|
|
+ [self waitForExpectationsWithCommonTimeout];
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - Auth
|
|
|
|
|
|
- (void)testHiddenBasicAuthentication {
|
|
|
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"Request should finish"];
|
|
|
- [self.manager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"user" password:@"password"];
|
|
|
- [self.manager
|
|
|
+ [self.sessionManager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"user" password:@"password"];
|
|
|
+ [self.sessionManager
|
|
|
GET:@"hidden-basic-auth/user/password"
|
|
|
parameters:nil
|
|
|
+ headers:nil
|
|
|
progress:nil
|
|
|
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
[expectation fulfill];
|
|
@@ -574,6 +787,7 @@
|
|
|
[manager
|
|
|
GET:@""
|
|
|
parameters:nil
|
|
|
+ headers:nil
|
|
|
progress:nil
|
|
|
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
XCTFail(@"Request should fail");
|
|
@@ -585,7 +799,7 @@
|
|
|
[expectation fulfill];
|
|
|
}];
|
|
|
[self waitForExpectationsWithCommonTimeout];
|
|
|
- [manager invalidateSessionCancelingTasks:YES];
|
|
|
+ [manager invalidateSessionCancelingTasks:YES resetSession:NO];
|
|
|
}
|
|
|
|
|
|
- (void)testInvalidServerTrustProducesCorrectErrorForPublicKeyPinning {
|
|
@@ -598,6 +812,7 @@
|
|
|
[manager
|
|
|
GET:@""
|
|
|
parameters:nil
|
|
|
+ headers:nil
|
|
|
progress:nil
|
|
|
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
XCTFail(@"Request should fail");
|
|
@@ -609,7 +824,7 @@
|
|
|
[expectation fulfill];
|
|
|
}];
|
|
|
[self waitForExpectationsWithCommonTimeout];
|
|
|
- [manager invalidateSessionCancelingTasks:YES];
|
|
|
+ [manager invalidateSessionCancelingTasks:YES resetSession:NO];
|
|
|
}
|
|
|
|
|
|
@end
|