Skip to content

Support bot protection #589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 24, 2020
Merged

Support bot protection #589

merged 3 commits into from
Aug 24, 2020

Conversation

lbalmaceda
Copy link
Contributor

@lbalmaceda lbalmaceda commented Aug 21, 2020

Changes

When a request is flagged as suspicious by the Bot Protection feature, it will require the user to complete the authentication on a web-based flow. When this error code happens on Lock, the browser will be automatically launched on the right page (login/signup).

References

https://auth0.com/docs/anomaly-detection/bot-protection

Testing

Added unit tests for the event handling. I've also manually tested sign in, sign up and log in.

  • This change adds unit test coverage

  • This change adds integration/UI test coverage

  • This change has been tested on the latest version of the platform/language or why not

Checklist

@lbalmaceda lbalmaceda added CH: Added medium Medium review labels Aug 21, 2020
@lbalmaceda lbalmaceda requested a review from a team August 21, 2020 21:37
@@ -36,6 +36,10 @@ android {
testOptions {
unitTests {
includeAndroidResources = true
// https://github.com/robolectric/robolectric/issues/5115
all {
systemProperty("javax.net.ssl.trustStoreType", "JKS")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required to be set before MockServer can be instantiated. See the referenced issue for details.

@@ -120,6 +122,9 @@ public LockActivity() {
this.options = options;
this.lockView = lockView;
this.webProvider = webProvider;
this.handler = new Handler();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are only used in tests. In absolutely NO scenario Android will instantiate the LockActivity through this constructor, so it's safe to use.

@@ -372,6 +377,27 @@ public void onOAuthAuthenticationRequest(OAuthLoginEvent event) {
webProvider.start(this, connection, extraAuthParameters, authProviderCallback, WEB_AUTH_REQUEST_CODE);
}

private void completeDatabaseAuthenticationOnBrowser() {
//DBConnection checked for nullability before the API call
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is called from a callback#onFailure. The action that registered the callback already checked for nullability, see https://github.com/auth0/Lock.Android/pull/589/files#diff-01fe7e862df1aaab8f18b1b31542c58fR404-R406.

String screenHint = null;
if (lastDatabaseSignUp != null) {
loginHint = lastDatabaseSignUp.getEmail();
screenHint = "signup";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought of using constants for these, but they are only being used here, once.

when(options.getAudience()).thenReturn("aud");
when(options.getAuthenticationParameters()).thenReturn(basicParameters);
//set sign in behavior
when(options.loginAfterSignUp()).thenReturn(true);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the important line

when(options.getAudience()).thenReturn("aud");
when(options.getAuthenticationParameters()).thenReturn(basicParameters);
//set create user behavior
when(options.loginAfterSignUp()).thenReturn(false);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the important line

@@ -416,7 +540,7 @@ public void shouldCallOAuthAuthenticationWithCustomProvider() {
verify(lockView, never()).showProgress(true);
verify(customProvider).setParameters(mapCaptor.capture());
verify(customProvider).start(eq(activity), any(AuthCallback.class), eq(REQ_CODE_PERMISSIONS), eq(REQ_CODE_CUSTOM_PROVIDER));
AuthResolver.setAuthHandlers(Collections.emptyList());
AuthResolver.setAuthHandlers(Collections.<AuthHandler>emptyList());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these were required after fixing the wrong class import

import java.util.HashMap;
import java.util.Map;

import edu.emory.mathcs.backport.java.util.Collections;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incorrect class, omg.

- run: ./gradlew clean test --continue --console=plain --max-workers=4
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

limited the number of workers to avoid OOM issues

// https://github.com/robolectric/robolectric/issues/5115
all {
systemProperty("javax.net.ssl.trustStoreType", "JKS")
maxHeapSize = "1024m"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are independent of the JVM options passed in the command line (see CI script)

@lbalmaceda lbalmaceda merged commit 618fffa into master Aug 24, 2020
@lbalmaceda lbalmaceda deleted the feat-botprot branch August 24, 2020 22:11
@lbalmaceda lbalmaceda modified the milestones: v2-Next, v2.22.0 Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CH: Added medium Medium review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants