use of org.camunda.bpm.engine.identity.GroupQuery in project camunda-bpm-platform by camunda.
the class GroupRestServiceInteractionTest method testUpdateGroupThrowsAuthorizationException.
@Test
public void testUpdateGroupThrowsAuthorizationException() {
Group initialGroup = MockProvider.createMockGroup();
Group groupUpdate = MockProvider.createMockGroupUpdate();
GroupQuery sampleGroupQuery = mock(GroupQuery.class);
when(identityServiceMock.createGroupQuery()).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.groupId(MockProvider.EXAMPLE_GROUP_ID)).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.singleResult()).thenReturn(initialGroup);
String message = "exception expected";
doThrow(new AuthorizationException(message)).when(identityServiceMock).saveGroup(any(Group.class));
given().pathParam("id", MockProvider.EXAMPLE_GROUP_ID).body(GroupDto.fromGroup(groupUpdate)).contentType(ContentType.JSON).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(AuthorizationException.class.getSimpleName())).body("message", equalTo(message)).when().put(GROUP_URL);
// initial group was updated
verify(initialGroup).setName(groupUpdate.getName());
}
use of org.camunda.bpm.engine.identity.GroupQuery in project camunda-bpm-platform by camunda.
the class GroupRestServiceInteractionTest method testGetSingleGroup.
@Test
public void testGetSingleGroup() {
Group sampleGroup = MockProvider.createMockGroup();
GroupQuery sampleGroupQuery = mock(GroupQuery.class);
when(identityServiceMock.createGroupQuery()).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.groupId(MockProvider.EXAMPLE_GROUP_ID)).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.singleResult()).thenReturn(sampleGroup);
given().pathParam("id", MockProvider.EXAMPLE_GROUP_ID).then().expect().statusCode(Status.OK.getStatusCode()).body("id", equalTo(MockProvider.EXAMPLE_GROUP_ID)).body("name", equalTo(MockProvider.EXAMPLE_GROUP_NAME)).when().get(GROUP_URL);
}
use of org.camunda.bpm.engine.identity.GroupQuery in project camunda-bpm-platform by camunda.
the class GroupRestServiceInteractionTest method testGroupMembersResourceOptionsAuthorized.
@Test
public void testGroupMembersResourceOptionsAuthorized() {
String fullMembersUrl = "http://localhost:" + PORT + TEST_RESOURCE_ROOT_PATH + "/group/" + MockProvider.EXAMPLE_GROUP_ID + "/members";
Authentication authentication = new Authentication(MockProvider.EXAMPLE_USER_ID, null);
when(identityServiceMock.getCurrentAuthentication()).thenReturn(authentication);
when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, DELETE, GROUP_MEMBERSHIP, MockProvider.EXAMPLE_GROUP_ID)).thenReturn(true);
when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, CREATE, GROUP_MEMBERSHIP, MockProvider.EXAMPLE_GROUP_ID)).thenReturn(true);
Group sampleGroup = MockProvider.createMockGroup();
GroupQuery sampleGroupQuery = mock(GroupQuery.class);
when(identityServiceMock.createGroupQuery()).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.groupId(MockProvider.EXAMPLE_GROUP_ID)).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.singleResult()).thenReturn(sampleGroup);
when(processEngineConfigurationMock.isAuthorizationEnabled()).thenReturn(true);
given().pathParam("id", MockProvider.EXAMPLE_GROUP_ID).then().expect().statusCode(Status.OK.getStatusCode()).body("links[0].href", equalTo(fullMembersUrl)).body("links[0].method", equalTo(HttpMethod.GET)).body("links[0].rel", equalTo("self")).body("links[1].href", equalTo(fullMembersUrl)).body("links[1].method", equalTo(HttpMethod.DELETE)).body("links[1].rel", equalTo("delete")).body("links[2].href", equalTo(fullMembersUrl)).body("links[2].method", equalTo(HttpMethod.PUT)).body("links[2].rel", equalTo("create")).when().options(GROUP_MEMBERS_URL);
verify(identityServiceMock, times(2)).getCurrentAuthentication();
verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, DELETE, GROUP_MEMBERSHIP, MockProvider.EXAMPLE_GROUP_ID);
verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, CREATE, GROUP_MEMBERSHIP, MockProvider.EXAMPLE_GROUP_ID);
}
use of org.camunda.bpm.engine.identity.GroupQuery in project camunda-bpm-platform by camunda.
the class GroupRestServiceInteractionTest method testUpdateExistingGroup.
@Test
public void testUpdateExistingGroup() {
Group initialGroup = MockProvider.createMockGroup();
Group groupUpdate = MockProvider.createMockGroupUpdate();
GroupQuery sampleGroupQuery = mock(GroupQuery.class);
when(identityServiceMock.createGroupQuery()).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.groupId(MockProvider.EXAMPLE_GROUP_ID)).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.singleResult()).thenReturn(initialGroup);
given().pathParam("id", MockProvider.EXAMPLE_GROUP_ID).body(GroupDto.fromGroup(groupUpdate)).contentType(ContentType.JSON).then().expect().statusCode(Status.NO_CONTENT.getStatusCode()).when().put(GROUP_URL);
// initial group was updated
verify(initialGroup).setName(groupUpdate.getName());
// and then saved
verify(identityServiceMock).saveGroup(initialGroup);
}
use of org.camunda.bpm.engine.identity.GroupQuery in project camunda-bpm-platform by camunda.
the class GroupRestServiceInteractionTest method testGroupResourceOptionsUnauthorized.
@Test
public void testGroupResourceOptionsUnauthorized() {
String fullGroupUrl = "http://localhost:" + PORT + TEST_RESOURCE_ROOT_PATH + "/group/" + MockProvider.EXAMPLE_GROUP_ID;
Authentication authentication = new Authentication(MockProvider.EXAMPLE_USER_ID, null);
when(identityServiceMock.getCurrentAuthentication()).thenReturn(authentication);
when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, DELETE, GROUP, MockProvider.EXAMPLE_GROUP_ID)).thenReturn(false);
when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, UPDATE, GROUP, MockProvider.EXAMPLE_GROUP_ID)).thenReturn(false);
Group sampleGroup = MockProvider.createMockGroup();
GroupQuery sampleGroupQuery = mock(GroupQuery.class);
when(identityServiceMock.createGroupQuery()).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.groupId(MockProvider.EXAMPLE_GROUP_ID)).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.singleResult()).thenReturn(sampleGroup);
when(processEngineConfigurationMock.isAuthorizationEnabled()).thenReturn(true);
given().pathParam("id", MockProvider.EXAMPLE_GROUP_ID).then().expect().statusCode(Status.OK.getStatusCode()).body("links[0].href", equalTo(fullGroupUrl)).body("links[0].method", equalTo(HttpMethod.GET)).body("links[0].rel", equalTo("self")).body("links[1]", nullValue()).body("links[2]", nullValue()).when().options(GROUP_URL);
verify(identityServiceMock, times(2)).getCurrentAuthentication();
verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, DELETE, GROUP, MockProvider.EXAMPLE_GROUP_ID);
verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, UPDATE, GROUP, MockProvider.EXAMPLE_GROUP_ID);
}
Aggregations