Search in sources :

Example 71 with Request

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

the class OrganizationEntityTest method shouldGetInvitationsWithFilter.

@Test
public void shouldGetInvitationsWithFilter() throws Exception {
    InvitationsFilter filter = new InvitationsFilter().withSort("created_at:1").withFields("invitee,inviter,created_at", true);
    Request<InvitationsPage> request = api.organizations().getInvitations("org_123", filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(INVITATIONS_LIST, 200);
    InvitationsPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/organizations/org_123/invitations"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, hasQueryParameter("fields", "invitee,inviter,created_at"));
    assertThat(recordedRequest, hasQueryParameter("include_fields", "true"));
    assertThat(recordedRequest, hasQueryParameter("sort", "created_at:1"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) InvitationsFilter(com.auth0.client.mgmt.filter.InvitationsFilter) Test(org.junit.Test)

Example 72 with Request

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

the class OrganizationEntityTest method shouldGetInvitationsWithTotals.

@Test
public void shouldGetInvitationsWithTotals() throws Exception {
    InvitationsFilter filter = new InvitationsFilter().withTotals(true);
    Request<InvitationsPage> request = api.organizations().getInvitations("org_123", filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(INVITATIONS_PAGED_LIST, 200);
    InvitationsPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/organizations/org_123/invitations"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, hasQueryParameter("include_totals", "true"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) InvitationsFilter(com.auth0.client.mgmt.filter.InvitationsFilter) Test(org.junit.Test)

Example 73 with Request

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

the class OrganizationEntityTest method shouldListOrgsWithPage.

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

Example 74 with Request

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

the class ResourceServerEntityTest method shouldListResourceServerWithPage.

@Test
public void shouldListResourceServerWithPage() throws Exception {
    ResourceServersFilter filter = new ResourceServersFilter().withPage(23, 5);
    Request<ResourceServersPage> request = api.resourceServers().list(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_RESOURCE_SERVERS_LIST, 200);
    ResourceServersPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/resource-servers"));
    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) ResourceServersFilter(com.auth0.client.mgmt.filter.ResourceServersFilter) ResourceServersPage(com.auth0.json.mgmt.ResourceServersPage) Test(org.junit.Test)

Example 75 with Request

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

the class ResourceServerEntityTest method shouldUpdateResourceServer.

@Test
public void shouldUpdateResourceServer() throws Exception {
    ResourceServer resourceServer = new ResourceServer("https://api.my-company.com/api/v2/");
    resourceServer.setId("23445566abab");
    resourceServer.setName("Some API");
    resourceServer.setScopes(Collections.singletonList(new Scope("update:something")));
    resourceServer.setSigningAlgorithm("RS256");
    resourceServer.setSigningSecret("secret");
    resourceServer.setAllowOfflineAccess(false);
    resourceServer.setEnforcePolicies(true);
    resourceServer.setSkipConsentForVerifiableFirstPartyClients(false);
    resourceServer.setTokenDialect("access_token");
    resourceServer.setTokenLifetime(0);
    resourceServer.setVerificationLocation("verification_location");
    Request<ResourceServer> request = api.resourceServers().update("23445566abab", resourceServer);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_RESOURCE_SERVER, 200);
    ResourceServer response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("PATCH", "/api/v2/resource-servers/23445566abab"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    Map<String, Object> body = bodyFromRequest(recordedRequest);
    assertThat(body.size(), is(12));
    assertThat(body, hasEntry("identifier", "https://api.my-company.com/api/v2/"));
    assertThat(response.getIdentifier(), is("https://api.my-company.com/api/v2/"));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Scope(com.auth0.json.mgmt.Scope) ResourceServer(com.auth0.json.mgmt.ResourceServer) 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