Search in sources :

Example 26 with HttpOptions

use of com.auth0.client.HttpOptions in project auth0-java by auth0.

the class AuthAPITest method proxyShouldNotProcessAlreadyAuthenticatedRequest.

@Test
public void proxyShouldNotProcessAlreadyAuthenticatedRequest() throws Exception {
    Proxy proxy = Mockito.mock(Proxy.class);
    ProxyOptions proxyOptions = new ProxyOptions(proxy);
    proxyOptions.setBasicAuthentication("johndoe", "psswd".toCharArray());
    assertThat(proxyOptions.getBasicAuthentication(), is("Basic am9obmRvZTpwc3N3ZA=="));
    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 alreadyAuthenticatedRequest = new okhttp3.Request.Builder().url("https://test.com/app").addHeader("some-header", "some-value").header("Proxy-Authorization", "pre-existing-value").build();
    okhttp3.Response alreadyAuthenticatedResponse = new okhttp3.Response.Builder().protocol(Protocol.HTTP_2).code(200).message("OK").request(alreadyAuthenticatedRequest).build();
    okhttp3.Request processedRequest = authenticator.authenticate(route, alreadyAuthenticatedResponse);
    assertThat(processedRequest, is(nullValue()));
}
Also used : Proxy(java.net.Proxy) ProxyOptions(com.auth0.client.ProxyOptions) okhttp3(okhttp3) HttpOptions(com.auth0.client.HttpOptions) Test(org.junit.Test)

Example 27 with HttpOptions

use of com.auth0.client.HttpOptions in project auth0-java by auth0.

the class AuthAPITest method shouldUseProxyWithAuthentication.

@Test
public void shouldUseProxyWithAuthentication() throws Exception {
    Proxy proxy = Mockito.mock(Proxy.class);
    ProxyOptions proxyOptions = new ProxyOptions(proxy);
    proxyOptions.setBasicAuthentication("johndoe", "psswd".toCharArray());
    assertThat(proxyOptions.getBasicAuthentication(), is("Basic am9obmRvZTpwc3N3ZA=="));
    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(notNullValue()));
    assertThat(processedRequest.url(), is(HttpUrl.parse("https://test.com/app")));
    assertThat(processedRequest.header("Proxy-Authorization"), is(proxyOptions.getBasicAuthentication()));
    assertThat(processedRequest.header("some-header"), is("some-value"));
}
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 28 with HttpOptions

use of com.auth0.client.HttpOptions 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 29 with HttpOptions

use of com.auth0.client.HttpOptions 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 30 with HttpOptions

use of com.auth0.client.HttpOptions 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)

Aggregations

HttpOptions (com.auth0.client.HttpOptions)31 Test (org.junit.Test)29 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)9 LoggingOptions (com.auth0.client.LoggingOptions)8 ProxyOptions (com.auth0.client.ProxyOptions)8 RateLimitInterceptor (com.auth0.net.RateLimitInterceptor)6 Proxy (java.net.Proxy)6 okhttp3 (okhttp3)6 TelemetryInterceptor (com.auth0.net.TelemetryInterceptor)5 Request (com.auth0.net.Request)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 Test (org.junit.jupiter.api.Test)2 PasswordlessEmailResponse (com.auth0.json.auth.PasswordlessEmailResponse)1 PasswordlessSmsResponse (com.auth0.json.auth.PasswordlessSmsResponse)1