Search in sources :

Example 16 with AuthAPI

use of com.auth0.client.auth.AuthAPI in project auth0-java by auth0.

the class AuthAPITest method setUp.

@Before
public void setUp() throws Exception {
    server = new MockServer();
    api = new AuthAPI(server.getBaseUrl(), CLIENT_ID, CLIENT_SECRET);
}
Also used : MockServer(com.auth0.client.MockServer) Before(org.junit.Before)

Example 17 with AuthAPI

use of com.auth0.client.auth.AuthAPI in project auth0-java by auth0.

the class AuthAPITest method shouldConfigureBasicLoggingFromOptions.

@Test
public void shouldConfigureBasicLoggingFromOptions() {
    LoggingOptions loggingOptions = new LoggingOptions(LoggingOptions.LogLevel.BASIC);
    HttpOptions options = new HttpOptions();
    options.setLoggingOptions(loggingOptions);
    AuthAPI api = new AuthAPI(DOMAIN, CLIENT_ID, CLIENT_SECRET, options);
    assertThat(api.getClient().interceptors(), hasItem(isA(HttpLoggingInterceptor.class)));
    for (Interceptor i : api.getClient().interceptors()) {
        if (i instanceof HttpLoggingInterceptor) {
            HttpLoggingInterceptor logging = (HttpLoggingInterceptor) i;
            assertThat(logging.getLevel(), is(Level.BASIC));
        }
    }
}
Also used : HttpOptions(com.auth0.client.HttpOptions) LoggingOptions(com.auth0.client.LoggingOptions) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Test(org.junit.Test)

Example 18 with AuthAPI

use of com.auth0.client.auth.AuthAPI in project auth0-java by auth0.

the class AuthAPITest method shouldConfigureNoneLoggingFromOptions.

@Test
public void shouldConfigureNoneLoggingFromOptions() {
    LoggingOptions loggingOptions = new LoggingOptions(LoggingOptions.LogLevel.NONE);
    HttpOptions options = new HttpOptions();
    options.setLoggingOptions(loggingOptions);
    AuthAPI api = new AuthAPI(DOMAIN, CLIENT_ID, CLIENT_SECRET, options);
    assertThat(api.getClient().interceptors(), hasItem(isA(HttpLoggingInterceptor.class)));
    for (Interceptor i : api.getClient().interceptors()) {
        if (i instanceof HttpLoggingInterceptor) {
            HttpLoggingInterceptor logging = (HttpLoggingInterceptor) i;
            assertThat(logging.getLevel(), is(Level.NONE));
        }
    }
}
Also used : HttpOptions(com.auth0.client.HttpOptions) LoggingOptions(com.auth0.client.LoggingOptions) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Test(org.junit.Test)

Example 19 with AuthAPI

use of com.auth0.client.auth.AuthAPI in project auth0-java by auth0.

the class AuthAPITest method shouldUseProxy.

@Test
public void shouldUseProxy() throws Exception {
    Proxy proxy = Mockito.mock(Proxy.class);
    ProxyOptions proxyOptions = new ProxyOptions(proxy);
    HttpOptions httpOptions = new HttpOptions();
    httpOptions.setProxyOptions(proxyOptions);
    AuthAPI api = new AuthAPI(DOMAIN, CLIENT_ID, CLIENT_SECRET, httpOptions);
    assertThat(api.getClient().proxy(), is(proxy));
    Authenticator authenticator = api.getClient().proxyAuthenticator();
    assertThat(authenticator, is(notNullValue()));
    Route route = Mockito.mock(Route.class);
    okhttp3.Request nonAuthenticatedRequest = new okhttp3.Request.Builder().url("https://test.com/app").addHeader("some-header", "some-value").build();
    okhttp3.Response nonAuthenticatedResponse = new okhttp3.Response.Builder().protocol(Protocol.HTTP_2).code(200).message("OK").request(nonAuthenticatedRequest).build();
    okhttp3.Request processedRequest = authenticator.authenticate(route, nonAuthenticatedResponse);
    assertThat(processedRequest, is(nullValue()));
}
Also used : ProxyOptions(com.auth0.client.ProxyOptions) HttpOptions(com.auth0.client.HttpOptions) Request(com.auth0.net.Request) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Proxy(java.net.Proxy) okhttp3(okhttp3) Test(org.junit.Test)

Example 20 with AuthAPI

use of com.auth0.client.auth.AuthAPI in project auth0-java by auth0.

the class AuthAPITest method shouldUseZeroIfNegativeTimoutConfigured.

@Test
public void shouldUseZeroIfNegativeTimoutConfigured() {
    HttpOptions options = new HttpOptions();
    options.setConnectTimeout(-1);
    options.setReadTimeout(-10);
    AuthAPI api = new AuthAPI(DOMAIN, CLIENT_ID, CLIENT_SECRET, options);
    assertThat(api.getClient().connectTimeoutMillis(), is(0));
    assertThat(api.getClient().readTimeoutMillis(), is(0));
}
Also used : HttpOptions(com.auth0.client.HttpOptions) Test(org.junit.Test)

Aggregations

AuthAPI (com.auth0.client.auth.AuthAPI)12 HttpOptions (com.auth0.client.HttpOptions)11 Test (org.junit.Test)11 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 Test (org.junit.jupiter.api.Test)7 LoggingOptions (com.auth0.client.LoggingOptions)4 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)4 ProxyOptions (com.auth0.client.ProxyOptions)3 Proxy (java.net.Proxy)3 okhttp3 (okhttp3)3 UserInfo (com.auth0.json.auth.UserInfo)2 AuthRequest (com.auth0.net.AuthRequest)2 Request (com.auth0.net.Request)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 Before (org.junit.Before)2 MockServer (com.auth0.client.MockServer)1 APIException (com.auth0.exception.APIException)1 Auth0Exception (com.auth0.exception.Auth0Exception)1 TokenHolder (com.auth0.json.auth.TokenHolder)1