summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2016-08-18 09:34:12 -0400
committerJoel Fischer <joeljfischer@gmail.com>2016-08-18 09:34:12 -0400
commit5f12171c6f202d19726c0a97d77437215d169b77 (patch)
treeb477e3e3ddb6e1cea55c4b72afd5dfc684da4fda
parent0d3dce6a2e1a4e17630a3ad7532f713917b6c943 (diff)
downloadsdl_ios-hotfix/issue_432_HTTP__Convert_ATS.tar.gz
Add a test for HTTP -> HTTPS conversionhotfix/issue_432_HTTP__Convert_ATS
-rw-r--r--SmartDeviceLinkTests/UtilitiesSpecs/HTTP Connection/SDLURLSessionSpec.m166
1 files changed, 88 insertions, 78 deletions
diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/HTTP Connection/SDLURLSessionSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/HTTP Connection/SDLURLSessionSpec.m
index d15bcc049..68caa4e98 100644
--- a/SmartDeviceLinkTests/UtilitiesSpecs/HTTP Connection/SDLURLSessionSpec.m
+++ b/SmartDeviceLinkTests/UtilitiesSpecs/HTTP Connection/SDLURLSessionSpec.m
@@ -10,80 +10,110 @@ describe(@"the url session", ^{
__block SDLURLSession *testSession = nil;
describe(@"attempting to get good data", ^{
- context(@"uploading data", ^{
+ context(@"from an http address", ^{
+ context(@"uploading data", ^{
+ NSData *testData = [@"testData" dataUsingEncoding:NSUTF8StringEncoding];
+ NSArray *someJSONObject = @[@"one", @"two"];
+ NSData *testJSONData = [NSJSONSerialization dataWithJSONObject:someJSONObject options:0 error:nil];
+
+ __block NSData *testReturnData = nil;
+ __block NSURLResponse *testReturnResponse = nil;
+ __block NSError *testReturnError = nil;
+ __block NSArray *testReturnJSONObject = nil;
+
+ beforeEach(^{
+ [OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) {
+ if ([request.URL.host isEqualToString:@"www.faketest.com"]) {
+ testReturnJSONObject = [NSJSONSerialization JSONObjectWithData:request.HTTPBody options:0 error:nil];
+ return YES;
+ }
+
+ return NO;
+ } withStubResponse:^OHHTTPStubsResponse *(NSURLRequest *request) {
+ return [[OHHTTPStubsResponse responseWithData:testData statusCode:200 headers:nil] requestTime:0.5 responseTime:0];
+ }];
+
+ testSession = [[SDLURLSession alloc] init];
+ NSURLRequest *someURLRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.faketest.com"]];
+
+ [testSession uploadWithURLRequest:someURLRequest data:testJSONData completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
+ testReturnData = data;
+ testReturnResponse = response;
+ testReturnError = error;
+ }];
+ });
+
+ afterEach(^{
+ testSession = nil;
+ [OHHTTPStubs removeAllStubs];
+ });
+
+ it(@"should have correct data", ^{
+ expect(testReturnJSONObject).toEventually(equal(someJSONObject));
+ expect(testReturnData).toEventually(equal(testData));
+ expect(testReturnResponse).toEventuallyNot(beNil());
+ expect(testReturnError).toEventually(beNil());
+ });
+ });
+
+ context(@"downloading data", ^{
+ NSData *testData = [@"someData" dataUsingEncoding:NSUTF8StringEncoding];
+
+ __block NSData *testReturnData = nil;
+ __block NSURLResponse *testReturnResponse = nil;
+ __block NSError *testReturnError = nil;
+
+ beforeEach(^{
+ [OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) {
+ return [request.URL.host isEqualToString:@"www.faketest.com"];
+ } withStubResponse:^OHHTTPStubsResponse *(NSURLRequest *request) {
+ return [[OHHTTPStubsResponse responseWithData:testData statusCode:200 headers:nil] requestTime:0.5 responseTime:0];
+ }];
+
+ testSession = [[SDLURLSession alloc] init];
+ [testSession dataFromURL:[NSURL URLWithString:@"https://www.faketest.com"] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
+ testReturnData = data;
+ testReturnResponse = response;
+ testReturnError = error;
+ }];
+ });
+
+ afterEach(^{
+ testSession = nil;
+ [OHHTTPStubs removeAllStubs];
+ });
+
+ it(@"should return correct info", ^{
+ expect(testReturnData).toEventually(equal(testData));
+ expect(testReturnResponse).toEventuallyNot(beNil());
+ expect(testReturnError).toEventually(beNil());
+ });
+ });
+ });
+
+ context(@"from an http address", ^{
NSData *testData = [@"testData" dataUsingEncoding:NSUTF8StringEncoding];
NSArray *someJSONObject = @[@"one", @"two"];
NSData *testJSONData = [NSJSONSerialization dataWithJSONObject:someJSONObject options:0 error:nil];
- __block NSData *testReturnData = nil;
- __block NSURLResponse *testReturnResponse = nil;
- __block NSError *testReturnError = nil;
- __block NSArray *testReturnJSONObject = nil;
+ __block NSString *testURLRequestComponent = nil;
beforeEach(^{
[OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) {
if ([request.URL.host isEqualToString:@"www.faketest.com"]) {
- testReturnJSONObject = [NSJSONSerialization JSONObjectWithData:request.HTTPBody options:0 error:nil];
+ testURLRequestComponent = request.URL.scheme;
return YES;
}
return NO;
} withStubResponse:^OHHTTPStubsResponse *(NSURLRequest *request) {
- return [[OHHTTPStubsResponse responseWithData:testData statusCode:200 headers:nil] requestTime:0.5 responseTime:0];
+ return [[OHHTTPStubsResponse responseWithData:testData statusCode:200 headers:request.allHTTPHeaderFields] requestTime:0.5 responseTime:0];
}];
testSession = [[SDLURLSession alloc] init];
NSURLRequest *someURLRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.faketest.com"]];
- [testSession uploadWithURLRequest:someURLRequest data:testJSONData completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
- testReturnData = data;
- testReturnResponse = response;
- testReturnError = error;
- }];
- });
-
- afterEach(^{
- testSession = nil;
- [OHHTTPStubs removeAllStubs];
- });
-
- it(@"should have the json object", ^{
- expect(testReturnJSONObject).toEventually(equal(someJSONObject));
- });
-
- it(@"should not return any data", ^{
- expect(testReturnData).toEventually(equal(testData));
- });
-
- it(@"should return a response", ^{
- expect(testReturnResponse).toEventuallyNot(beNil());
- });
-
- it(@"should not return an error", ^{
- expect(testReturnError).toEventually(beNil());
- });
- });
-
- context(@"downloading data", ^{
- NSData *testData = [@"someData" dataUsingEncoding:NSUTF8StringEncoding];
-
- __block NSData *testReturnData = nil;
- __block NSURLResponse *testReturnResponse = nil;
- __block NSError *testReturnError = nil;
-
- beforeEach(^{
- [OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) {
- return [request.URL.host isEqualToString:@"www.faketest.com"];
- } withStubResponse:^OHHTTPStubsResponse *(NSURLRequest *request) {
- return [[OHHTTPStubsResponse responseWithData:testData statusCode:200 headers:nil] requestTime:0.5 responseTime:0];
- }];
-
- testSession = [[SDLURLSession alloc] init];
- [testSession dataFromURL:[NSURL URLWithString:@"http://www.faketest.com"] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
- testReturnData = data;
- testReturnResponse = response;
- testReturnError = error;
- }];
+ [testSession uploadWithURLRequest:someURLRequest data:testJSONData completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {}];
});
afterEach(^{
@@ -91,16 +121,8 @@ describe(@"the url session", ^{
[OHHTTPStubs removeAllStubs];
});
- it(@"should not return any data", ^{
- expect(testReturnData).toEventually(equal(testData));
- });
-
- it(@"should return a response", ^{
- expect(testReturnResponse).toEventuallyNot(beNil());
- });
-
- it(@"should not return an error", ^{
- expect(testReturnError).toEventually(beNil());
+ it(@"should have called the HTTPS URL instead", ^{
+ expect(testURLRequestComponent).toEventually(match(@"https"));
});
});
});
@@ -134,13 +156,7 @@ describe(@"the url session", ^{
it(@"should return nil data", ^{
expect(testReturnData).toEventually(beNil());
- });
-
- it(@"should return a nil response", ^{
expect(testReturnResponse).toEventually(beNil());
- });
-
- it(@"should return an error", ^{
expect(@(testReturnError.code)).toEventually(equal(@(someNetworkError.code)));
});
});
@@ -176,13 +192,7 @@ describe(@"the url session", ^{
it(@"should return nil data", ^{
expect(testReturnData).toEventually(beNil());
- });
-
- it(@"should return a nil response", ^{
expect(testReturnResponse).toEventually(beNil());
- });
-
- it(@"should return an error", ^{
expect(@(testReturnError.code)).toEventually(equal(@(kCFURLErrorCancelled)));
});
});