use of org.gluu.oxauth.model.uma.UmaPermission in project oxAuth by GluuFederation.
the class UmaRegisterPermissionFlowHttpTest method testRegisterPermissionForInvalidResource.
/**
* Test for registering permissions for resource
*/
@Test
public void testRegisterPermissionForInvalidResource() throws Exception {
showTitle("testRegisterPermissionForInvalidResource");
UmaPermission permission = new UmaPermission();
permission.setResourceId(this.registerResourceTest.resourceId + "1");
permission.setScopes(Arrays.asList("http://photoz.example.com/dev/scopes/view", "http://photoz.example.com/dev/scopes/all"));
PermissionTicket ticket = null;
try {
ticket = getPermissionService().registerPermission("Bearer " + this.registerResourceTest.pat.getAccessToken(), UmaPermissionList.instance(permission));
} catch (ClientErrorException ex) {
System.err.println(ex.getResponse().readEntity(String.class));
assertTrue(ex.getResponse().getStatus() != Response.Status.CREATED.getStatusCode() && ex.getResponse().getStatus() != Response.Status.OK.getStatusCode(), "Unexpected response status");
}
assertNull(ticket, "Resource permission is not null");
}
use of org.gluu.oxauth.model.uma.UmaPermission in project oxAuth by GluuFederation.
the class RegisterPermissionWSTest method testRegisterPermissionWithInvalidResource.
@Test(dependsOnMethods = { "testRegisterPermission" })
public void testRegisterPermissionWithInvalidResource() {
final String path = umaPermissionPath;
try {
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + path).request();
request.header("Accept", UmaConstants.JSON_MEDIA_TYPE);
request.header("Authorization", "Bearer " + pat.getAccessToken());
String json = null;
try {
final UmaPermission r = new UmaPermission();
r.setResourceId(resource.getId() + "x");
json = ServerUtil.createJsonMapper().writeValueAsString(r);
} catch (IOException e) {
e.printStackTrace();
fail();
}
Response response = request.post(Entity.json(json));
String entity = response.readEntity(String.class);
BaseTest.showResponse("UMA : RegisterPermissionWSTest.testRegisterPermissionWithInvalidResource() : ", response, entity);
assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(), "Unexpected response code.");
try {
final PermissionTicket t = ServerUtil.createJsonMapper().readValue(entity, PermissionTicket.class);
Assert.assertNull(t);
} catch (Exception e) {
// it's ok if it fails here, we expect ticket as null.
}
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
Aggregations