Skip to content

Commit 6124d39

Browse files
dsp1589dhanax
andauthored
#1566 Bugfix/twitter cancel continue app crash (#1567)
* Looking for Oauth and denied params * updated test cases and removed 'and' condition for successful redirection(made or to check for 'oauth_verifier' or 'oauth_token' * Update Gemfile.lock reverting gemlock Co-authored-by: dhana <[email protected]>
1 parent 9d1b958 commit 6124d39

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

ParseTwitterUtils/ParseTwitterUtils/Internal/Dialog/PFOAuth1FlowDialog.m

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,21 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati
414414
NSURL *url = navigationAction.request.URL;
415415
BOOL hasPrefix = [url.absoluteString hasPrefix:self.redirectURLPrefix];
416416
if (hasPrefix) {
417-
[self _dismissWithSuccess:YES url:url error:nil];
417+
NSURLComponents* components = [[NSURLComponents alloc] initWithString:url.absoluteString];
418+
NSArray<NSURLQueryItem *> * items = components.queryItems;
419+
if (items) {
420+
for (NSURLQueryItem * queryItem in items) {
421+
if ([queryItem.name isEqualToString:@"denied"]) {
422+
[self _dismissWithSuccess:NO url:url error:nil];
423+
break;
424+
} else if ([queryItem.name isEqualToString:@"oauth_verifier"] || [queryItem.name isEqualToString:@"oauth_token" ]) {
425+
[self _dismissWithSuccess:YES url:url error:nil];
426+
break;;
427+
}
428+
}
429+
} else {
430+
[self _dismissWithSuccess:NO url:url error:nil];
431+
}
418432
decisionHandler(WKNavigationActionPolicyCancel);
419433
return;
420434
} else if (navigationAction.navigationType == UIWebViewNavigationTypeLinkClicked && [self.dataSource dialog:self shouldOpenURLInExternalBrowser:url]) {

ParseTwitterUtils/Tests/Unit/OAuth1FlowDialogTests.m

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ - (void)skip_testRotation {
127127

128128
- (void)testWebViewDelegate {
129129
NSURL *sampleURL = [NSURL URLWithString:@"http://foo.bar"];
130-
NSURL *successURL = [NSURL URLWithString:@"foo://success"];
130+
NSURL *successURL = [NSURL URLWithString:@"foo://success/?oauth_verifier=abcd&oauth_token=authtoken123"];
131+
NSURL *rejectedURL = [NSURL URLWithString:@"foo://success/?denied=authtoken123"];
131132

132133
//XCTestExpectation *flowExpectation = [[XCTestExpectation alloc] initWithDescription: @"Waiting for redirect"];
133134
XCTestExpectation *flowExpectation = [self currentSelectorTestExpectation];
@@ -172,7 +173,22 @@ - (void)testWebViewDelegate {
172173
[canceledExpectation fulfill];
173174
}];
174175

175-
[self waitForExpectations:@[policyExpectation, flowExpectation, canceledExpectation] timeout:20];
176+
XCTestExpectation *canceledOnDeniedExpectation = [[XCTestExpectation alloc] initWithDescription:@"Waiting for canceled policy decision"];
177+
178+
WKNavigation* rejectNavigation = (WKNavigation *)([[NSObject alloc] init]);
179+
[flowDialog webView:webView didStartProvisionalNavigation:rejectNavigation];
180+
[flowDialog webView:webView didFinishNavigation:rejectNavigation];
181+
182+
FakeWKNavigationAction *rejectAction = [[FakeWKNavigationAction alloc] init];
183+
rejectAction.navigationType = WKNavigationTypeOther;
184+
rejectAction.request = [NSURLRequest requestWithURL:rejectedURL];
185+
186+
[flowDialog webView:webView decidePolicyForNavigationAction:rejectAction decisionHandler:^(WKNavigationActionPolicy policy) {
187+
XCTAssertTrue(policy == WKNavigationActionPolicyCancel);
188+
[canceledOnDeniedExpectation fulfill];
189+
}];
190+
191+
[self waitForExpectations:@[policyExpectation, flowExpectation, canceledExpectation, canceledOnDeniedExpectation] timeout:20];
176192
}
177193

178194
@end

0 commit comments

Comments
 (0)