use of com.auth0.client.HttpOptions in project auth0-java by auth0.
the class ManagementAPITest 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);
ManagementAPI api = new ManagementAPI(DOMAIN, API_TOKEN, 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"));
}
use of com.auth0.client.HttpOptions in project auth0-java by auth0.
the class AuthAPITest method shouldThrowOnInValidMaxRequestsPerHostConfiguration.
@Test
public void shouldThrowOnInValidMaxRequestsPerHostConfiguration() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("maxRequestsPerHost must be one or greater.");
HttpOptions options = new HttpOptions();
options.setMaxRequestsPerHost(0);
}
use of com.auth0.client.HttpOptions in project auth0-java by auth0.
the class AuthAPITest method shouldConfigureBodyLoggingFromOptions.
@Test
public void shouldConfigureBodyLoggingFromOptions() {
LoggingOptions loggingOptions = new LoggingOptions(LoggingOptions.LogLevel.BODY);
Set<String> headersToRedact = new HashSet<>();
headersToRedact.add("Authorization");
headersToRedact.add("Cookie");
loggingOptions.setHeadersToRedact(headersToRedact);
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.BODY));
}
}
}
use of com.auth0.client.HttpOptions in project auth0-java by auth0.
the class AuthAPITest method shouldThrowOnInValidMaxRequestsConfiguration.
@Test
public void shouldThrowOnInValidMaxRequestsConfiguration() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("maxRequests must be one or greater.");
HttpOptions options = new HttpOptions();
options.setMaxRequests(0);
}
use of com.auth0.client.HttpOptions in project auth0-java by auth0.
the class AuthAPITest method shouldUseConfiguredMaxRequests.
@Test
public void shouldUseConfiguredMaxRequests() {
HttpOptions options = new HttpOptions();
options.setMaxRequests(10);
AuthAPI api = new AuthAPI(DOMAIN, CLIENT_ID, CLIENT_SECRET, options);
assertThat(api.getClient().dispatcher().getMaxRequests(), is(10));
}
Aggregations