Skip to content

Commit

Permalink
rename setLogging(boolean) to loggingEnabled()
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalmaceda committed Nov 24, 2016
1 parent bf1db68 commit c9abadc
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void shouldEnableHttpLogging() throws Exception {

ArgumentCaptor<Interceptor> 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());
Expand All @@ -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<Interceptor> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void shouldEnableHttpLogging() throws Exception {

ArgumentCaptor<Interceptor> 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());
Expand All @@ -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<Interceptor> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c9abadc

Please sign in to comment.