diff --git a/auth0/src/main/java/com/auth0/android/authentication/AuthenticationAPIClient.java b/auth0/src/main/java/com/auth0/android/authentication/AuthenticationAPIClient.java index 59be66a20..959143c8e 100755 --- a/auth0/src/main/java/com/auth0/android/authentication/AuthenticationAPIClient.java +++ b/auth0/src/main/java/com/auth0/android/authentication/AuthenticationAPIClient.java @@ -134,13 +134,11 @@ private AuthenticationAPIClient(Auth0 auth0, RequestFactory factory, OkHttpClien } /** - * Whether to log every Request and Response or not. + * Log every Request and Response made by this client. * You shouldn't enable logging in release builds as it may leak sensitive information. - * - * @param enabled whether the logging is enabled or not. */ - public void setLogging(boolean enabled) { - logInterceptor.setLevel(enabled ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE); + public void enableLogging() { + logInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); } public String getClientId() { diff --git a/auth0/src/main/java/com/auth0/android/management/UsersAPIClient.java b/auth0/src/main/java/com/auth0/android/management/UsersAPIClient.java index 9abc11187..0d57ca351 100755 --- a/auth0/src/main/java/com/auth0/android/management/UsersAPIClient.java +++ b/auth0/src/main/java/com/auth0/android/management/UsersAPIClient.java @@ -114,13 +114,11 @@ private UsersAPIClient(Auth0 auth0, RequestFactory factory, OkHttpClient client, } /** - * Whether to log every Request and Response or not. + * Log every Request and Response made by this client. * You shouldn't enable logging in release builds as it may leak sensitive information. - * - * @param enabled whether the logging is enabled or not. */ - public void setLogging(boolean enabled) { - logInterceptor.setLevel(enabled ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE); + public void enableLogging() { + logInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); } public String getClientId() { diff --git a/auth0/src/main/java/com/auth0/android/provider/WebAuthProvider.java b/auth0/src/main/java/com/auth0/android/provider/WebAuthProvider.java index e7dd9be4f..074752e0d 100644 --- a/auth0/src/main/java/com/auth0/android/provider/WebAuthProvider.java +++ b/auth0/src/main/java/com/auth0/android/provider/WebAuthProvider.java @@ -224,13 +224,11 @@ public Builder withConnection(@NonNull String connectionName) { } /** - * Whether to log every Request and Response or not. + * Log every Request and Response made by this provider. * You shouldn't enable logging in release builds as it may leak sensitive information. - * - * @param enabled whether the logging is enabled or not. */ - public Builder setLogging(boolean enabled) { - this.loggingEnabled = enabled; + public Builder enableLogging() { + this.loggingEnabled = true; return this; } @@ -479,7 +477,9 @@ private Uri buildAuthorizeUri() { private PKCE createPKCE(String redirectUri) { if (pkce == null) { final AuthenticationAPIClient client = new AuthenticationAPIClient(account); - client.setLogging(loggingEnabled); + if (loggingEnabled) { + client.enableLogging(); + } return new PKCE(client, redirectUri); } else { return pkce; diff --git a/auth0/src/test/java/com/auth0/android/authentication/AuthenticationAPIClientTest.java b/auth0/src/test/java/com/auth0/android/authentication/AuthenticationAPIClientTest.java index fa14eb3ce..0d459e519 100755 --- a/auth0/src/test/java/com/auth0/android/authentication/AuthenticationAPIClientTest.java +++ b/auth0/src/test/java/com/auth0/android/authentication/AuthenticationAPIClientTest.java @@ -157,7 +157,7 @@ public void shouldEnableHttpLogging() throws Exception { ArgumentCaptor interceptorCaptor = ArgumentCaptor.forClass(Interceptor.class); AuthenticationAPIClient client = new AuthenticationAPIClient(account, factory, okClient); - client.setLogging(true); + client.enableLogging(); verify(okClient).interceptors(); verify(list).add(interceptorCaptor.capture()); @@ -167,27 +167,6 @@ public void shouldEnableHttpLogging() throws Exception { assertThat(((HttpLoggingInterceptor) interceptorCaptor.getValue()).getLevel(), is(HttpLoggingInterceptor.Level.BODY)); } - @SuppressWarnings("unchecked") - @Test - public void shouldDisableHttpLogging() throws Exception { - Auth0 account = mock(Auth0.class); - RequestFactory factory = mock(RequestFactory.class); - OkHttpClient okClient = mock(OkHttpClient.class); - List list = mock(List.class); - when(okClient.interceptors()).thenReturn(list); - - ArgumentCaptor interceptorCaptor = ArgumentCaptor.forClass(Interceptor.class); - AuthenticationAPIClient client = new AuthenticationAPIClient(account, factory, okClient); - client.setLogging(false); - - verify(okClient).interceptors(); - verify(list).add(interceptorCaptor.capture()); - - assertThat(interceptorCaptor.getValue(), is(notNullValue())); - assertThat(interceptorCaptor.getValue(), is(instanceOf(HttpLoggingInterceptor.class))); - assertThat(((HttpLoggingInterceptor) interceptorCaptor.getValue()).getLevel(), is(HttpLoggingInterceptor.Level.NONE)); - } - @SuppressWarnings("unchecked") @Test public void shouldHaveHttpLoggingDisabledByDefault() throws Exception { diff --git a/auth0/src/test/java/com/auth0/android/management/UsersAPIClientTest.java b/auth0/src/test/java/com/auth0/android/management/UsersAPIClientTest.java index 05485ff33..a213c48c3 100755 --- a/auth0/src/test/java/com/auth0/android/management/UsersAPIClientTest.java +++ b/auth0/src/test/java/com/auth0/android/management/UsersAPIClientTest.java @@ -152,7 +152,7 @@ public void shouldEnableHttpLogging() throws Exception { ArgumentCaptor interceptorCaptor = ArgumentCaptor.forClass(Interceptor.class); UsersAPIClient client = new UsersAPIClient(account, factory, okClient); - client.setLogging(true); + client.enableLogging(); verify(okClient).interceptors(); verify(list).add(interceptorCaptor.capture()); @@ -162,27 +162,6 @@ public void shouldEnableHttpLogging() throws Exception { assertThat(((HttpLoggingInterceptor) interceptorCaptor.getValue()).getLevel(), is(HttpLoggingInterceptor.Level.BODY)); } - @SuppressWarnings("unchecked") - @Test - public void shouldDisableHttpLogging() throws Exception { - Auth0 account = mock(Auth0.class); - RequestFactory factory = mock(RequestFactory.class); - OkHttpClient okClient = mock(OkHttpClient.class); - List list = mock(List.class); - when(okClient.interceptors()).thenReturn(list); - - ArgumentCaptor interceptorCaptor = ArgumentCaptor.forClass(Interceptor.class); - UsersAPIClient client = new UsersAPIClient(account, factory, okClient); - client.setLogging(false); - - verify(okClient).interceptors(); - verify(list).add(interceptorCaptor.capture()); - - assertThat(interceptorCaptor.getValue(), is(notNullValue())); - assertThat(interceptorCaptor.getValue(), is(instanceOf(HttpLoggingInterceptor.class))); - assertThat(((HttpLoggingInterceptor) interceptorCaptor.getValue()).getLevel(), is(HttpLoggingInterceptor.Level.NONE)); - } - @SuppressWarnings("unchecked") @Test public void shouldHaveHttpLoggingDisabledByDefault() throws Exception { diff --git a/auth0/src/test/java/com/auth0/android/provider/WebAuthProviderTest.java b/auth0/src/test/java/com/auth0/android/provider/WebAuthProviderTest.java index 2b144d9cb..a6abc11e6 100644 --- a/auth0/src/test/java/com/auth0/android/provider/WebAuthProviderTest.java +++ b/auth0/src/test/java/com/auth0/android/provider/WebAuthProviderTest.java @@ -170,23 +170,13 @@ public void shouldHaveLoggingDisabledByDefault() throws Exception { @Test public void shouldEnableLogging() throws Exception { WebAuthProvider.init(account) - .setLogging(true) + .enableLogging() .start(activity, callback); final WebAuthProvider instance = WebAuthProvider.getInstance(); assertTrue(instance.isLoggingEnabled()); } - @Test - public void shouldDisableLogging() throws Exception { - WebAuthProvider.init(account) - .setLogging(false) - .start(activity, callback); - - final WebAuthProvider instance = WebAuthProvider.getInstance(); - assertFalse(instance.isLoggingEnabled()); - } - @Test public void shouldCallStartWithRequestCode() throws Exception { WebAuthProvider.init(account)