From d7a6b066a56a1bbff18a1b1850d31c6bcb59438d Mon Sep 17 00:00:00 2001 From: Luciano Balmaceda Date: Mon, 8 Aug 2016 15:20:36 -0300 Subject: [PATCH] let the user accept/cancel the terms before signing up --- .../com/auth0/android/lock/Configuration.java | 6 + .../java/com/auth0/android/lock/Lock.java | 12 ++ .../java/com/auth0/android/lock/Options.java | 11 + .../android/lock/views/ClassicLockView.java | 56 +++-- lib/src/main/res/values/strings.xml | 5 +- .../auth0/android/lock/ConfigurationTest.java | 8 + .../com/auth0/android/lock/OptionsTest.java | 196 ++++++++---------- 7 files changed, 161 insertions(+), 133 deletions(-) diff --git a/lib/src/main/java/com/auth0/android/lock/Configuration.java b/lib/src/main/java/com/auth0/android/lock/Configuration.java index 69505467a..8fbb7ec41 100644 --- a/lib/src/main/java/com/auth0/android/lock/Configuration.java +++ b/lib/src/main/java/com/auth0/android/lock/Configuration.java @@ -71,6 +71,7 @@ public class Configuration { private boolean allowSignUp; private boolean allowForgotPassword; private boolean usernameRequired; + private boolean mustAcceptTerms; @PasswordStrength private int passwordPolicy; private final boolean classicLockAvailable; @@ -249,6 +250,7 @@ private void parseLocalOptions(Options options) { usernameStyle = options.usernameStyle(); socialButtonStyle = options.socialButtonStyle(); loginAfterSignUp = options.loginAfterSignUp(); + mustAcceptTerms = options.mustAcceptTerms(); final boolean socialAvailable = !getSocialStrategies().isEmpty(); final boolean dbAvailable = getDefaultDatabaseConnection() != null; @@ -413,4 +415,8 @@ public String getTermsURL() { public String getPrivacyURL() { return privacyURL; } + + public boolean mustAcceptTerms() { + return mustAcceptTerms; + } } \ No newline at end of file diff --git a/lib/src/main/java/com/auth0/android/lock/Lock.java b/lib/src/main/java/com/auth0/android/lock/Lock.java index 9daaabb8a..81088d79f 100644 --- a/lib/src/main/java/com/auth0/android/lock/Lock.java +++ b/lib/src/main/java/com/auth0/android/lock/Lock.java @@ -430,6 +430,18 @@ public Builder setTermsURL(@NonNull String url) { return this; } + /** + * Prompts the user to accept the Privacy Policy and Terms of Service before signing up. + * The default value is false. + * + * @param mustAcceptTerms whether the user needs to accept the terms before sign up or not. + * @return the current builder instance + */ + public Builder setMustAcceptTerms(boolean mustAcceptTerms) { + options.setMustAcceptTerms(mustAcceptTerms); + return this; + } + private List removeDuplicatedKeys(List customFields) { int originalSize = customFields.size(); final List withoutDuplicates = new ArrayList<>(); diff --git a/lib/src/main/java/com/auth0/android/lock/Options.java b/lib/src/main/java/com/auth0/android/lock/Options.java index 8fc15eb68..f8ace42aa 100644 --- a/lib/src/main/java/com/auth0/android/lock/Options.java +++ b/lib/src/main/java/com/auth0/android/lock/Options.java @@ -60,6 +60,7 @@ class Options implements Parcelable { private boolean allowSignUp; private boolean allowForgotPassword; private boolean loginAfterSignUp; + private boolean mustAcceptTerms; private String defaultDatabaseConnection; private List connections; private List enterpriseConnectionsUsingWebForm; @@ -94,6 +95,7 @@ protected Options(Parcel in) { allowSignUp = in.readByte() != WITHOUT_DATA; allowForgotPassword = in.readByte() != WITHOUT_DATA; loginAfterSignUp = in.readByte() != WITHOUT_DATA; + mustAcceptTerms = in.readByte() != WITHOUT_DATA; useCodePasswordless = in.readByte() != WITHOUT_DATA; defaultDatabaseConnection = in.readString(); usernameStyle = in.readInt(); @@ -144,6 +146,7 @@ public void writeToParcel(Parcel dest, int flags) { dest.writeByte((byte) (allowSignUp ? HAS_DATA : WITHOUT_DATA)); dest.writeByte((byte) (allowForgotPassword ? HAS_DATA : WITHOUT_DATA)); dest.writeByte((byte) (loginAfterSignUp ? HAS_DATA : WITHOUT_DATA)); + dest.writeByte((byte) (mustAcceptTerms ? HAS_DATA : WITHOUT_DATA)); dest.writeByte((byte) (useCodePasswordless ? HAS_DATA : WITHOUT_DATA)); dest.writeString(defaultDatabaseConnection); dest.writeInt(usernameStyle); @@ -372,4 +375,12 @@ public void setTermsURL(@NonNull String url) { public String getTermsURL() { return termsURL; } + + public void setMustAcceptTerms(boolean mustAcceptTerms) { + this.mustAcceptTerms = mustAcceptTerms; + } + + public boolean mustAcceptTerms() { + return mustAcceptTerms; + } } \ No newline at end of file diff --git a/lib/src/main/java/com/auth0/android/lock/views/ClassicLockView.java b/lib/src/main/java/com/auth0/android/lock/views/ClassicLockView.java index 2a1da62c3..73b239eb3 100644 --- a/lib/src/main/java/com/auth0/android/lock/views/ClassicLockView.java +++ b/lib/src/main/java/com/auth0/android/lock/views/ClassicLockView.java @@ -25,6 +25,7 @@ package com.auth0.android.lock.views; import android.content.Context; +import android.content.DialogInterface; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.StringRes; @@ -51,7 +52,7 @@ import com.auth0.android.lock.views.interfaces.LockWidgetForm; import com.squareup.otto.Bus; -public class ClassicLockView extends LinearLayout implements View.OnClickListener, LockWidgetForm { +public class ClassicLockView extends LinearLayout implements LockWidgetForm { private static final String TAG = ClassicLockView.class.getSimpleName(); private static final int FORM_INDEX = 2; @@ -114,14 +115,32 @@ private void showContentLayout() { bottomBanner.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - showSignUpTermsDialog(); + showSignUpTermsDialog(null); } }); bottomBanner.setVisibility(GONE); addView(bottomBanner, wrapHeightParams); actionButton = new ActionButton(getContext(), lockTheme); - actionButton.setOnClickListener(this); + actionButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + final Object event = subForm != null ? subForm.submitForm() : formLayout.onActionPressed(); + if (event == null) { + return; + } + if (!configuration.mustAcceptTerms() || !(event instanceof DatabaseSignUpEvent)) { + bus.post(event); + return; + } + showSignUpTermsDialog(new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + bus.post(event); + } + }); + } + }); addView(actionButton, wrapHeightParams); boolean showDatabase = configuration.getDefaultDatabaseConnection() != null; @@ -254,15 +273,26 @@ private void showSignUpTerms(boolean show) { bottomBanner.setVisibility(show ? VISIBLE : GONE); } - private void showSignUpTermsDialog() { + /** + * Create a dialog to show the Privacy Policy and Terms of Service text. + * If the provided callback it's not null, it will ask for acceptance. + * + * @param acceptCallback the callback to receive the acceptance. Can be null. + */ + private void showSignUpTermsDialog(@Nullable DialogInterface.OnClickListener acceptCallback) { final String content = String.format(getResources().getString(R.string.com_auth0_lock_sign_up_terms_dialog_message), configuration.getTermsURL(), configuration.getPrivacyURL()); - final AlertDialog dialog = new AlertDialog.Builder(getContext()) + final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()) .setTitle(getResources().getString(R.string.com_auth0_lock_sign_up_terms_dialog_title)) - .setPositiveButton(android.R.string.ok, null) - .setMessage(Html.fromHtml(content)) - .show(); + .setPositiveButton(R.string.com_auth0_lock_action_ok, null) + .setMessage(Html.fromHtml(content)); + if (acceptCallback != null) { + builder.setNegativeButton(R.string.com_auth0_lock_action_cancel, null) + .setPositiveButton(R.string.com_auth0_lock_action_accept, acceptCallback) + .setCancelable(false); + } - final TextView message = (TextView) dialog.findViewById(android.R.id.message); + //the dialog needs to be shown before we can get it's view. + final TextView message = (TextView) builder.show().findViewById(android.R.id.message); if (message != null) { message.setMovementMethod(LinkMovementMethod.getInstance()); } @@ -278,14 +308,6 @@ public void onFormSubmit() { actionButton.callOnClick(); } - @Override - public void onClick(View v) { - Object event = subForm != null ? subForm.submitForm() : formLayout.onActionPressed(); - if (event != null) { - bus.post(event); - } - } - @Override public void showCustomFieldsForm(DatabaseSignUpEvent event) { addSubForm(new CustomFieldsFormView(this, event.getEmail(), event.getPassword(), event.getUsername())); diff --git a/lib/src/main/res/values/strings.xml b/lib/src/main/res/values/strings.xml index ff0243835..484cdb337 100644 --- a/lib/src/main/res/values/strings.xml +++ b/lib/src/main/res/values/strings.xml @@ -91,6 +91,9 @@ Don\'t remember your password? Please enter your corporate credentials at %s Retry + Accept + Cancel + OK Single Sign On Enabled OR Otherwise, enter your phone to sign in or create an account @@ -112,7 +115,7 @@ terms of service and privacy policy ]]> - + There isn\'t any connection configured for this Application. Check your dashboard configuration on http://auth0.com Error retrieving the Dashboard configuration diff --git a/lib/src/test/java/com/auth0/android/lock/ConfigurationTest.java b/lib/src/test/java/com/auth0/android/lock/ConfigurationTest.java index 5dd6feecc..f904ec85d 100644 --- a/lib/src/test/java/com/auth0/android/lock/ConfigurationTest.java +++ b/lib/src/test/java/com/auth0/android/lock/ConfigurationTest.java @@ -115,6 +115,7 @@ public void shouldKeepApplicationDefaultsIfOptionsAreNotModified() throws Except assertThat(configuration.getSocialButtonStyle(), is(equalTo(SocialButtonStyle.UNSPECIFIED))); assertThat(configuration.hasExtraFields(), is(false)); assertThat(configuration.getPasswordPolicy(), is(PasswordStrength.NONE)); + assertThat(configuration.mustAcceptTerms(), is(false)); } @Test @@ -574,6 +575,13 @@ public void shouldHaveCustomTermsOfServiceURL() throws Exception { assertThat(configuration.getTermsURL(), is(equalTo("https://google.com/terms"))); } + @Test + public void shouldHaveMustAcceptTermsEnabled() throws Exception { + options.setMustAcceptTerms(true); + configuration = new Configuration(application, options); + assertThat(configuration.mustAcceptTerms(), is(true)); + } + private Configuration unfilteredConfig() { return new Configuration(application, options); } diff --git a/lib/src/test/java/com/auth0/android/lock/OptionsTest.java b/lib/src/test/java/com/auth0/android/lock/OptionsTest.java index 732d81d09..fa6d4c2e7 100644 --- a/lib/src/test/java/com/auth0/android/lock/OptionsTest.java +++ b/lib/src/test/java/com/auth0/android/lock/OptionsTest.java @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.List; +import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; @@ -42,15 +43,17 @@ public class OptionsTest { private static final String DEVICE_KEY = "device"; private static final String SCOPE_OPENID_OFFLINE_ACCESS = "openid offline_access"; - private Auth0 auth0; + private Options options; @Before public void setUp() throws Exception { - auth0 = new Auth0(CLIENT_ID, DOMAIN, CONFIG_DOMAIN); + options = new Options(); + options.setAccount(new Auth0(CLIENT_ID, DOMAIN, CONFIG_DOMAIN)); } @Test - public void shouldSetAccount() { + public void shouldSetAccount() throws Exception { + Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN, CONFIG_DOMAIN); Options options = new Options(); options.setAccount(auth0); @@ -65,9 +68,20 @@ public void shouldSetAccount() { } @Test - public void shouldSetPrivacyPolicyURL() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldSetMustAcceptTerms() throws Exception { + options.setMustAcceptTerms(true); + + Parcel parcel = Parcel.obtain(); + options.writeToParcel(parcel, 0); + parcel.setDataPosition(0); + + Options parceledOptions = Options.CREATOR.createFromParcel(parcel); + assertThat(options.mustAcceptTerms(), is(true)); + assertThat(options.mustAcceptTerms(), is(equalTo(parceledOptions.mustAcceptTerms()))); + } + + @Test + public void shouldSetPrivacyPolicyURL() throws Exception { options.setPrivacyURL("https://valid.url/privacy"); Parcel parcel = Parcel.obtain(); @@ -75,13 +89,12 @@ public void shouldSetPrivacyPolicyURL() { parcel.setDataPosition(0); Options parceledOptions = Options.CREATOR.createFromParcel(parcel); + assertThat(options.getPrivacyURL(), is(notNullValue())); assertThat(options.getPrivacyURL(), is(equalTo(parceledOptions.getPrivacyURL()))); } @Test - public void shouldNotSetPrivacyPolicyURLWhenInvalidURL() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldNotSetPrivacyPolicyURLWhenInvalidURL() throws Exception { options.setPrivacyURL("an-invalid/url"); Parcel parcel = Parcel.obtain(); @@ -94,9 +107,7 @@ public void shouldNotSetPrivacyPolicyURLWhenInvalidURL() { } @Test - public void shouldSetTermsOfServiceURL() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldSetTermsOfServiceURL() throws Exception { options.setTermsURL("https://valid.url/terms"); Parcel parcel = Parcel.obtain(); @@ -104,13 +115,12 @@ public void shouldSetTermsOfServiceURL() { parcel.setDataPosition(0); Options parceledOptions = Options.CREATOR.createFromParcel(parcel); + assertThat(options.getTermsURL(), is(notNullValue())); assertThat(options.getTermsURL(), is(equalTo(parceledOptions.getTermsURL()))); } @Test - public void shouldNotSetTermsOfServiceURLWhenInvalidURL() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldNotSetTermsOfServiceURLWhenInvalidURL() throws Exception { options.setTermsURL("an-invalid/url"); Parcel parcel = Parcel.obtain(); @@ -123,9 +133,7 @@ public void shouldNotSetTermsOfServiceURLWhenInvalidURL() { } @Test - public void shouldUseBrowser() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldUseBrowser() throws Exception { options.setUseBrowser(true); Parcel parcel = Parcel.obtain(); @@ -133,13 +141,12 @@ public void shouldUseBrowser() { parcel.setDataPosition(0); Options parceledOptions = Options.CREATOR.createFromParcel(parcel); + assertThat(options.useBrowser(), is(true)); assertThat(options.useBrowser(), is(equalTo(parceledOptions.useBrowser()))); } @Test - public void shouldUseBigSocialButtonStyle() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldUseBigSocialButtonStyle() throws Exception { options.setSocialButtonStyle(SocialButtonStyle.BIG); Parcel parcel = Parcel.obtain(); @@ -147,13 +154,12 @@ public void shouldUseBigSocialButtonStyle() { parcel.setDataPosition(0); Options parceledOptions = Options.CREATOR.createFromParcel(parcel); + assertThat(options.socialButtonStyle(), is(SocialButtonStyle.BIG)); assertThat(options.socialButtonStyle(), is(equalTo(parceledOptions.socialButtonStyle()))); } @Test - public void shouldUseSmallSocialButtonStyle() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldUseSmallSocialButtonStyle() throws Exception { options.setSocialButtonStyle(SocialButtonStyle.SMALL); Parcel parcel = Parcel.obtain(); @@ -161,27 +167,24 @@ public void shouldUseSmallSocialButtonStyle() { parcel.setDataPosition(0); Options parceledOptions = Options.CREATOR.createFromParcel(parcel); + assertThat(options.socialButtonStyle(), is(equalTo(SocialButtonStyle.SMALL))); assertThat(options.socialButtonStyle(), is(equalTo(parceledOptions.socialButtonStyle()))); } @Test - public void shouldHavePKCEEnabledByDefault() { - Options options = new Options(); - options.setAccount(auth0); - + public void shouldHavePKCEEnabledByDefault() throws Exception { Parcel parcel = Parcel.obtain(); options.writeToParcel(parcel, 0); parcel.setDataPosition(0); Options parceledOptions = Options.CREATOR.createFromParcel(parcel); + assertThat(options.usePKCE(), is(parceledOptions.usePKCE())); assertThat(options.usePKCE(), is(true)); assertThat(parceledOptions.usePKCE(), is(true)); } @Test - public void shouldEnablePKCE() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldEnablePKCE() throws Exception { options.setUsePKCE(true); Parcel parcel = Parcel.obtain(); @@ -189,14 +192,13 @@ public void shouldEnablePKCE() { parcel.setDataPosition(0); Options parceledOptions = Options.CREATOR.createFromParcel(parcel); + assertThat(options.usePKCE(), is(parceledOptions.usePKCE())); assertThat(options.usePKCE(), is(true)); assertThat(parceledOptions.usePKCE(), is(true)); } @Test - public void shouldDisablePKCE() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldDisablePKCE() throws Exception { options.setUsePKCE(false); Parcel parcel = Parcel.obtain(); @@ -204,14 +206,13 @@ public void shouldDisablePKCE() { parcel.setDataPosition(0); Options parceledOptions = Options.CREATOR.createFromParcel(parcel); + assertThat(options.usePKCE(), is(parceledOptions.usePKCE())); assertThat(options.usePKCE(), is(false)); assertThat(parceledOptions.usePKCE(), is(false)); } @Test - public void shouldBeClosable() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldBeClosable() throws Exception { options.setClosable(true); Parcel parcel = Parcel.obtain(); @@ -220,12 +221,11 @@ public void shouldBeClosable() { Options parceledOptions = Options.CREATOR.createFromParcel(parcel); assertThat(options.isClosable(), is(equalTo(parceledOptions.isClosable()))); + assertThat(options.isClosable(), is(true)); } @Test - public void shouldNotLoginAfterSignUp() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldNotLoginAfterSignUp() throws Exception { options.setLoginAfterSignUp(false); Parcel parcel = Parcel.obtain(); @@ -234,12 +234,11 @@ public void shouldNotLoginAfterSignUp() { Options parceledOptions = Options.CREATOR.createFromParcel(parcel); assertThat(options.loginAfterSignUp(), is(equalTo(parceledOptions.loginAfterSignUp()))); + assertThat(options.loginAfterSignUp(), is(false)); } @Test - public void shouldChangeInitialScreenToLogIn() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldChangeInitialScreenToLogIn() throws Exception { options.setInitialScreen(InitialScreen.LOG_IN); Parcel parcel = Parcel.obtain(); @@ -248,12 +247,11 @@ public void shouldChangeInitialScreenToLogIn() { Options parceledOptions = Options.CREATOR.createFromParcel(parcel); assertThat(options.initialScreen(), is(equalTo(parceledOptions.initialScreen()))); + assertThat(options.initialScreen(), is(InitialScreen.LOG_IN)); } @Test - public void shouldChangeInitialScreenToSignUp() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldChangeInitialScreenToSignUp() throws Exception { options.setInitialScreen(InitialScreen.SIGN_UP); Parcel parcel = Parcel.obtain(); @@ -262,12 +260,11 @@ public void shouldChangeInitialScreenToSignUp() { Options parceledOptions = Options.CREATOR.createFromParcel(parcel); assertThat(options.initialScreen(), is(equalTo(parceledOptions.initialScreen()))); + assertThat(options.initialScreen(), is(InitialScreen.SIGN_UP)); } @Test - public void shouldChangeInitialScreenToForgotPassword() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldChangeInitialScreenToForgotPassword() throws Exception { options.setInitialScreen(InitialScreen.FORGOT_PASSWORD); Parcel parcel = Parcel.obtain(); @@ -276,12 +273,11 @@ public void shouldChangeInitialScreenToForgotPassword() { Options parceledOptions = Options.CREATOR.createFromParcel(parcel); assertThat(options.initialScreen(), is(equalTo(parceledOptions.initialScreen()))); + assertThat(options.initialScreen(), is(InitialScreen.FORGOT_PASSWORD)); } @Test - public void shouldUseEmailUsernameStyle() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldUseEmailUsernameStyle() throws Exception { options.setUsernameStyle(UsernameStyle.EMAIL); Parcel parcel = Parcel.obtain(); @@ -290,12 +286,11 @@ public void shouldUseEmailUsernameStyle() { Options parceledOptions = Options.CREATOR.createFromParcel(parcel); assertThat(options.usernameStyle(), is(equalTo(parceledOptions.usernameStyle()))); + assertThat(options.usernameStyle(), is(UsernameStyle.EMAIL)); } @Test - public void shouldUseUsernameUsernameStyle() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldUseUsernameUsernameStyle() throws Exception { options.setUsernameStyle(UsernameStyle.USERNAME); Parcel parcel = Parcel.obtain(); @@ -304,12 +299,11 @@ public void shouldUseUsernameUsernameStyle() { Options parceledOptions = Options.CREATOR.createFromParcel(parcel); assertThat(options.usernameStyle(), is(equalTo(parceledOptions.usernameStyle()))); + assertThat(options.usernameStyle(), is(UsernameStyle.USERNAME)); } @Test - public void shouldUseDefaultUsernameStyle() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldUseDefaultUsernameStyle() throws Exception { options.setUsernameStyle(UsernameStyle.DEFAULT); Parcel parcel = Parcel.obtain(); @@ -318,12 +312,11 @@ public void shouldUseDefaultUsernameStyle() { Options parceledOptions = Options.CREATOR.createFromParcel(parcel); assertThat(options.usernameStyle(), is(equalTo(parceledOptions.usernameStyle()))); + assertThat(options.usernameStyle(), is(UsernameStyle.DEFAULT)); } @Test - public void shouldAllowLogIn() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldAllowLogIn() throws Exception { options.setAllowLogIn(true); Parcel parcel = Parcel.obtain(); @@ -332,12 +325,11 @@ public void shouldAllowLogIn() { Options parceledOptions = Options.CREATOR.createFromParcel(parcel); assertThat(options.allowLogIn(), is(equalTo(parceledOptions.allowLogIn()))); + assertThat(options.allowLogIn(), is(true)); } @Test - public void shouldAllowSignUp() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldAllowSignUp() throws Exception { options.setAllowSignUp(true); Parcel parcel = Parcel.obtain(); @@ -346,12 +338,11 @@ public void shouldAllowSignUp() { Options parceledOptions = Options.CREATOR.createFromParcel(parcel); assertThat(options.allowSignUp(), is(equalTo(parceledOptions.allowSignUp()))); + assertThat(options.allowSignUp(), is(true)); } @Test - public void shouldAllowForgotPassword() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldAllowForgotPassword() throws Exception { options.setAllowForgotPassword(true); Parcel parcel = Parcel.obtain(); @@ -360,12 +351,11 @@ public void shouldAllowForgotPassword() { Options parceledOptions = Options.CREATOR.createFromParcel(parcel); assertThat(options.allowForgotPassword(), is(equalTo(parceledOptions.allowForgotPassword()))); + assertThat(options.allowForgotPassword(), is(true)); } @Test - public void shouldUsePasswordlessCode() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldUsePasswordlessCode() throws Exception { options.setUseCodePasswordless(false); Parcel parcel = Parcel.obtain(); @@ -374,26 +364,23 @@ public void shouldUsePasswordlessCode() { Options parceledOptions = Options.CREATOR.createFromParcel(parcel); assertThat(options.useCodePasswordless(), is(equalTo(parceledOptions.useCodePasswordless()))); + assertThat(options.useCodePasswordless(), is(false)); } @Test - public void shouldHavePasswordlessCodeByDefault() { - Options options = new Options(); - options.setAccount(auth0); - + public void shouldHavePasswordlessCodeByDefault() throws Exception { Parcel parcel = Parcel.obtain(); options.writeToParcel(parcel, 0); parcel.setDataPosition(0); Options parceledOptions = Options.CREATOR.createFromParcel(parcel); + assertThat(options.useCodePasswordless(), is(equalTo(parceledOptions.useCodePasswordless()))); assertThat(options.useCodePasswordless(), is(true)); assertThat(parceledOptions.useCodePasswordless(), is(true)); } @Test - public void shouldSetDefaultDatabaseConnection() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldSetDefaultDatabaseConnection() throws Exception { options.useDatabaseConnection("default_db_connection"); Parcel parcel = Parcel.obtain(); @@ -402,13 +389,11 @@ public void shouldSetDefaultDatabaseConnection() { Options parceledOptions = Options.CREATOR.createFromParcel(parcel); assertThat(options.getDefaultDatabaseConnection(), is(equalTo(parceledOptions.getDefaultDatabaseConnection()))); + assertThat(options.getDefaultDatabaseConnection(), is("default_db_connection")); } @Test public void shouldSetDefaultTheme() { - Options options = new Options(); - options.setAccount(auth0); - Parcel parcel = Parcel.obtain(); options.writeToParcel(parcel, 0); parcel.setDataPosition(0); @@ -420,9 +405,7 @@ public void shouldSetDefaultTheme() { @Test - public void shouldSetCustomTheme() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldSetCustomTheme() throws Exception { Theme theme = Theme.newBuilder() .withHeaderTitle(R.string.com_auth0_lock_header_title) .withHeaderLogo(R.drawable.com_auth0_lock_header_logo) @@ -447,9 +430,7 @@ public void shouldSetCustomTheme() { } @Test - public void shouldSetConnections() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldSetConnections() throws Exception { options.setConnections(createConnections("twitter", "facebook")); Parcel parcel = Parcel.obtain(); @@ -457,14 +438,13 @@ public void shouldSetConnections() { parcel.setDataPosition(0); Options parceledOptions = Options.CREATOR.createFromParcel(parcel); + assertThat(options.getConnections(), is(containsInAnyOrder("twitter", "facebook"))); assertThat(options.getConnections(), is(equalTo(parceledOptions.getConnections()))); } @Test - public void shouldSetEnterpriseConnectionsUsingWebForm() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldSetEnterpriseConnectionsUsingWebForm() throws Exception { options.setEnterpriseConnectionsUsingWebForm(createEnterpriseConnectionsUsingWebForm("myAD")); Parcel parcel = Parcel.obtain(); @@ -472,13 +452,12 @@ public void shouldSetEnterpriseConnectionsUsingWebForm() { parcel.setDataPosition(0); Options parceledOptions = Options.CREATOR.createFromParcel(parcel); + assertThat(options.getEnterpriseConnectionsUsingWebForm(), containsInAnyOrder("myAD")); assertThat(options.getEnterpriseConnectionsUsingWebForm(), is(equalTo(parceledOptions.getEnterpriseConnectionsUsingWebForm()))); } @Test - public void shouldSetAuthenticationParameters() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldSetAuthenticationParameters() throws Exception { options.setAuthenticationParameters(createAuthenticationParameters(654123)); Parcel parcel = Parcel.obtain(); @@ -490,9 +469,7 @@ public void shouldSetAuthenticationParameters() { } @Test - public void shouldSetCustomFields() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldSetCustomFields() throws Exception { options.setCustomFields(createCustomFields()); Parcel parcel = Parcel.obtain(); @@ -509,10 +486,7 @@ public void shouldSetCustomFields() { } @Test - public void shouldGetEmptyCustomFieldsIfNotSet() { - Options options = new Options(); - options.setAccount(auth0); - + public void shouldGetEmptyCustomFieldsIfNotSet() throws Exception { Parcel parcel = Parcel.obtain(); options.writeToParcel(parcel, 0); parcel.setDataPosition(0); @@ -525,9 +499,7 @@ public void shouldGetEmptyCustomFieldsIfNotSet() { } @Test - public void shouldSetDeviceParameterIfUsingOfflineAccessScope() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldSetDeviceParameterIfUsingOfflineAccessScope() throws Exception { HashMap params = new HashMap<>(); params.put(SCOPE_KEY, SCOPE_OPENID_OFFLINE_ACCESS); options.setAuthenticationParameters(params); @@ -544,9 +516,7 @@ public void shouldSetDeviceParameterIfUsingOfflineAccessScope() { } @Test - public void shouldNotOverrideDeviceParameterIfAlreadySet() { - Options options = new Options(); - options.setAccount(auth0); + public void shouldNotOverrideDeviceParameterIfAlreadySet() throws Exception { HashMap params = new HashMap<>(); params.put(SCOPE_KEY, SCOPE_OPENID_OFFLINE_ACCESS); params.put(DEVICE_KEY, "my_device 2016"); @@ -564,10 +534,7 @@ public void shouldNotOverrideDeviceParameterIfAlreadySet() { } @Test - public void shouldSetDefaultValues() { - Options options = new Options(); - options.setAccount(auth0); - + public void shouldSetDefaultValues() throws Exception { Parcel parcel = Parcel.obtain(); options.writeToParcel(parcel, 0); parcel.setDataPosition(0); @@ -581,6 +548,7 @@ public void shouldSetDefaultValues() { assertThat(options.allowForgotPassword(), is(true)); assertThat(options.loginAfterSignUp(), is(true)); assertThat(options.useCodePasswordless(), is(true)); + assertThat(options.mustAcceptTerms(), is(false)); assertThat(options.usernameStyle(), is(equalTo(UsernameStyle.DEFAULT))); assertThat(options.socialButtonStyle(), is(equalTo(SocialButtonStyle.UNSPECIFIED))); assertThat(options.getTheme(), is(notNullValue())); @@ -589,9 +557,6 @@ public void shouldSetDefaultValues() { @Test public void shouldSetAllTrueFields() throws Exception { - Options options = new Options(); - options.setAccount(auth0); - options.setUseBrowser(true); options.setUsePKCE(true); options.setUsernameStyle(UsernameStyle.EMAIL); @@ -600,6 +565,7 @@ public void shouldSetAllTrueFields() throws Exception { options.setAllowSignUp(true); options.setAllowForgotPassword(true); options.setClosable(true); + options.setMustAcceptTerms(true); options.setSocialButtonStyle(SocialButtonStyle.BIG); options.setLoginAfterSignUp(true); @@ -609,6 +575,7 @@ public void shouldSetAllTrueFields() throws Exception { parcel.setDataPosition(0); Options parceledOptions = Options.CREATOR.createFromParcel(parcel); + assertThat(options.mustAcceptTerms(), is(equalTo(parceledOptions.mustAcceptTerms()))); assertThat(options.isClosable(), is(equalTo(parceledOptions.isClosable()))); assertThat(options.useBrowser(), is(equalTo(parceledOptions.useBrowser()))); assertThat(options.usePKCE(), is(equalTo(parceledOptions.usePKCE()))); @@ -623,9 +590,6 @@ public void shouldSetAllTrueFields() throws Exception { @Test public void shouldSetAllFalseFields() throws Exception { - Options options = new Options(); - options.setAccount(auth0); - options.setClosable(false); options.setUseBrowser(false); options.setUsePKCE(false); @@ -634,6 +598,7 @@ public void shouldSetAllFalseFields() throws Exception { options.setAllowLogIn(false); options.setAllowSignUp(false); options.setAllowForgotPassword(false); + options.setMustAcceptTerms(false); options.setSocialButtonStyle(SocialButtonStyle.SMALL); options.setLoginAfterSignUp(false); @@ -643,6 +608,7 @@ public void shouldSetAllFalseFields() throws Exception { parcel.setDataPosition(0); Options parceledOptions = Options.CREATOR.createFromParcel(parcel); + assertThat(options.mustAcceptTerms(), is(equalTo(parceledOptions.mustAcceptTerms()))); assertThat(options.isClosable(), is(equalTo(parceledOptions.isClosable()))); assertThat(options.useBrowser(), is(equalTo(parceledOptions.useBrowser()))); assertThat(options.usePKCE(), is(equalTo(parceledOptions.usePKCE())));