From 2a09c9ad379ba5fd29b99332740a53b29ab7051a Mon Sep 17 00:00:00 2001 From: Luciano Balmaceda Date: Wed, 18 Oct 2017 12:21:36 -0300 Subject: [PATCH] fix webauth tests --- .../auth0/android/lock/WebProviderTest.java | 73 +++++++++++-------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/lib/src/test/java/com/auth0/android/lock/WebProviderTest.java b/lib/src/test/java/com/auth0/android/lock/WebProviderTest.java index f5cbd0fa2..fe38a54a2 100644 --- a/lib/src/test/java/com/auth0/android/lock/WebProviderTest.java +++ b/lib/src/test/java/com/auth0/android/lock/WebProviderTest.java @@ -8,7 +8,6 @@ import com.auth0.android.lock.internal.configuration.Options; import com.auth0.android.provider.AuthCallback; import com.auth0.android.provider.AuthenticationActivity; -import com.auth0.android.provider.WebAuthActivity; import org.junit.Before; import org.junit.Rule; @@ -16,7 +15,6 @@ import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; -import org.mockito.Mock; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; @@ -24,7 +22,6 @@ import java.util.HashMap; import java.util.Map; -import static android.support.test.espresso.intent.matcher.IntentMatchers.hasAction; import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent; import static android.support.test.espresso.intent.matcher.UriMatchers.hasHost; import static android.support.test.espresso.intent.matcher.UriMatchers.hasParamWithValue; @@ -88,12 +85,15 @@ public void shouldStartWithCustomAuthenticationParameters() throws Exception { Intent intent = intentCaptor.getValue(); assertThat(intent, is(notNullValue())); - assertThat(intent.getData(), hasHost("domain.auth0.com")); - assertThat(intent.getData(), hasParamWithValue("custom-param-1", "value-1")); - assertThat(intent.getData(), hasParamWithValue("custom-param-2", "value-2")); - assertThat(intent.getData(), hasParamWithValue("client_id", "clientId")); - assertThat(intent.getData(), hasParamWithValue("connection", "my-connection")); - assertThat(intent.getData(), hasParamWithValue("audience", "https://me.auth0.com/myapi")); + + assertThat(intent.hasExtra("com.auth0.android.EXTRA_AUTHORIZE_URI"), is(true)); + Uri authorizeUri = intent.getParcelableExtra("com.auth0.android.EXTRA_AUTHORIZE_URI"); + assertThat(authorizeUri, hasHost("domain.auth0.com")); + assertThat(authorizeUri, hasParamWithValue("custom-param-1", "value-1")); + assertThat(authorizeUri, hasParamWithValue("custom-param-2", "value-2")); + assertThat(authorizeUri, hasParamWithValue("client_id", "clientId")); + assertThat(authorizeUri, hasParamWithValue("connection", "my-connection")); + assertThat(authorizeUri, hasParamWithValue("audience", "https://me.auth0.com/myapi")); assertThat(intent, hasComponent(AuthenticationActivity.class.getName())); } @@ -116,10 +116,13 @@ public void shouldStartWithCustomAudience() throws Exception { Intent intent = intentCaptor.getValue(); assertThat(intent, is(notNullValue())); - assertThat(intent.getData(), hasHost("domain.auth0.com")); - assertThat(intent.getData(), hasParamWithValue("client_id", "clientId")); - assertThat(intent.getData(), hasParamWithValue("connection", "my-connection")); - assertThat(intent.getData(), hasParamWithValue("audience", "https://me.auth0.com/myapi")); + + assertThat(intent.hasExtra("com.auth0.android.EXTRA_AUTHORIZE_URI"), is(true)); + Uri authorizeUri = intent.getParcelableExtra("com.auth0.android.EXTRA_AUTHORIZE_URI"); + assertThat(authorizeUri, hasHost("domain.auth0.com")); + assertThat(authorizeUri, hasParamWithValue("client_id", "clientId")); + assertThat(authorizeUri, hasParamWithValue("connection", "my-connection")); + assertThat(authorizeUri, hasParamWithValue("audience", "https://me.auth0.com/myapi")); assertThat(intent, hasComponent(AuthenticationActivity.class.getName())); } @@ -147,16 +150,20 @@ public void shouldStartBrowserWithOptions() throws Exception { Intent intent = intentCaptor.getValue(); assertThat(intent, is(notNullValue())); - assertThat(intent.getData().getQueryParameter("redirect_uri"), is(notNullValue())); - Uri redirectUri = Uri.parse(intent.getData().getQueryParameter("redirect_uri")); + assertThat(intent.hasExtra("com.auth0.android.EXTRA_AUTHORIZE_URI"), is(true)); + Uri authorizeUri = intent.getParcelableExtra("com.auth0.android.EXTRA_AUTHORIZE_URI"); + + assertThat(authorizeUri.getQueryParameter("redirect_uri"), is(notNullValue())); + Uri redirectUri = Uri.parse(authorizeUri.getQueryParameter("redirect_uri")); assertThat(redirectUri, hasScheme("auth0")); - assertThat(intent.getData(), hasHost("domain.auth0.com")); - assertThat(intent.getData(), hasParamWithValue("client_id", "clientId")); - assertThat(intent.getData(), hasParamWithValue("connection", "my-connection")); - assertThat(intent.getData(), hasParamWithValue("custom-param-1", "value-1")); - assertThat(intent.getData(), hasParamWithValue("custom-param-2", "value-2")); - assertThat(intent.getData(), hasParamWithValue("scope", "email profile photos")); - assertThat(intent.getData(), hasParamWithValue("connection_scope", "the connection scope")); + + assertThat(authorizeUri, hasHost("domain.auth0.com")); + assertThat(authorizeUri, hasParamWithValue("client_id", "clientId")); + assertThat(authorizeUri, hasParamWithValue("connection", "my-connection")); + assertThat(authorizeUri, hasParamWithValue("custom-param-1", "value-1")); + assertThat(authorizeUri, hasParamWithValue("custom-param-2", "value-2")); + assertThat(authorizeUri, hasParamWithValue("scope", "email profile photos")); + assertThat(authorizeUri, hasParamWithValue("connection_scope", "the connection scope")); assertThat(intent.hasExtra("com.auth0.android.EXTRA_USE_BROWSER"), is(true)); assertThat(intent.getBooleanExtra("com.auth0.android.EXTRA_USE_BROWSER", false), is(true)); assertThat(intent, hasComponent(AuthenticationActivity.class.getName())); @@ -186,16 +193,20 @@ public void shouldStartWebViewWithOptions() throws Exception { Intent intent = intentCaptor.getValue(); assertThat(intent, is(notNullValue())); - assertThat(intent.getData().getQueryParameter("redirect_uri"), is(notNullValue())); - Uri redirectUri = Uri.parse(intent.getData().getQueryParameter("redirect_uri")); + assertThat(intent.hasExtra("com.auth0.android.EXTRA_AUTHORIZE_URI"), is(true)); + Uri authorizeUri = intent.getParcelableExtra("com.auth0.android.EXTRA_AUTHORIZE_URI"); + + assertThat(authorizeUri.getQueryParameter("redirect_uri"), is(notNullValue())); + Uri redirectUri = Uri.parse(authorizeUri.getQueryParameter("redirect_uri")); assertThat(redirectUri, hasScheme("auth0")); - assertThat(intent.getData(), hasHost("domain.auth0.com")); - assertThat(intent.getData(), hasParamWithValue("client_id", "clientId")); - assertThat(intent.getData(), hasParamWithValue("connection", "my-connection")); - assertThat(intent.getData(), hasParamWithValue("custom-param-1", "value-1")); - assertThat(intent.getData(), hasParamWithValue("custom-param-2", "value-2")); - assertThat(intent.getData(), hasParamWithValue("scope", "email profile photos")); - assertThat(intent.getData(), hasParamWithValue("connection_scope", "the connection scope")); + + assertThat(authorizeUri, hasHost("domain.auth0.com")); + assertThat(authorizeUri, hasParamWithValue("client_id", "clientId")); + assertThat(authorizeUri, hasParamWithValue("connection", "my-connection")); + assertThat(authorizeUri, hasParamWithValue("custom-param-1", "value-1")); + assertThat(authorizeUri, hasParamWithValue("custom-param-2", "value-2")); + assertThat(authorizeUri, hasParamWithValue("scope", "email profile photos")); + assertThat(authorizeUri, hasParamWithValue("connection_scope", "the connection scope")); assertThat(intent.hasExtra("com.auth0.android.EXTRA_USE_BROWSER"), is(true)); assertThat(intent.getBooleanExtra("com.auth0.android.EXTRA_USE_BROWSER", true), is(false)); assertThat(intent, hasComponent(AuthenticationActivity.class.getName()));