use of org.camunda.bpm.engine.identity.UserQuery in project camunda-bpm-platform by camunda.
the class UserRestServiceInteractionTest method testUserResourceOptionsUnauthorized.
@Test
public void testUserResourceOptionsUnauthorized() {
String fullUserUrl = "http://localhost:" + PORT + TEST_RESOURCE_ROOT_PATH + "/user/" + MockProvider.EXAMPLE_USER_ID;
User sampleUser = MockProvider.createMockUser();
UserQuery sampleUserQuery = mock(UserQuery.class);
when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
when(sampleUserQuery.singleResult()).thenReturn(sampleUser);
Authentication authentication = new Authentication(MockProvider.EXAMPLE_USER_ID, null);
when(identityServiceMock.getCurrentAuthentication()).thenReturn(authentication);
when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, DELETE, USER, MockProvider.EXAMPLE_USER_ID)).thenReturn(false);
when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, UPDATE, USER, MockProvider.EXAMPLE_USER_ID)).thenReturn(false);
when(processEngineConfigurationMock.isAuthorizationEnabled()).thenReturn(true);
given().pathParam("id", MockProvider.EXAMPLE_USER_ID).then().statusCode(Status.OK.getStatusCode()).body("links[0].href", equalTo(fullUserUrl + "/profile")).body("links[0].method", equalTo(HttpMethod.GET)).body("links[0].rel", equalTo("self")).body("links[1]", nullValue()).body("links[2]", nullValue()).when().options(USER_URL);
verify(identityServiceMock, times(2)).getCurrentAuthentication();
verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, DELETE, USER, MockProvider.EXAMPLE_USER_ID);
verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, UPDATE, USER, MockProvider.EXAMPLE_USER_ID);
}
use of org.camunda.bpm.engine.identity.UserQuery in project camunda-bpm-platform by camunda.
the class UserRestServiceInteractionTest method testPutProfileNonexistingFails.
@Test
public void testPutProfileNonexistingFails() {
User userUpdate = MockProvider.createMockUserUpdate();
UserQuery sampleUserQuery = mock(UserQuery.class);
when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
when(sampleUserQuery.userId("aNonExistingUser")).thenReturn(sampleUserQuery);
when(sampleUserQuery.singleResult()).thenReturn(null);
UserProfileDto updateDto = UserProfileDto.fromUser(userUpdate);
given().pathParam("id", "aNonExistingUser").body(updateDto).contentType(ContentType.JSON).then().then().expect().statusCode(Status.NOT_FOUND.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(InvalidRequestException.class.getSimpleName())).body("message", equalTo("User with id aNonExistingUser does not exist")).when().put(USER_PROFILE_URL);
// nothing was saved
verify(identityServiceMock, never()).saveUser(any(User.class));
}
use of org.camunda.bpm.engine.identity.UserQuery in project camunda-bpm-platform by camunda.
the class UserRestServiceInteractionTest method testGetNonExistingUserProfile.
@Test
public void testGetNonExistingUserProfile() {
UserQuery sampleUserQuery = mock(UserQuery.class);
when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
when(sampleUserQuery.userId(anyString())).thenReturn(sampleUserQuery);
when(sampleUserQuery.singleResult()).thenReturn(null);
given().pathParam("id", "aNonExistingUser").then().statusCode(Status.NOT_FOUND.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(InvalidRequestException.class.getSimpleName())).body("message", equalTo("User with id aNonExistingUser does not exist")).when().get(USER_PROFILE_URL);
}
use of org.camunda.bpm.engine.identity.UserQuery in project camunda-bpm-platform by camunda.
the class UserRestServiceInteractionTest method testPutCredentials.
@Test
public void testPutCredentials() {
User initialUser = MockProvider.createMockUser();
UserQuery sampleUserQuery = mock(UserQuery.class);
when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
when(sampleUserQuery.singleResult()).thenReturn(initialUser);
UserCredentialsDto dto = new UserCredentialsDto();
dto.setPassword("new-password");
given().pathParam("id", MockProvider.EXAMPLE_USER_ID).body(dto).contentType(ContentType.JSON).then().statusCode(Status.NO_CONTENT.getStatusCode()).when().put(USER_CREDENTIALS_URL);
// password was updated
verify(initialUser).setPassword(dto.getPassword());
// and then saved
verify(identityServiceMock).saveUser(initialUser);
}
use of org.camunda.bpm.engine.identity.UserQuery in project camunda-bpm-platform by camunda.
the class UserRestServiceInteractionTest method testPutProfile.
@Test
public void testPutProfile() {
User initialUser = MockProvider.createMockUser();
User userUpdate = MockProvider.createMockUserUpdate();
UserQuery sampleUserQuery = mock(UserQuery.class);
when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
when(sampleUserQuery.singleResult()).thenReturn(initialUser);
UserProfileDto updateDto = UserProfileDto.fromUser(userUpdate);
given().pathParam("id", MockProvider.EXAMPLE_USER_ID).body(updateDto).contentType(ContentType.JSON).then().statusCode(Status.NO_CONTENT.getStatusCode()).when().put(USER_PROFILE_URL);
// password was updated
verify(initialUser).setEmail(updateDto.getEmail());
verify(initialUser).setFirstName(updateDto.getFirstName());
verify(initialUser).setLastName(updateDto.getLastName());
// and then saved
verify(identityServiceMock).saveUser(initialUser);
}
Aggregations