use of org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto in project camunda-bpm-platform by camunda.
the class UserRestServiceInteractionTest method testChangeCredentialsWithWrongAuthenticatedUserPassword.
@Test
public void testChangeCredentialsWithWrongAuthenticatedUserPassword() {
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);
Authentication authentication = MockProvider.createMockAuthentication();
when(identityServiceMock.getCurrentAuthentication()).thenReturn(authentication);
when(identityServiceMock.checkPassword(MockProvider.EXAMPLE_USER_ID, MockProvider.EXAMPLE_USER_PASSWORD)).thenReturn(false);
UserCredentialsDto dto = new UserCredentialsDto();
dto.setPassword("new-password");
dto.setAuthenticatedUserPassword(MockProvider.EXAMPLE_USER_PASSWORD);
given().pathParam("id", MockProvider.EXAMPLE_USER_ID).contentType(ContentType.JSON).body(dto).then().statusCode(Status.BAD_REQUEST.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo("InvalidRequestException")).body("message", equalTo("The given authenticated user password is not valid.")).when().put(USER_CREDENTIALS_URL);
}
use of org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto in project camunda-bpm-platform by camunda.
the class UserRestServiceInteractionTest method testPutCredentialsNonExistingUserFails.
@Test
public void testPutCredentialsNonExistingUserFails() {
UserQuery sampleUserQuery = mock(UserQuery.class);
when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
when(sampleUserQuery.userId("aNonExistingUser")).thenReturn(sampleUserQuery);
when(sampleUserQuery.singleResult()).thenReturn(null);
UserCredentialsDto dto = new UserCredentialsDto();
dto.setPassword("new-password");
given().pathParam("id", "aNonExistingUser").body(dto).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_CREDENTIALS_URL);
// user was not updated
verify(identityServiceMock, never()).saveUser(any(User.class));
}
use of org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto in project camunda-bpm-platform by camunda.
the class UserRestServiceInteractionTest method testChangeCredentials.
@Test
public void testChangeCredentials() {
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);
Authentication authentication = MockProvider.createMockAuthentication();
when(identityServiceMock.getCurrentAuthentication()).thenReturn(authentication);
when(identityServiceMock.checkPassword(MockProvider.EXAMPLE_USER_ID, MockProvider.EXAMPLE_USER_PASSWORD)).thenReturn(true);
UserCredentialsDto dto = new UserCredentialsDto();
dto.setPassword("new-password");
dto.setAuthenticatedUserPassword(MockProvider.EXAMPLE_USER_PASSWORD);
given().pathParam("id", MockProvider.EXAMPLE_USER_ID).contentType(ContentType.JSON).body(dto).then().statusCode(Status.NO_CONTENT.getStatusCode()).when().put(USER_CREDENTIALS_URL);
verify(identityServiceMock).getCurrentAuthentication();
verify(identityServiceMock).checkPassword(MockProvider.EXAMPLE_USER_ID, MockProvider.EXAMPLE_USER_PASSWORD);
// password was updated
verify(initialUser).setPassword(dto.getPassword());
// and then saved
verify(identityServiceMock).saveUser(initialUser);
}
use of org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto in project camunda-bpm-platform by camunda.
the class TestUtil method createInitialUser.
public void createInitialUser(String id, String password, String firstName, String lastName) {
UserDto user = new UserDto();
UserCredentialsDto credentials = new UserCredentialsDto();
credentials.setPassword(password);
user.setCredentials(credentials);
UserProfileDto profile = new UserProfileDto();
profile.setId(id);
profile.setFirstName(firstName);
profile.setLastName(lastName);
user.setProfile(profile);
WebResource webResource = client.resource(testProperties.getApplicationPath("/camunda/api/admin/setup/default/user/create"));
ClientResponse clientResponse = webResource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post(ClientResponse.class, user);
try {
if (clientResponse.getResponseStatus() != Response.Status.NO_CONTENT) {
throw new WebApplicationException(clientResponse.getResponseStatus());
}
} finally {
clientResponse.close();
}
}
use of org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto 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);
}
Aggregations