}
@Test
public void update() {
// 1. create an user (as admin)
UserTO userTO = UserTestITCase.getUniqueSampleTO("selfupdate@syncope.apache.org");
String initialPassword = userTO.getPassword();
userTO = createUser(userTO);
assertNotNull(userTO);
UserMod userMod = new UserMod();
userMod.setId(userTO.getId());
userMod.setPassword(initialPassword);
// 2. try to request user update as admin: failure
try {
createUserRequest(userRequestService, new UserRequestTO(userMod));
fail();
} catch (SyncopeClientCompositeErrorException e) {
assertNotNull(e.getException(SyncopeClientExceptionType.UnauthorizedRole));
}
// 3. auth as user just created
UserRequestService userRequestService2 = setupCredentials(userRequestService, UserRequestService.class,
userTO.getUsername(), initialPassword);
// 4. update with same password: not matching password policy
try {
createUserRequest(userRequestService2, new UserRequestTO(userMod));
fail();
} catch (SyncopeClientCompositeErrorException scce) {
assertNotNull(scce.getException(SyncopeClientExceptionType.InvalidSyncopeUser));
}
// 5. now request user update works
userMod.setPassword("new" + initialPassword);
createUserRequest(userRequestService2, new UserRequestTO(userMod));
// 6. switch back to admin
super.resetRestTemplate();
// 7. user password has not changed yet
UserService userService1 = super.setupCredentials(userService, UserService.class, userTO.getUsername(),
userMod.getPassword());
try {
userService1.readSelf();
fail("Credentials are not updated yet, thus request should raise AccessControlException");
} catch (AccessControlException e) {
assertNotNull(e);
}
resetRestTemplate();
// 8. actually update user
userTO = userService.update(userMod.getId(), userMod);
assertNotNull(userTO);
// 9. user password has now changed
UserService userService2 = super.setupCredentials(userService, UserService.class, userTO.getUsername(),
userMod.getPassword());
try {
UserTO user = userService2.readSelf();
assertNotNull(user);
} catch (AccessControlException e) {
fail("Credentials should be valid and not cause AccessControlException");
}
}