Skip to content

Commit

Permalink
Merge pull request #250 from auth0/android-lint
Browse files Browse the repository at this point in the history
Update gradle android plugin and wrapper version
  • Loading branch information
damieng authored Jul 23, 2019
2 parents 4fe2b0b + e7bff70 commit 590a2bf
Show file tree
Hide file tree
Showing 56 changed files with 601 additions and 620 deletions.
2 changes: 1 addition & 1 deletion auth0/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ dependencies {
implementation 'com.squareup.okhttp:okhttp:2.7.5'
implementation 'com.squareup.okhttp:logging-interceptor:2.7.5'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.auth0.android:jwtdecode:1.1.1'
implementation 'com.auth0.android:jwtdecode:1.3.0'

testImplementation 'junit:junit:4.12'
testImplementation 'org.hamcrest:java-hamcrest:2.0.0.0'
Expand Down
3 changes: 3 additions & 0 deletions auth0/src/main/java/com/auth0/android/Auth0Exception.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
public class Auth0Exception extends RuntimeException {

public static final String UNKNOWN_ERROR = "a0.sdk.internal_error.unknown";
@SuppressWarnings("WeakerAccess")
public static final String NON_JSON_ERROR = "a0.sdk.internal_error.plain";
@SuppressWarnings("WeakerAccess")
public static final String EMPTY_BODY_ERROR = "a0.sdk.internal_error.empty";
@SuppressWarnings("WeakerAccess")
public static final String EMPTY_RESPONSE_BODY_DESCRIPTION = "Empty response body";

public Auth0Exception(String message, Throwable cause) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class AuthenticationActivity extends Activity {
static final String EXTRA_USE_FULL_SCREEN = "com.auth0.android.EXTRA_USE_FULL_SCREEN";
static final String EXTRA_CONNECTION_NAME = "com.auth0.android.EXTRA_CONNECTION_NAME";
static final String EXTRA_AUTHORIZE_URI = "com.auth0.android.EXTRA_AUTHORIZE_URI";
static final String EXTRA_INTENT_LAUNCHED = "com.auth0.android.EXTRA_INTENT_LAUNCHED";
static final String EXTRA_CT_OPTIONS = "com.auth0.android.EXTRA_CT_OPTIONS";
private static final String EXTRA_INTENT_LAUNCHED = "com.auth0.android.EXTRA_INTENT_LAUNCHED";

private boolean intentLaunched;
private CustomTabsController customTabsController;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.auth0.android.provider;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Parcel;
Expand Down Expand Up @@ -33,6 +34,7 @@ public static Builder newBuilder() {
}


@SuppressLint("ResourceType")
Intent toIntent(Context context, CustomTabsSession session) {
final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(session)
.setShowTitle(showTitle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package com.auth0.android.provider;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -83,15 +84,15 @@ protected void onCreate(Bundle savedInstanceState) {
bar.setDisplayShowCustomEnabled(true);
bar.setTitle(serviceName);
}
webView = (WebView) findViewById(R.id.com_auth0_lock_webview);
webView = findViewById(R.id.com_auth0_lock_webview);
webView.setVisibility(View.INVISIBLE);
progressBar = (ProgressBar) findViewById(R.id.com_auth0_lock_progressbar);
progressBar = findViewById(R.id.com_auth0_lock_progressbar);
progressBar.setIndeterminate(true);
progressBar.setMax(100);
errorView = findViewById(R.id.com_auth0_lock_error_view);
errorView.setVisibility(View.GONE);
errorMessage = (TextView) findViewById(R.id.com_auth0_lock_text);
Button retryButton = (Button) findViewById(R.id.com_auth0_lock_retry);
errorMessage = findViewById(R.id.com_auth0_lock_text);
Button retryButton = findViewById(R.id.com_auth0_lock_retry);
retryButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -112,6 +113,7 @@ public void onWindowFocusChanged(boolean hasFocus) {
}
}

@SuppressLint("SetJavaScriptEnabled")
private void startUrlLoading() {
if (!isNetworkAvailable()) {
renderLoadError(getString(R.string.com_auth0_webauth_network_error));
Expand Down Expand Up @@ -162,7 +164,6 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) {
progressBar.setVisibility(View.VISIBLE);
}

@SuppressWarnings("deprecation")
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.w(TAG, String.format("Load error (%d) %s", errorCode, description));
Expand Down Expand Up @@ -196,6 +197,7 @@ private boolean isNetworkAvailable() {
boolean available = true;
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
try {
@SuppressLint("MissingPermission")
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
available = activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
Log.v(TAG, "Is network available? " + available);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package com.auth0.android.provider;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
Expand Down Expand Up @@ -160,6 +161,7 @@ public static class Builder {
* @return the current builder instance
* @deprecated This method has been deprecated since it only applied to WebView authentication and Google is no longer supporting it. You should use the default value (use browser).
*/
@SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
public Builder useBrowser(boolean useBrowser) {
this.useBrowser = useBrowser;
Expand Down Expand Up @@ -342,6 +344,7 @@ Builder withPKCE(PKCE pkce) {
* @param requestCode to use in the authentication request
* @deprecated This method has been deprecated since it only applied to WebView authentication and Google is no longer supporting it. Please use {@link WebAuthProvider.Builder#start(Activity, AuthCallback)}
*/
@SuppressLint("VisibleForTests")
@Deprecated
public void start(@NonNull Activity activity, @NonNull AuthCallback callback, int requestCode) {
resetManagerInstance();
Expand Down
54 changes: 27 additions & 27 deletions auth0/src/test/java/com/auth0/android/Auth0Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,102 +68,102 @@ public class Auth0Test {
private static final String OTHER_DOMAIN = "samples-test.other-subdomain.other.auth0.com";

@Before
public void setUp() throws Exception {
public void setUp() {
MockitoAnnotations.initMocks(this);
}

@Test
public void shouldBeOIDCConformant() throws Exception {
public void shouldBeOIDCConformant() {
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN);
auth0.setOIDCConformant(true);

assertThat(auth0.isOIDCConformant(), is(true));
}

@Test
public void shouldNotBeOIDCConformant() throws Exception {
public void shouldNotBeOIDCConformant() {
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN);
auth0.setOIDCConformant(false);

assertThat(auth0.isOIDCConformant(), is(false));
}

@Test
public void shouldNotBeOIDCConformantByDefault() throws Exception {
public void shouldNotBeOIDCConformantByDefault() {
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN);
assertThat(auth0.isOIDCConformant(), is(false));
}

@Test
public void shouldHaveLoggingEnabled() throws Exception {
public void shouldHaveLoggingEnabled() {
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN);
auth0.setLoggingEnabled(true);

assertThat(auth0.isLoggingEnabled(), is(true));
}

@Test
public void shouldNotHaveLoggingEnabled() throws Exception {
public void shouldNotHaveLoggingEnabled() {
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN);
auth0.setLoggingEnabled(false);

assertThat(auth0.isLoggingEnabled(), is(false));
}

@Test
public void shouldNotEnforceTLS12ByDefault() throws Exception {
public void shouldNotEnforceTLS12ByDefault() {
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN);
assertThat(auth0.isTLS12Enforced(), is(false));
}

@Test
public void shouldHaveTLS12Enforced() throws Exception {
public void shouldHaveTLS12Enforced() {
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN);
auth0.setTLS12Enforced(true);

assertThat(auth0.isTLS12Enforced(), is(true));
}

@Test
public void shouldNotHaveTLS12Enforced() throws Exception {
public void shouldNotHaveTLS12Enforced() {
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN);
auth0.setTLS12Enforced(false);

assertThat(auth0.isTLS12Enforced(), is(false));
}

@Test
public void shouldHaveConnectTimeout() throws Exception {
public void shouldHaveConnectTimeout() {
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN);
auth0.setConnectTimeoutInSeconds(5);

assertThat(auth0.getConnectTimeoutInSeconds(), is(5));
}

@Test
public void shouldReadHaveTimeout() throws Exception {
public void shouldReadHaveTimeout() {
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN);
auth0.setReadTimeoutInSeconds(15);

assertThat(auth0.getReadTimeoutInSeconds(), is(15));
}

@Test
public void shouldHaveWriteTimeout() throws Exception {
public void shouldHaveWriteTimeout() {
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN);
auth0.setWriteTimeoutInSeconds(20);

assertThat(auth0.getWriteTimeoutInSeconds(), is(20));
}

@Test
public void shouldNotHaveLoggingEnabledByDefault() throws Exception {
public void shouldNotHaveLoggingEnabledByDefault() {
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN);
assertThat(auth0.isLoggingEnabled(), is(false));
}

@Test
public void shouldBuildFromResources() throws Exception {
public void shouldBuildFromResources() {
Resources resources = Mockito.mock(Resources.class);
when(context.getResources()).thenReturn(resources);
when(resources.getIdentifier(eq("com_auth0_client_id"), eq("string"), anyString())).thenReturn(222);
Expand All @@ -181,7 +181,7 @@ public void shouldBuildFromResources() throws Exception {
}

@Test
public void shouldFailToBuildFromResourcesWithoutClientID() throws Exception {
public void shouldFailToBuildFromResourcesWithoutClientID() {
Resources resources = Mockito.mock(Resources.class);
when(context.getResources()).thenReturn(resources);
when(resources.getIdentifier(eq("com_auth0_client_id"), eq("string"), anyString())).thenReturn(0);
Expand All @@ -194,7 +194,7 @@ public void shouldFailToBuildFromResourcesWithoutClientID() throws Exception {
}

@Test
public void shouldFailToBuildFromResourcesWithoutDomain() throws Exception {
public void shouldFailToBuildFromResourcesWithoutDomain() {
Resources resources = Mockito.mock(Resources.class);
when(context.getResources()).thenReturn(resources);
when(resources.getIdentifier(eq("com_auth0_client_id"), eq("string"), anyString())).thenReturn(222);
Expand All @@ -207,61 +207,61 @@ public void shouldFailToBuildFromResourcesWithoutDomain() throws Exception {
}

@Test
public void shouldBuildWithClientIdAndDomain() throws Exception {
public void shouldBuildWithClientIdAndDomain() {
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN);
assertThat(auth0.getClientId(), equalTo(CLIENT_ID));
assertThat(HttpUrl.parse(auth0.getDomainUrl()), equalTo(HttpUrl.parse("https://samples.auth0.com")));
assertThat(HttpUrl.parse(auth0.getConfigurationUrl()), equalTo(HttpUrl.parse("https://cdn.auth0.com")));
}

@Test
public void shouldBuildWithConfigurationDomainToo() throws Exception {
public void shouldBuildWithConfigurationDomainToo() {
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN, CONFIG_DOMAIN_CUSTOM);
assertThat(auth0.getClientId(), equalTo(CLIENT_ID));
assertThat(HttpUrl.parse(auth0.getDomainUrl()), equalTo(HttpUrl.parse("https://samples.auth0.com")));
assertThat(HttpUrl.parse(auth0.getConfigurationUrl()), equalTo(HttpUrl.parse("https://config.mydomain.com")));
}

@Test
public void shouldHandleEUInstance() throws Exception {
public void shouldHandleEUInstance() {
Auth0 auth0 = new Auth0(CLIENT_ID, EU_DOMAIN);
assertThat(auth0.getClientId(), equalTo(CLIENT_ID));
assertThat(HttpUrl.parse(auth0.getDomainUrl()), equalTo(HttpUrl.parse("https://samples.eu.auth0.com")));
assertThat(HttpUrl.parse(auth0.getConfigurationUrl()), equalTo(HttpUrl.parse("https://cdn.eu.auth0.com")));
}

@Test
public void shouldHandleAUInstance() throws Exception {
public void shouldHandleAUInstance() {
Auth0 auth0 = new Auth0(CLIENT_ID, AU_DOMAIN);
assertThat(auth0.getClientId(), equalTo(CLIENT_ID));
assertThat(HttpUrl.parse(auth0.getDomainUrl()), equalTo(HttpUrl.parse("https://samples.au.auth0.com")));
assertThat(HttpUrl.parse(auth0.getConfigurationUrl()), equalTo(HttpUrl.parse("https://cdn.au.auth0.com")));
}

@Test
public void shouldHandleOtherInstance() throws Exception {
public void shouldHandleOtherInstance() {
Auth0 auth0 = new Auth0(CLIENT_ID, OTHER_DOMAIN);
assertThat(auth0.getClientId(), equalTo(CLIENT_ID));
assertThat(HttpUrl.parse(auth0.getDomainUrl()), equalTo(HttpUrl.parse("https://samples-test.other-subdomain.other.auth0.com")));
assertThat(HttpUrl.parse(auth0.getConfigurationUrl()), equalTo(HttpUrl.parse("https://cdn.other.auth0.com")));
}

@Test
public void shouldHandleNonAuth0Domain() throws Exception {
public void shouldHandleNonAuth0Domain() {
Auth0 auth0 = new Auth0(CLIENT_ID, "mydomain.com");
assertThat(auth0.getClientId(), equalTo(CLIENT_ID));
assertThat(HttpUrl.parse(auth0.getDomainUrl()), equalTo(HttpUrl.parse("https://mydomain.com")));
assertThat(HttpUrl.parse(auth0.getConfigurationUrl()), equalTo(HttpUrl.parse("https://mydomain.com")));
}

@Test
public void shouldThrowWhenInvalidDomain() throws Exception {
public void shouldThrowWhenInvalidDomain() {
expectedException.expect(IllegalArgumentException.class);
new Auth0(CLIENT_ID, "some invalid domain.com");
}

@Test
public void shouldReturnAuthorizeUrl() throws Exception {
public void shouldReturnAuthorizeUrl() {
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN);

final HttpUrl url = HttpUrl.parse(auth0.getAuthorizeUrl());
Expand All @@ -271,7 +271,7 @@ public void shouldReturnAuthorizeUrl() throws Exception {
}

@Test
public void shouldReturnLogoutUrl() throws Exception {
public void shouldReturnLogoutUrl() {
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN);

final HttpUrl url = HttpUrl.parse(auth0.getLogoutUrl());
Expand All @@ -281,14 +281,14 @@ public void shouldReturnLogoutUrl() throws Exception {
}

@Test
public void shouldNotReturnTelemetryWhenExplicitlyDisabledThem() throws Exception {
public void shouldNotReturnTelemetryWhenExplicitlyDisabledThem() {
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN);
auth0.doNotSendTelemetry();
assertThat(auth0.getTelemetry(), is(nullValue()));
}

@Test
public void shouldSetCustomTelemetry() throws Exception {
public void shouldSetCustomTelemetry() {
Telemetry customTelemetry = new Telemetry("custom", "9.9.9", "1.1.1");
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN);
auth0.setTelemetry(customTelemetry);
Expand Down
Loading

0 comments on commit 590a2bf

Please sign in to comment.