Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE when browser re-attempts a finished authentication #143

Merged
merged 2 commits into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
@Override
protected void onResume() {
super.onResume();
if (!intentLaunched) {
if (!intentLaunched && getIntent().getExtras() == null) {
//Activity was launched in an unexpected way
finish();
return;
} else if (!intentLaunched) {
intentLaunched = true;
launchAuthenticationIntent();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ public void run() {
context.startActivity(intent);
} catch (ActivityNotFoundException ignored) {
Intent fallbackIntent = new Intent(Intent.ACTION_VIEW, uri);
fallbackIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
context.startActivity(fallbackIntent);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ private void createActivity(Intent configurationIntent) {
activityShadow = shadowOf(activity);
}

@SuppressWarnings("deprecation")
@Test
public void shouldFinishGracefullyWhenCalledByError() throws Exception {
Intent intent = new Intent(callerActivity, AuthenticationActivity.class);
//An invalid call will not pass any expected extras
createActivity(intent);

activityController.create().newIntent(intent).start().resume();

verifyNoMoreInteractions(customTabsController);
assertThat(activity.getDeliveredIntent(), is(nullValue()));
assertThat(activity.isFinishing(), is(true));

activityController.destroy();
}

@SuppressWarnings("deprecation")
@Test
public void shouldAuthenticateUsingBrowser() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public void shouldLaunchUriWithFallbackIfCustomTabIntentFails() throws Exception
Intent fallbackIntent = intents.get(1);
assertThat(fallbackIntent.getAction(), is(Intent.ACTION_VIEW));
assertThat(fallbackIntent.getData(), is(uri));
assertThat(fallbackIntent, hasFlag(Intent.FLAG_ACTIVITY_NO_HISTORY));
assertThat(fallbackIntent, not(hasFlag(Intent.FLAG_ACTIVITY_NO_HISTORY)));
assertThat(fallbackIntent.hasExtra(CustomTabsIntent.EXTRA_SESSION), is(false));
assertThat(fallbackIntent.hasExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE), is(false));
}
Expand Down