Skip to content

Commit

Permalink
fix webauth tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalmaceda committed Oct 18, 2017
1 parent de551ae commit 2a09c9a
Showing 1 changed file with 42 additions and 31 deletions.
73 changes: 42 additions & 31 deletions lib/src/test/java/com/auth0/android/lock/WebProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@
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;
import org.junit.Test;
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;

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;
Expand Down Expand Up @@ -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()));
}

Expand All @@ -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()));
}

Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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()));
Expand Down

0 comments on commit 2a09c9a

Please sign in to comment.