Search in sources :

Example 36 with Request

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()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) LogEvent(com.auth0.json.mgmt.logevents.LogEvent) Test(org.junit.Test)

Example 37 with Request

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())));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) LogStream(com.auth0.json.mgmt.logstreams.LogStream) Test(org.junit.Test)

Example 38 with Request

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()));
}
Also used : ProxyOptions(com.auth0.client.ProxyOptions) HttpOptions(com.auth0.client.HttpOptions) Proxy(java.net.Proxy) okhttp3(okhttp3) Test(org.junit.Test)

Example 39 with Request

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()));
}
Also used : Proxy(java.net.Proxy) ProxyOptions(com.auth0.client.ProxyOptions) okhttp3(okhttp3) HttpOptions(com.auth0.client.HttpOptions) Test(org.junit.Test)

Example 40 with Request

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"));
}
Also used : ProxyOptions(com.auth0.client.ProxyOptions) HttpOptions(com.auth0.client.HttpOptions) Proxy(java.net.Proxy) okhttp3(okhttp3) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)193 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)185 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)77 IOException (java.io.IOException)76 List (java.util.List)63 Algorithm (com.auth0.jwt.algorithms.Algorithm)35 VoidRequest (com.auth0.net.VoidRequest)33 Auth0Exception (com.auth0.exception.Auth0Exception)30 APIException (com.auth0.exception.APIException)27 RateLimitException (com.auth0.exception.RateLimitException)25 HashMap (java.util.HashMap)24 PageFilter (com.auth0.client.mgmt.filter.PageFilter)23 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)23 ServletException (javax.servlet.ServletException)23 TokenHolder (com.auth0.json.auth.TokenHolder)22 JWTVerifier (com.auth0.jwt.JWTVerifier)22 ArrayList (java.util.ArrayList)22 Test (org.junit.jupiter.api.Test)22 JWTVerificationException (com.auth0.jwt.exceptions.JWTVerificationException)20 Date (java.util.Date)20