Search in sources :

Example 46 with Request

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

the class ActionsEntityTest method shouldListActionsWithFilter.

@Test
public void shouldListActionsWithFilter() throws Exception {
    ActionsFilter filter = new ActionsFilter().withActionName("action-name").withDeployed(true).withInstalled(false).withTriggerId("post-login").withPage(1, 10);
    Request<ActionsPage> request = api.actions().list(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MockServer.ACTIONS_LIST, 200);
    ActionsPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/actions/actions"));
    assertThat(recordedRequest, hasQueryParameter("actionName", "action-name"));
    assertThat(recordedRequest, hasQueryParameter("deployed", "true"));
    assertThat(recordedRequest, hasQueryParameter("installed", "false"));
    assertThat(recordedRequest, hasQueryParameter("triggerId", "post-login"));
    assertThat(recordedRequest, hasQueryParameter("page", "1"));
    assertThat(recordedRequest, hasQueryParameter("per_page", "10"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ActionsFilter(com.auth0.client.mgmt.filter.ActionsFilter) Test(org.junit.Test)

Example 47 with Request

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

the class BlacklistsEntityTest method shouldBlacklistToken.

@Test
public void shouldBlacklistToken() throws Exception {
    Request<Void> request = api.blacklists().blacklistToken(new Token("id"));
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_BLACKLISTED_TOKENS_LIST, 200);
    request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/blacklists/tokens"));
    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("jti", "id"));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Token(com.auth0.json.mgmt.Token) Test(org.junit.Test)

Example 48 with Request

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

the class ClientGrantsEntityTest method shouldCreateClientGrant.

@Test
public void shouldCreateClientGrant() throws Exception {
    Request<ClientGrant> request = api.clientGrants().create("clientId", "audience", new String[] { "openid" });
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_CLIENT_GRANT, 200);
    ClientGrant response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/client-grants"));
    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("client_id", "clientId"));
    assertThat(body, hasEntry("audience", "audience"));
    assertThat(body, hasKey("scope"));
    assertThat((Iterable<?>) body.get("scope"), contains("openid"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ClientGrant(com.auth0.json.mgmt.ClientGrant) Test(org.junit.Test)

Example 49 with Request

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

the class ClientGrantsEntityTest method shouldUpdateClientGrant.

@Test
public void shouldUpdateClientGrant() throws Exception {
    Request<ClientGrant> request = api.clientGrants().update("1", new String[] { "openid", "profile" });
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_CLIENT_GRANT, 200);
    ClientGrant response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("PATCH", "/api/v2/client-grants/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((ArrayList<?>) body.get("scope"), contains("openid", "profile"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ClientGrant(com.auth0.json.mgmt.ClientGrant) Test(org.junit.Test)

Example 50 with Request

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

the class ClientGrantsEntityTest method shouldListClientGrantsWithAdditionalProperties.

@Test
public void shouldListClientGrantsWithAdditionalProperties() throws Exception {
    ClientGrantsFilter filter = new ClientGrantsFilter().withAudience("https://myapi.auth0.com").withClientId("u9e3hh3e9j2fj9092ked");
    Request<ClientGrantsPage> request = api.clientGrants().list(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_CLIENT_GRANTS_LIST, 200);
    ClientGrantsPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/client-grants"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, hasQueryParameter("audience", "https://myapi.auth0.com"));
    assertThat(recordedRequest, hasQueryParameter("client_id", "u9e3hh3e9j2fj9092ked"));
    assertThat(response, is(notNullValue()));
    assertThat(response.getItems(), hasSize(2));
}
Also used : ClientGrantsPage(com.auth0.json.mgmt.ClientGrantsPage) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ClientGrantsFilter(com.auth0.client.mgmt.filter.ClientGrantsFilter) 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