Search in sources :

Example 61 with Request

use of com.auth0.net.Request in project auth0-java by auth0.

the class ConnectionsEntityTest method shouldListConnections.

@Test
public void shouldListConnections() throws Exception {
    @SuppressWarnings("deprecation") Request<List<Connection>> request = api.connections().list(null);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_CONNECTIONS_LIST, 200);
    List<Connection> response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/connections"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(response, is(notNullValue()));
    assertThat(response, hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Connection(com.auth0.json.mgmt.Connection) List(java.util.List) Test(org.junit.Test)

Example 62 with Request

use of com.auth0.net.Request in project auth0-java by auth0.

the class DeviceCredentialsEntityTest method shouldListDeviceCredentialsWithType.

@Test
public void shouldListDeviceCredentialsWithType() throws Exception {
    DeviceCredentialsFilter filter = new DeviceCredentialsFilter().withType("public_key");
    Request<List<DeviceCredentials>> request = api.deviceCredentials().list(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_DEVICE_CREDENTIALS_LIST, 200);
    List<DeviceCredentials> response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/device-credentials"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, hasQueryParameter("type", "public_key"));
    assertThat(response, is(notNullValue()));
    assertThat(response, hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) DeviceCredentialsFilter(com.auth0.client.mgmt.filter.DeviceCredentialsFilter) List(java.util.List) DeviceCredentials(com.auth0.json.mgmt.DeviceCredentials) Test(org.junit.Test)

Example 63 with Request

use of com.auth0.net.Request in project auth0-java by auth0.

the class DeviceCredentialsEntityTest method shouldCreateDeviceCredentials.

@Test
public void shouldCreateDeviceCredentials() throws Exception {
    Request<DeviceCredentials> request = api.deviceCredentials().create(new DeviceCredentials("device", "public_key", "val123", "id123", "clientId"));
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_DEVICE_CREDENTIALS, 200);
    DeviceCredentials response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/device-credentials"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    Map<String, Object> body = bodyFromRequest(recordedRequest);
    assertThat(body.size(), is(5));
    assertThat(body, hasEntry("device_name", "device"));
    assertThat(body, hasEntry("type", "public_key"));
    assertThat(body, hasEntry("value", "val123"));
    assertThat(body, hasEntry("device_id", "id123"));
    assertThat(body, hasEntry("client_id", "clientId"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) DeviceCredentials(com.auth0.json.mgmt.DeviceCredentials) Test(org.junit.Test)

Example 64 with Request

use of com.auth0.net.Request in project auth0-java by auth0.

the class DeviceCredentialsEntityTest method shouldListDeviceCredentialsWithClientId.

@Test
public void shouldListDeviceCredentialsWithClientId() throws Exception {
    DeviceCredentialsFilter filter = new DeviceCredentialsFilter().withClientId("client_23");
    Request<List<DeviceCredentials>> request = api.deviceCredentials().list(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_DEVICE_CREDENTIALS_LIST, 200);
    List<DeviceCredentials> response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/device-credentials"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, hasQueryParameter("client_id", "client_23"));
    assertThat(response, is(notNullValue()));
    assertThat(response, hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) DeviceCredentialsFilter(com.auth0.client.mgmt.filter.DeviceCredentialsFilter) List(java.util.List) DeviceCredentials(com.auth0.json.mgmt.DeviceCredentials) Test(org.junit.Test)

Example 65 with Request

use of com.auth0.net.Request in project auth0-java by auth0.

the class DeviceCredentialsEntityTest method shouldListDeviceCredentials.

@Test
public void shouldListDeviceCredentials() throws Exception {
    Request<List<DeviceCredentials>> request = api.deviceCredentials().list(null);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_DEVICE_CREDENTIALS_LIST, 200);
    List<DeviceCredentials> response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/device-credentials"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(response, is(notNullValue()));
    assertThat(response, hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) List(java.util.List) DeviceCredentials(com.auth0.json.mgmt.DeviceCredentials) 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