From 9ffdc5d2eb2a75cc61ece83cb9e3033733783803 Mon Sep 17 00:00:00 2001 From: Sefa Ilkimen Date: Mon, 3 Feb 2020 03:23:50 +0100 Subject: [PATCH 1/2] test: implement e2e test for #248 --- test/e2e-specs.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/e2e-specs.js b/test/e2e-specs.js index c11b244..dfe674d 100644 --- a/test/e2e-specs.js +++ b/test/e2e-specs.js @@ -464,7 +464,7 @@ const tests = [ } }, { - description: 'should not send any cookies after running "clearCookies" (GET) #59', + description: 'should not send programmatically set cookies after running "clearCookies" (GET) #59', expected: 'resolved: {"status": 200, "data": "{\"headers\": {\"Cookie\": \"\"...', func: function (resolve, reject) { cordova.plugin.http.setCookie('http://httpbin.org/get', 'myCookie=myValue'); @@ -946,6 +946,26 @@ const tests = [ }); } }, + { + only: true, + description: 'should not send any cookies after running "clearCookies" (GET) #248', + expected: 'resolved: {"status": 200, "data": "{\"cookies\":{}} ...', + before: helpers.disableFollowingRedirect, + func: function (resolve, reject) { + cordova.plugin.http.get('https://httpbin.org/cookies/set?myCookieKey=myCookieValue', {}, {}, function() { + cordova.plugin.http.clearCookies(); + cordova.plugin.http.get('https://httpbin.org/cookies', {}, {}, resolve, reject); + }, function() { + cordova.plugin.http.clearCookies(); + cordova.plugin.http.get('https://httpbin.org/cookies', {}, {}, resolve, reject); + }); + }, + validationFunc: function (driver, result) { + result.type.should.be.equal('resolved'); + result.data.status.should.be.equal(200); + JSON.parse(result.data.data).cookies.should.be.eql({}); + } + }, // TODO: not ready yet // { From 92be8f8e9656c05e898abcb0ed2e1d0b8444b56c Mon Sep 17 00:00:00 2001 From: Sefa Ilkimen Date: Mon, 3 Feb 2020 03:58:09 +0100 Subject: [PATCH 2/2] fix #248: clearCookies() does not work on iOS --- src/ios/AFNetworking/AFHTTPSessionManager.m | 8 ++++++++ test/e2e-specs.js | 1 - 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ios/AFNetworking/AFHTTPSessionManager.m b/src/ios/AFNetworking/AFHTTPSessionManager.m index 448983e..11467e3 100644 --- a/src/ios/AFNetworking/AFHTTPSessionManager.m +++ b/src/ios/AFNetworking/AFHTTPSessionManager.m @@ -184,6 +184,8 @@ { NSError *serializationError = nil; NSMutableURLRequest *request = [self.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters constructingBodyWithBlock:block error:&serializationError]; + [request setHTTPShouldHandleCookies:NO]; + if (serializationError) { if (failure) { dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{ @@ -232,6 +234,8 @@ { NSError *serializationError = nil; NSMutableURLRequest *request = [self.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters constructingBodyWithBlock:block error:&serializationError]; + [request setHTTPShouldHandleCookies:NO]; + if (serializationError) { if (failure) { dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{ @@ -293,6 +297,8 @@ { NSError *serializationError = nil; NSMutableURLRequest *request = [self.requestSerializer multipartFormRequestWithMethod:method URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters constructingBodyWithBlock:block error:&serializationError]; + [request setHTTPShouldHandleCookies:NO]; + if (serializationError) { if (failure) { dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{ @@ -358,6 +364,8 @@ { NSError *serializationError = nil; NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:method URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:&serializationError]; + [request setHTTPShouldHandleCookies:NO]; + if (serializationError) { if (failure) { dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{ diff --git a/test/e2e-specs.js b/test/e2e-specs.js index dfe674d..78923b9 100644 --- a/test/e2e-specs.js +++ b/test/e2e-specs.js @@ -947,7 +947,6 @@ const tests = [ } }, { - only: true, description: 'should not send any cookies after running "clearCookies" (GET) #248', expected: 'resolved: {"status": 200, "data": "{\"cookies\":{}} ...', before: helpers.disableFollowingRedirect,