Search in sources :

Example 1 with ClientInfoRequest

use of org.xdi.oxauth.client.ClientInfoRequest in project oxAuth by GluuFederation.

the class ClientInfoRestWebServiceEmbeddedTest method requestClientInfoStep2PostImplicitFlow.

@Parameters({ "clientInfoPath" })
@Test(dependsOnMethods = "requestClientInfoStep1ImplicitFlow")
public void requestClientInfoStep2PostImplicitFlow(final String clientInfoPath) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + clientInfoPath).request();
    request.header("Authorization", "Bearer " + accessToken1);
    request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
    ClientInfoRequest clientInfoRequest = new ClientInfoRequest(null);
    Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(clientInfoRequest.getParameters())));
    String entity = response.readEntity(String.class);
    showResponse("requestClientInfo step 2 POST Implicit Flow", response, entity);
    assertEquals(response.getStatus(), 200, "Unexpected response code.");
    assertTrue(response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store, private"), "Unexpected result: " + response.getHeaderString("Cache-Control"));
    assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma"));
    assertNotNull(entity, "Unexpected result: " + entity);
    try {
        JSONObject jsonObj = new JSONObject(entity);
        assertTrue(jsonObj.has("displayName"), "Unexpected result: displayName not found");
        assertTrue(jsonObj.has("inum"), "Unexpected result: inum not found");
        assertTrue(jsonObj.has("oxAuthAppType"), "Unexpected result: oxAuthAppType not found");
        assertTrue(jsonObj.has("oxAuthIdTokenSignedResponseAlg"), "Unexpected result: oxAuthIdTokenSignedResponseAlg not found");
        assertTrue(jsonObj.has("oxAuthRedirectURI"), "Unexpected result: oxAuthRedirectURI not found");
        assertTrue(jsonObj.has("oxAuthScope"), "Unexpected result: oxAuthScope not found");
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage() + "\nResponse was: " + entity);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : RegisterResponse(org.xdi.oxauth.client.RegisterResponse) Response(javax.ws.rs.core.Response) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) JSONObject(org.codehaus.jettison.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.codehaus.jettison.json.JSONException) ClientInfoRequest(org.xdi.oxauth.client.ClientInfoRequest) URISyntaxException(java.net.URISyntaxException) JSONException(org.codehaus.jettison.json.JSONException) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 2 with ClientInfoRequest

use of org.xdi.oxauth.client.ClientInfoRequest in project oxAuth by GluuFederation.

the class ClientInfoRestWebServiceEmbeddedTest method requestClientInfoInvalidRequest.

@Parameters({ "clientInfoPath" })
@Test
public void requestClientInfoInvalidRequest(final String clientInfoPath) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + clientInfoPath).request();
    request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
    ClientInfoRequest clientInfoRequest = new ClientInfoRequest(null);
    Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(clientInfoRequest.getParameters())));
    String entity = response.readEntity(String.class);
    showResponse("requestClientInfoInvalidRequest", response, entity);
    assertEquals(response.getStatus(), 400, "Unexpected response code.");
    assertNotNull(entity, "Unexpected result: " + entity);
    try {
        JSONObject jsonObj = new JSONObject(entity);
        assertTrue(jsonObj.has("error"), "The error type is null");
        assertTrue(jsonObj.has("error_description"), "The error description is null");
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage() + "\nResponse was: " + entity);
    }
}
Also used : RegisterResponse(org.xdi.oxauth.client.RegisterResponse) Response(javax.ws.rs.core.Response) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) JSONObject(org.codehaus.jettison.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.codehaus.jettison.json.JSONException) ClientInfoRequest(org.xdi.oxauth.client.ClientInfoRequest) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 3 with ClientInfoRequest

use of org.xdi.oxauth.client.ClientInfoRequest in project oxAuth by GluuFederation.

the class ClientInfoRestWebServiceEmbeddedTest method requestClientInfoStep2GetImplicitFlow.

@Parameters({ "clientInfoPath" })
@Test(dependsOnMethods = "requestClientInfoStep1ImplicitFlow")
public void requestClientInfoStep2GetImplicitFlow(final String clientInfoPath) throws Exception {
    ClientInfoRequest clientInfoRequest = new ClientInfoRequest(null);
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + clientInfoPath + "?" + clientInfoRequest.getQueryString()).request();
    request.header("Authorization", "Bearer " + accessToken1);
    request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
    Response response = request.get();
    String entity = response.readEntity(String.class);
    showResponse("requestClientInfo step 2 GET Implicit Flow", response, entity);
    assertEquals(response.getStatus(), 200, "Unexpected response code.");
    assertTrue(response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store, private"), "Unexpected result: " + response.getHeaderString("Cache-Control"));
    assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma"));
    assertNotNull(entity, "Unexpected result: " + entity);
    try {
        JSONObject jsonObj = new JSONObject(entity);
        assertTrue(jsonObj.has("displayName"), "Unexpected result: displayName not found");
        assertTrue(jsonObj.has("inum"), "Unexpected result: inum not found");
        assertTrue(jsonObj.has("oxAuthAppType"), "Unexpected result: oxAuthAppType not found");
        assertTrue(jsonObj.has("oxAuthIdTokenSignedResponseAlg"), "Unexpected result: oxAuthIdTokenSignedResponseAlg not found");
        assertTrue(jsonObj.has("oxAuthRedirectURI"), "Unexpected result: oxAuthRedirectURI not found");
        assertTrue(jsonObj.has("oxAuthScope"), "Unexpected result: oxAuthScope not found");
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage() + "\nResponse was: " + entity);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : RegisterResponse(org.xdi.oxauth.client.RegisterResponse) Response(javax.ws.rs.core.Response) JSONObject(org.codehaus.jettison.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.codehaus.jettison.json.JSONException) ClientInfoRequest(org.xdi.oxauth.client.ClientInfoRequest) URISyntaxException(java.net.URISyntaxException) JSONException(org.codehaus.jettison.json.JSONException) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 4 with ClientInfoRequest

use of org.xdi.oxauth.client.ClientInfoRequest in project oxAuth by GluuFederation.

the class ClientInfoRestWebServiceEmbeddedTest method requestClientInfoInvalidToken.

@Parameters({ "clientInfoPath" })
@Test
public void requestClientInfoInvalidToken(final String clientInfoPath) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + clientInfoPath).request();
    request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
    ClientInfoRequest clientInfoRequest = new ClientInfoRequest("INVALID-TOKEN");
    clientInfoRequest.setAuthorizationMethod(AuthorizationMethod.FORM_ENCODED_BODY_PARAMETER);
    Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(clientInfoRequest.getParameters())));
    String entity = response.readEntity(String.class);
    showResponse("requestClientInfoInvalidToken", response, entity);
    assertEquals(response.getStatus(), 400, "Unexpected response code.");
    assertNotNull(entity, "Unexpected result: " + entity);
    try {
        JSONObject jsonObj = new JSONObject(entity);
        assertTrue(jsonObj.has("error"), "The error type is null");
        assertTrue(jsonObj.has("error_description"), "The error description is null");
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage() + "\nResponse was: " + entity);
    }
}
Also used : RegisterResponse(org.xdi.oxauth.client.RegisterResponse) Response(javax.ws.rs.core.Response) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) JSONObject(org.codehaus.jettison.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.codehaus.jettison.json.JSONException) ClientInfoRequest(org.xdi.oxauth.client.ClientInfoRequest) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 5 with ClientInfoRequest

use of org.xdi.oxauth.client.ClientInfoRequest in project oxAuth by GluuFederation.

the class ClientInfoRestWebServiceEmbeddedTest method requestClientInfoStep2PasswordFlow.

@Parameters({ "clientInfoPath" })
@Test(dependsOnMethods = "requestClientInfoStep1PasswordFlow")
public void requestClientInfoStep2PasswordFlow(final String clientInfoPath) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + clientInfoPath).request();
    request.header("Authorization", "Bearer " + accessToken3);
    request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
    ClientInfoRequest clientInfoRequest = new ClientInfoRequest(null);
    Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(clientInfoRequest.getParameters())));
    String entity = response.readEntity(String.class);
    showResponse("requestUserInfoStep2PasswordFlow", response, entity);
    assertEquals(response.getStatus(), 200, "Unexpected response code.");
    assertTrue(response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store, private"), "Unexpected result: " + response.getHeaderString("Cache-Control"));
    assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma"));
    assertNotNull(entity, "Unexpected result: " + entity);
    try {
        JSONObject jsonObj = new JSONObject(entity);
        assertTrue(jsonObj.has("displayName"), "Unexpected result: displayName not found");
        assertTrue(jsonObj.has("inum"), "Unexpected result: inum not found");
        assertTrue(jsonObj.has("oxAuthAppType"), "Unexpected result: oxAuthAppType not found");
        assertTrue(jsonObj.has("oxAuthIdTokenSignedResponseAlg"), "Unexpected result: oxAuthIdTokenSignedResponseAlg not found");
        assertTrue(jsonObj.has("oxAuthRedirectURI"), "Unexpected result: oxAuthRedirectURI not found");
        assertTrue(jsonObj.has("oxAuthScope"), "Unexpected result: oxAuthScope not found");
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage() + "\nResponse was: " + entity);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : RegisterResponse(org.xdi.oxauth.client.RegisterResponse) Response(javax.ws.rs.core.Response) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) JSONObject(org.codehaus.jettison.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.codehaus.jettison.json.JSONException) ClientInfoRequest(org.xdi.oxauth.client.ClientInfoRequest) URISyntaxException(java.net.URISyntaxException) JSONException(org.codehaus.jettison.json.JSONException) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Aggregations

Builder (javax.ws.rs.client.Invocation.Builder)5 Response (javax.ws.rs.core.Response)5 JSONException (org.codehaus.jettison.json.JSONException)5 JSONObject (org.codehaus.jettison.json.JSONObject)5 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)5 Parameters (org.testng.annotations.Parameters)5 Test (org.testng.annotations.Test)5 BaseTest (org.xdi.oxauth.BaseTest)5 ClientInfoRequest (org.xdi.oxauth.client.ClientInfoRequest)5 RegisterResponse (org.xdi.oxauth.client.RegisterResponse)5 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)4 URISyntaxException (java.net.URISyntaxException)3