From 4594bc95a98671cef51174755e31e695218592f1 Mon Sep 17 00:00:00 2001 From: dhana Date: Fri, 23 Oct 2020 12:13:25 +0530 Subject: [PATCH 1/3] Looking for Oauth and denied params --- .../Internal/Dialog/PFOAuth1FlowDialog.m | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ParseTwitterUtils/ParseTwitterUtils/Internal/Dialog/PFOAuth1FlowDialog.m b/ParseTwitterUtils/ParseTwitterUtils/Internal/Dialog/PFOAuth1FlowDialog.m index 75702d357..7ab0f7642 100644 --- a/ParseTwitterUtils/ParseTwitterUtils/Internal/Dialog/PFOAuth1FlowDialog.m +++ b/ParseTwitterUtils/ParseTwitterUtils/Internal/Dialog/PFOAuth1FlowDialog.m @@ -414,7 +414,21 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati NSURL *url = navigationAction.request.URL; BOOL hasPrefix = [url.absoluteString hasPrefix:self.redirectURLPrefix]; if (hasPrefix) { - [self _dismissWithSuccess:YES url:url error:nil]; + NSURLComponents* components = [[NSURLComponents alloc] initWithString:url.absoluteString]; + NSArray * items = components.queryItems; + if (items) { + for (NSURLQueryItem * queryItem in items) { + if ([queryItem.name isEqualToString:@"denied"]) { + [self _dismissWithSuccess:NO url:url error:nil]; + break; + } else if ([queryItem.name isEqualToString:@"oauth_verifier"] && [queryItem.name isEqualToString:@"oauth_token" ]) { + [self _dismissWithSuccess:YES url:url error:nil]; + break;; + } + } + } else { + [self _dismissWithSuccess:NO url:url error:nil]; + } decisionHandler(WKNavigationActionPolicyCancel); return; } else if (navigationAction.navigationType == UIWebViewNavigationTypeLinkClicked && [self.dataSource dialog:self shouldOpenURLInExternalBrowser:url]) { From 153fec799995ff476d87b71cfcd36a6f2682914a Mon Sep 17 00:00:00 2001 From: dsp1589 Date: Fri, 23 Oct 2020 14:26:57 +0530 Subject: [PATCH 2/3] updated test cases and removed 'and' condition for successful redirection(made or to check for 'oauth_verifier' or 'oauth_token' --- Gemfile.lock | 37 ++++++++++--------- .../Internal/Dialog/PFOAuth1FlowDialog.m | 4 +- .../Tests/Unit/OAuth1FlowDialogTests.m | 20 +++++++++- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 84ceeec8c..fe7ebd8e6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,25 +2,26 @@ GEM remote: https://rubygems.org/ specs: CFPropertyList (3.0.2) - activesupport (4.2.11.3) - i18n (~> 0.7) + activesupport (5.2.4.4) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - algoliasearch (1.27.3) + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) + algoliasearch (1.27.4) httpclient (~> 2.8, >= 2.8.3) json (>= 1.5.1) atomos (0.1.3) claide (1.0.3) - cocoapods (1.9.3) - activesupport (>= 4.0.2, < 5) + cocoapods (1.10.0) + addressable (~> 2.6) claide (>= 1.0.2, < 2.0) - cocoapods-core (= 1.9.3) + cocoapods-core (= 1.10.0) cocoapods-deintegrate (>= 1.0.3, < 2.0) - cocoapods-downloader (>= 1.2.2, < 2.0) + cocoapods-downloader (>= 1.4.0, < 2.0) cocoapods-plugins (>= 1.0.0, < 2.0) cocoapods-search (>= 1.0.0, < 2.0) - cocoapods-stats (>= 1.0.0, < 2.0) cocoapods-trunk (>= 1.4.0, < 2.0) cocoapods-try (>= 1.1.0, < 2.0) colored2 (~> 3.1) @@ -30,27 +31,28 @@ GEM molinillo (~> 0.6.6) nap (~> 1.0) ruby-macho (~> 1.4) - xcodeproj (>= 1.14.0, < 2.0) - cocoapods-core (1.9.3) - activesupport (>= 4.0.2, < 6) + xcodeproj (>= 1.19.0, < 2.0) + cocoapods-core (1.10.0) + activesupport (> 5.0, < 6) + addressable (~> 2.6) algoliasearch (~> 1.0) concurrent-ruby (~> 1.1) fuzzy_match (~> 2.0.4) nap (~> 1.0) netrc (~> 0.11) + public_suffix typhoeus (~> 1.0) cocoapods-deintegrate (1.0.4) cocoapods-downloader (1.4.0) cocoapods-plugins (1.0.0) nap cocoapods-search (1.0.0) - cocoapods-stats (1.1.0) cocoapods-trunk (1.5.0) nap (>= 0.8, < 2.0) netrc (~> 0.11) cocoapods-try (1.2.0) colored2 (3.1.2) - concurrent-ruby (1.1.6) + concurrent-ruby (1.1.7) escape (0.0.4) ethon (0.12.0) ffi (>= 1.3.0) @@ -59,7 +61,7 @@ GEM fuzzy_match (2.0.4) gh_inspector (1.1.3) httpclient (2.8.3) - i18n (0.9.5) + i18n (1.8.5) concurrent-ruby (~> 1.0) jazzy (0.13.5) cocoapods (~> 1.5) @@ -72,7 +74,7 @@ GEM xcinvoke (~> 0.3.0) json (2.3.1) liferaft (0.0.6) - minitest (5.14.1) + minitest (5.14.2) molinillo (0.6.6) mustache (1.1.1) nanaimo (0.3.0) @@ -81,6 +83,7 @@ GEM netrc (0.11.0) open4 (1.3.4) plist (3.5.0) + public_suffix (4.0.6) rake (13.0.1) redcarpet (3.5.0) rouge (2.0.7) @@ -95,7 +98,7 @@ GEM thread_safe (~> 0.1) xcinvoke (0.3.0) liferaft (~> 0.0.6) - xcodeproj (1.17.1) + xcodeproj (1.19.0) CFPropertyList (>= 2.3.3, < 4.0) atomos (~> 0.1.3) claide (>= 1.0.2, < 2.0) diff --git a/ParseTwitterUtils/ParseTwitterUtils/Internal/Dialog/PFOAuth1FlowDialog.m b/ParseTwitterUtils/ParseTwitterUtils/Internal/Dialog/PFOAuth1FlowDialog.m index 7ab0f7642..0c66597a1 100644 --- a/ParseTwitterUtils/ParseTwitterUtils/Internal/Dialog/PFOAuth1FlowDialog.m +++ b/ParseTwitterUtils/ParseTwitterUtils/Internal/Dialog/PFOAuth1FlowDialog.m @@ -415,13 +415,13 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati BOOL hasPrefix = [url.absoluteString hasPrefix:self.redirectURLPrefix]; if (hasPrefix) { NSURLComponents* components = [[NSURLComponents alloc] initWithString:url.absoluteString]; - NSArray * items = components.queryItems; + NSArray * items = components.queryItems; if (items) { for (NSURLQueryItem * queryItem in items) { if ([queryItem.name isEqualToString:@"denied"]) { [self _dismissWithSuccess:NO url:url error:nil]; break; - } else if ([queryItem.name isEqualToString:@"oauth_verifier"] && [queryItem.name isEqualToString:@"oauth_token" ]) { + } else if ([queryItem.name isEqualToString:@"oauth_verifier"] || [queryItem.name isEqualToString:@"oauth_token" ]) { [self _dismissWithSuccess:YES url:url error:nil]; break;; } diff --git a/ParseTwitterUtils/Tests/Unit/OAuth1FlowDialogTests.m b/ParseTwitterUtils/Tests/Unit/OAuth1FlowDialogTests.m index a3d7727f1..68d57dbf5 100644 --- a/ParseTwitterUtils/Tests/Unit/OAuth1FlowDialogTests.m +++ b/ParseTwitterUtils/Tests/Unit/OAuth1FlowDialogTests.m @@ -127,7 +127,8 @@ - (void)skip_testRotation { - (void)testWebViewDelegate { NSURL *sampleURL = [NSURL URLWithString:@"http://foo.bar"]; - NSURL *successURL = [NSURL URLWithString:@"foo://success"]; + NSURL *successURL = [NSURL URLWithString:@"foo://success/?oauth_verifier=abcd&oauth_token=authtoken123"]; + NSURL *rejectedURL = [NSURL URLWithString:@"foo://success/?denied=authtoken123"]; //XCTestExpectation *flowExpectation = [[XCTestExpectation alloc] initWithDescription: @"Waiting for redirect"]; XCTestExpectation *flowExpectation = [self currentSelectorTestExpectation]; @@ -172,7 +173,22 @@ - (void)testWebViewDelegate { [canceledExpectation fulfill]; }]; - [self waitForExpectations:@[policyExpectation, flowExpectation, canceledExpectation] timeout:20]; + XCTestExpectation *canceledOnDeniedExpectation = [[XCTestExpectation alloc] initWithDescription:@"Waiting for canceled policy decision"]; + + WKNavigation* rejectNavigation = (WKNavigation *)([[NSObject alloc] init]); + [flowDialog webView:webView didStartProvisionalNavigation:rejectNavigation]; + [flowDialog webView:webView didFinishNavigation:rejectNavigation]; + + FakeWKNavigationAction *rejectAction = [[FakeWKNavigationAction alloc] init]; + rejectAction.navigationType = WKNavigationTypeOther; + rejectAction.request = [NSURLRequest requestWithURL:rejectedURL]; + + [flowDialog webView:webView decidePolicyForNavigationAction:rejectAction decisionHandler:^(WKNavigationActionPolicy policy) { + XCTAssertTrue(policy == WKNavigationActionPolicyCancel); + [canceledOnDeniedExpectation fulfill]; + }]; + + [self waitForExpectations:@[policyExpectation, flowExpectation, canceledExpectation, canceledOnDeniedExpectation] timeout:20]; } @end From 1089ad6b67a73abbdb9ad780f687f947a88fc087 Mon Sep 17 00:00:00 2001 From: dsp1589 Date: Fri, 23 Oct 2020 17:14:08 +0530 Subject: [PATCH 3/3] Update Gemfile.lock reverting gemlock --- Gemfile.lock | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index fe7ebd8e6..84ceeec8c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,26 +2,25 @@ GEM remote: https://rubygems.org/ specs: CFPropertyList (3.0.2) - activesupport (5.2.4.4) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) + activesupport (4.2.11.3) + i18n (~> 0.7) minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) - algoliasearch (1.27.4) + algoliasearch (1.27.3) httpclient (~> 2.8, >= 2.8.3) json (>= 1.5.1) atomos (0.1.3) claide (1.0.3) - cocoapods (1.10.0) - addressable (~> 2.6) + cocoapods (1.9.3) + activesupport (>= 4.0.2, < 5) claide (>= 1.0.2, < 2.0) - cocoapods-core (= 1.10.0) + cocoapods-core (= 1.9.3) cocoapods-deintegrate (>= 1.0.3, < 2.0) - cocoapods-downloader (>= 1.4.0, < 2.0) + cocoapods-downloader (>= 1.2.2, < 2.0) cocoapods-plugins (>= 1.0.0, < 2.0) cocoapods-search (>= 1.0.0, < 2.0) + cocoapods-stats (>= 1.0.0, < 2.0) cocoapods-trunk (>= 1.4.0, < 2.0) cocoapods-try (>= 1.1.0, < 2.0) colored2 (~> 3.1) @@ -31,28 +30,27 @@ GEM molinillo (~> 0.6.6) nap (~> 1.0) ruby-macho (~> 1.4) - xcodeproj (>= 1.19.0, < 2.0) - cocoapods-core (1.10.0) - activesupport (> 5.0, < 6) - addressable (~> 2.6) + xcodeproj (>= 1.14.0, < 2.0) + cocoapods-core (1.9.3) + activesupport (>= 4.0.2, < 6) algoliasearch (~> 1.0) concurrent-ruby (~> 1.1) fuzzy_match (~> 2.0.4) nap (~> 1.0) netrc (~> 0.11) - public_suffix typhoeus (~> 1.0) cocoapods-deintegrate (1.0.4) cocoapods-downloader (1.4.0) cocoapods-plugins (1.0.0) nap cocoapods-search (1.0.0) + cocoapods-stats (1.1.0) cocoapods-trunk (1.5.0) nap (>= 0.8, < 2.0) netrc (~> 0.11) cocoapods-try (1.2.0) colored2 (3.1.2) - concurrent-ruby (1.1.7) + concurrent-ruby (1.1.6) escape (0.0.4) ethon (0.12.0) ffi (>= 1.3.0) @@ -61,7 +59,7 @@ GEM fuzzy_match (2.0.4) gh_inspector (1.1.3) httpclient (2.8.3) - i18n (1.8.5) + i18n (0.9.5) concurrent-ruby (~> 1.0) jazzy (0.13.5) cocoapods (~> 1.5) @@ -74,7 +72,7 @@ GEM xcinvoke (~> 0.3.0) json (2.3.1) liferaft (0.0.6) - minitest (5.14.2) + minitest (5.14.1) molinillo (0.6.6) mustache (1.1.1) nanaimo (0.3.0) @@ -83,7 +81,6 @@ GEM netrc (0.11.0) open4 (1.3.4) plist (3.5.0) - public_suffix (4.0.6) rake (13.0.1) redcarpet (3.5.0) rouge (2.0.7) @@ -98,7 +95,7 @@ GEM thread_safe (~> 0.1) xcinvoke (0.3.0) liferaft (~> 0.0.6) - xcodeproj (1.19.0) + xcodeproj (1.17.1) CFPropertyList (>= 2.3.3, < 4.0) atomos (~> 0.1.3) claide (>= 1.0.2, < 2.0)