Search in sources :

Example 76 with Request

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

the class ResourceServerEntityTest method shouldGetResourceServerById.

@Test
public void shouldGetResourceServerById() throws Exception {
    Request<ResourceServer> request = api.resourceServers().get("23445566abab");
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_RESOURCE_SERVER, 200);
    ResourceServer response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/resource-servers/23445566abab"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(response.getIdentifier(), is("https://api.my-company.com/api/v2/"));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ResourceServer(com.auth0.json.mgmt.ResourceServer) Test(org.junit.Test)

Example 77 with Request

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

the class RolesEntityTest method shouldGetRole.

@Test
public void shouldGetRole() throws Exception {
    Request<Role> request = api.roles().get("1");
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_ROLE, 200);
    Role response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/roles/1"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(response, is(notNullValue()));
}
Also used : Role(com.auth0.json.mgmt.Role) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test)

Example 78 with Request

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

the class RolesEntityTest method shouldListUsersWithPage.

@Test
public void shouldListUsersWithPage() throws Exception {
    PageFilter filter = new PageFilter().withPage(23, 5);
    Request<UsersPage> request = api.roles().listUsers("1", filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_ROLE_USERS_PAGED_LIST, 200);
    UsersPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/roles/1/users"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, hasQueryParameter("page", "23"));
    assertThat(recordedRequest, hasQueryParameter("per_page", "5"));
    assertThat(response, is(notNullValue()));
    assertThat(response.getItems(), hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) PageFilter(com.auth0.client.mgmt.filter.PageFilter) UsersPage(com.auth0.json.mgmt.users.UsersPage) Test(org.junit.Test)

Example 79 with Request

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

the class RolesEntityTest method shouldListPermissionsWithPage.

@Test
public void shouldListPermissionsWithPage() throws Exception {
    PageFilter filter = new PageFilter().withPage(23, 5);
    Request<PermissionsPage> request = api.roles().listPermissions("1", filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_ROLE_PERMISSIONS_PAGED_LIST, 200);
    PermissionsPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/roles/1/permissions"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, hasQueryParameter("page", "23"));
    assertThat(recordedRequest, hasQueryParameter("per_page", "5"));
    assertThat(response, is(notNullValue()));
    assertThat(response.getItems(), hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) PermissionsPage(com.auth0.json.mgmt.PermissionsPage) PageFilter(com.auth0.client.mgmt.filter.PageFilter) Test(org.junit.Test)

Example 80 with Request

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

the class RulesConfigsEntityTest method shouldUpdateRulesConfig.

@Test
public void shouldUpdateRulesConfig() throws Exception {
    Request<RulesConfig> request = api.rulesConfigs().update("1", new RulesConfig("my-value"));
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_CONNECTION, 200);
    RulesConfig response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("PUT", "/api/v2/rules-configs/1"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    Map<String, Object> body = bodyFromRequest(recordedRequest);
    assertThat(body.size(), is(1));
    assertThat(body, hasEntry("value", "my-value"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) RulesConfig(com.auth0.json.mgmt.RulesConfig) 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