use of javax.ws.rs.client.Invocation.Builder in project oxAuth by GluuFederation.
the class UserInfoRestWebServiceEmbeddedTest method requestUserInfoHS512Step3.
@Parameters({ "userInfoPath" })
@Test(dependsOnMethods = "requestUserInfoHS512Step2")
public void requestUserInfoHS512Step3(final String userInfoPath) throws Exception {
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + userInfoPath).request();
request.header("Authorization", "Bearer " + accessToken7);
request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
UserInfoRequest userInfoRequest = new UserInfoRequest(null);
Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(userInfoRequest.getParameters())));
String entity = response.readEntity(String.class);
showResponse("requestUserInfoHS512Step3", 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 {
Jwt jwt = Jwt.parse(entity);
assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.SUBJECT_IDENTIFIER));
assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.NAME));
assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.EMAIL));
assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.PICTURE));
} catch (InvalidJwtException e) {
e.printStackTrace();
fail(e.getMessage() + "\nResponse was: " + entity);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of javax.ws.rs.client.Invocation.Builder in project oxAuth by GluuFederation.
the class UserInfoRestWebServiceEmbeddedTest method requestUserInfoStep2PasswordFlow.
@Parameters({ "userInfoPath" })
@Test(dependsOnMethods = "requestUserInfoStep1PasswordFlow")
public void requestUserInfoStep2PasswordFlow(final String userInfoPath) throws Exception {
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + userInfoPath).request();
request.header("Authorization", "Bearer " + accessToken4);
request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
UserInfoRequest userInfoRequest = new UserInfoRequest(null);
Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(userInfoRequest.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(JwtClaimName.SUBJECT_IDENTIFIER));
assertTrue(jsonObj.has(JwtClaimName.NAME));
assertTrue(jsonObj.has(JwtClaimName.GIVEN_NAME));
assertTrue(jsonObj.has(JwtClaimName.FAMILY_NAME));
assertTrue(jsonObj.has(JwtClaimName.EMAIL));
} catch (JSONException e) {
e.printStackTrace();
fail(e.getMessage() + "\nResponse was: " + entity);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of javax.ws.rs.client.Invocation.Builder in project oxAuth by GluuFederation.
the class RegistrationRestWebServiceEmbeddedTest method requestClientRegistrationFail2.
@Parameters({ "registerPath" })
@Test
public void requestClientRegistrationFail2(final String registerPath) throws Exception {
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath).request();
String registerRequestContent = null;
try {
// Missing
RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", null);
// redirect
// URIs
registerRequestContent = registerRequest.getJSONParameters().toString(4);
} catch (JSONException e) {
e.printStackTrace();
fail(e.getMessage());
}
Response response = request.post(Entity.json(registerRequestContent));
String entity = response.readEntity(String.class);
showResponse("requestClientRegistrationFail 2", response, entity);
assertEquals(response.getStatus(), 400, "Unexpected response code. " + entity);
TestUtil.assertErrorResponse(entity);
}
use of javax.ws.rs.client.Invocation.Builder in project oxAuth by GluuFederation.
the class RegistrationRestWebServiceEmbeddedTest method requestClientRegistrationFail1.
@Parameters({ "registerPath" })
@Test
public void requestClientRegistrationFail1(final String registerPath) throws Exception {
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath).request();
String registerRequestContent = null;
try {
RegisterRequest registerRequest = new RegisterRequest(null, null, null);
registerRequestContent = registerRequest.getJSONParameters().toString(4);
} catch (JSONException e) {
e.printStackTrace();
fail(e.getMessage());
}
Response response = request.post(Entity.json(registerRequestContent));
String entity = response.readEntity(String.class);
showResponse("requestClientRegistrationFail 1", response, entity);
assertEquals(response.getStatus(), 400, "Unexpected response code. " + entity);
TestUtil.assertErrorResponse(entity);
}
use of javax.ws.rs.client.Invocation.Builder in project oxAuth by GluuFederation.
the class RegistrationRestWebServiceEmbeddedTest method requestClientUpdate.
@Parameters({ "registerPath", "redirectUris", "contactEmail1", "contactEmail2" })
@Test(dependsOnMethods = "requestClientAssociate1")
public void requestClientUpdate(final String registerPath, final String redirectUris, final String contactEmail1, final String contactEmail2) throws Exception {
final String contactEmailNewValue = contactEmail2;
final String logoUriNewValue = "http://www.gluu.org/test/yuriy/logo.png";
final String clientUriNewValue = "http://www.gluu.org/company/yuriy";
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath + "?" + registrationClientUri1.substring(registrationClientUri1.indexOf("?") + 1)).request();
String registerRequestContent = null;
try {
final RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris));
registerRequest.setContacts(Arrays.asList(contactEmail1, contactEmailNewValue));
registerRequest.setLogoUri(logoUriNewValue);
registerRequest.setClientUri(clientUriNewValue);
request.header("Authorization", "Bearer " + registrationAccessToken1);
registerRequestContent = registerRequest.getJSONParameters().toString(4);
} catch (Exception e) {
e.printStackTrace();
fail();
}
Response response = request.put(Entity.json(registerRequestContent));
String entity = response.readEntity(String.class);
showResponse("requestClientRead", response, entity);
readResponseAssert(response, entity);
try {
// check whether values are really updated
RegisterRequest r = RegisterRequest.fromJson(entity);
assertTrue(r.getContacts() != null && r.getContacts().contains(contactEmailNewValue));
assertTrue(r.getClientUri().equals(clientUriNewValue));
assertTrue(r.getLogoUri().equals(logoUriNewValue));
} catch (JSONException e) {
e.printStackTrace();
fail(e.getMessage() + "\nResponse was: " + entity);
}
}
Aggregations