Skip to content

Commit

Permalink
Merge pull request #155 from thepoofy/master
Browse files Browse the repository at this point in the history
Fix NPE caused by unset `productFlowPriority`
  • Loading branch information
thepoofy authored Feb 8, 2019
2 parents ea98364 + 6784fb5 commit a1cfbdb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public class LoginManager {
private final int requestCode;
private final LegacyUriRedirectHandler legacyUriRedirectHandler;

private Collection<SupportedAppType> productFlowPriority;
private ArrayList<SupportedAppType> productFlowPriority;
private boolean authCodeFlowEnabled = false;
@Deprecated
private boolean redirectForAuthorizationCode = false;
Expand Down Expand Up @@ -152,6 +152,7 @@ public LoginManager(
@NonNull LegacyUriRedirectHandler legacyUriRedirectHandler) {
this.accessTokenStorage = accessTokenStorage;
this.callback = loginCallback;
this.productFlowPriority = new ArrayList<>();
this.sessionConfiguration = configuration;
this.requestCode = requestCode;
this.legacyUriRedirectHandler = legacyUriRedirectHandler;
Expand All @@ -178,7 +179,7 @@ public void login(final @NonNull Activity activity) {
if (ssoDeeplink.isSupported(SsoDeeplink.FlowVersion.REDIRECT_TO_SDK)) {
Intent intent = LoginActivity.newIntent(
activity,
new ArrayList<>(productFlowPriority),
productFlowPriority,
sessionConfiguration,
ResponseType.TOKEN,
false,
Expand Down Expand Up @@ -372,7 +373,7 @@ public LoginManager setAuthCodeFlowEnabled(boolean authCodeFlowEnabled) {
* @return this instance of {@link LoginManager}.
*/
public LoginManager setProductFlowPriority(@NonNull Collection<SupportedAppType> productFlowPriority) {
this.productFlowPriority = productFlowPriority;
this.productFlowPriority = new ArrayList<>(productFlowPriority);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.uber.sdk.core.auth.Scope;
import com.uber.sdk.core.client.Session;
import com.uber.sdk.core.client.SessionConfiguration;
import edu.emory.mathcs.backport.java.util.Collections;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
Expand Down Expand Up @@ -155,7 +156,26 @@ public void login_withRedirectToSdkFlowSsoSupported_shouldLoginActivityWithSsoPa
verify(activity).startActivityForResult(intentCaptor.capture(), codeCaptor.capture());

final Intent resultIntent = intentCaptor.getValue();
validateLoginIntentFields(resultIntent, new ArrayList<SupportedAppType>(productPriority), sessionConfiguration,
validateLoginIntentFields(resultIntent, new ArrayList<>(productPriority), sessionConfiguration,
ResponseType.TOKEN, false, true, true);
assertThat(codeCaptor.getValue()).isEqualTo(REQUEST_CODE_LOGIN_DEFAULT);
}

@Test
public void login_withoutAppPriority_shouldLoginActivityWithSsoParams() {
when(ssoDeeplink.isSupported(REDIRECT_TO_SDK)).thenReturn(true);

loginManager.login(activity);

verify(ssoDeeplink).isSupported(REDIRECT_TO_SDK);

ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
ArgumentCaptor<Integer> codeCaptor = ArgumentCaptor.forClass(Integer.class);

verify(activity).startActivityForResult(intentCaptor.capture(), codeCaptor.capture());

final Intent resultIntent = intentCaptor.getValue();
validateLoginIntentFields(resultIntent, new ArrayList<SupportedAppType>(), sessionConfiguration,
ResponseType.TOKEN, false, true, true);
assertThat(codeCaptor.getValue()).isEqualTo(REQUEST_CODE_LOGIN_DEFAULT);
}
Expand Down Expand Up @@ -493,7 +513,7 @@ public void getSession_withoutAccessTokenOrToken_fails() {

private void validateLoginIntentFields(
@NonNull Intent loginIntent,
@NonNull ArrayList<SupportedAppType> expectedProductPriority,
@NonNull List<SupportedAppType> expectedProductPriority,
@NonNull SessionConfiguration expectedSessionConfiguration,
@NonNull ResponseType expectedResponseType,
boolean expectedForceWebview,
Expand All @@ -502,7 +522,7 @@ private void validateLoginIntentFields(
assertThat(loginIntent.getSerializableExtra(EXTRA_SESSION_CONFIGURATION)).isEqualTo(expectedSessionConfiguration);
assertThat(loginIntent.getSerializableExtra(EXTRA_RESPONSE_TYPE)).isEqualTo(expectedResponseType);
assertThat((ArrayList<SupportedAppType>) loginIntent.getSerializableExtra(EXTRA_PRODUCT_PRIORITY))
.hasSameElementsAs(expectedProductPriority);
.containsAll(expectedProductPriority);
assertThat(loginIntent.getBooleanExtra(EXTRA_FORCE_WEBVIEW, false)).isEqualTo(expectedForceWebview);
assertThat(loginIntent.getBooleanExtra(EXTRA_SSO_ENABLED, false)).isEqualTo(expectedSsoEnabled);
assertThat(loginIntent.getBooleanExtra(EXTRA_REDIRECT_TO_PLAY_STORE_ENABLED, false))
Expand Down

0 comments on commit a1cfbdb

Please sign in to comment.