use of com.auth0.net.Request in project auth0-java by auth0.
the class LogEventsEntityTest method shouldGetLogEvent.
@Test
public void shouldGetLogEvent() throws Exception {
Request<LogEvent> request = api.logEvents().get("1");
assertThat(request, is(notNullValue()));
server.jsonResponse(MGMT_LOG_EVENT, 200);
LogEvent response = request.execute();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/logs/1"));
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
assertThat(response, is(notNullValue()));
}
use of com.auth0.net.Request in project auth0-java by auth0.
the class LogStreamsEntityTest method shouldUpdateLogStream.
@Test
public void shouldUpdateLogStream() throws Exception {
LogStream logStream = getLogStream("log stream", null);
logStream.setStatus("paused");
Request<LogStream> request = api.logStreams().update("123", logStream);
assertThat(request, is(notNullValue()));
server.jsonResponse(MGMT_LOG_STREAM, 200);
LogStream response = request.execute();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest, hasMethodAndPath("PATCH", "/api/v2/log-streams/123"));
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
Map<String, Object> body = bodyFromRequest(recordedRequest);
assertThat(body.size(), is(3));
assertThat(body, hasEntry("name", "log stream"));
assertThat(body, hasEntry("status", "paused"));
assertThat(body, hasEntry("sink", logStream.getSink()));
assertThat(response, is(notNullValue()));
assertThat(response, hasProperty("id", is(notNullValue())));
assertThat(response, hasProperty("name", is(notNullValue())));
assertThat(response, hasProperty("type", is(notNullValue())));
assertThat(response, hasProperty("status", is(notNullValue())));
assertThat(response, hasProperty("sink", is(notNullValue())));
}
use of com.auth0.net.Request in project auth0-java by auth0.
the class ManagementAPITest 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);
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(nullValue()));
}
use of com.auth0.net.Request in project auth0-java by auth0.
the class ManagementAPITest 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);
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 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()));
}
use of com.auth0.net.Request 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"));
}
Aggregations