Skip to content

Commit

Permalink
Merge pull request #143 from auth0/webauth-browser-fix
Browse files Browse the repository at this point in the history
Fix NPE when browser re-attempts a finished authentication
  • Loading branch information
lbalmaceda committed Feb 1, 2018
2 parents 69a5809 + 4736ef2 commit 90b9a19
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
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

0 comments on commit 90b9a19

Please sign in to comment.