use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.
the class UserV1ControllerTest method synchronizeAllUsersRejected.
@Test
void synchronizeAllUsersRejected() {
Set<String> environments = Set.of(ENV_CRN);
Set<String> users = Set.of(USER_CRN);
SynchronizeAllUsersRequest request = new SynchronizeAllUsersRequest();
request.setEnvironments(environments);
request.setUsers(users);
Operation operation = mock(Operation.class);
UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(users, Set.of(), Optional.empty());
when(userSyncService.synchronizeUsersWithCustomPermissionCheck(ACCOUNT_ID, USER_CRN, environments, userSyncFilter, WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED, AuthorizationResourceAction.DESCRIBE_ENVIRONMENT)).thenReturn(operation);
SyncOperationStatus status = mock(SyncOperationStatus.class);
when(status.getStatus()).thenReturn(SynchronizationStatus.REJECTED);
when(operationToSyncOperationStatus.convert(operation)).thenReturn(status);
assertThrows(SyncOperationAlreadyRunningException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.synchronizeAllUsers(request)));
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.
the class UserV1ControllerTest method setPassword.
@Test
void setPassword() {
String password = "password";
SetPasswordRequest request = mock(SetPasswordRequest.class);
when(request.getPassword()).thenReturn(password);
Operation operation = mock(Operation.class);
when(passwordService.setPasswordWithCustomPermissionCheck(any(), any(), any(), any(), any())).thenReturn(operation);
SyncOperationStatus status = mock(SyncOperationStatus.class);
when(operationToSyncOperationStatus.convert(operation)).thenReturn(status);
assertEquals(status, ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.setPassword(request)));
verify(passwordService, times(1)).setPasswordWithCustomPermissionCheck(ACCOUNT_ID, USER_CRN, password, new HashSet<>(), AuthorizationResourceAction.DESCRIBE_ENVIRONMENT);
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.
the class UserV1ControllerTest method synchronizeUser.
@Test
void synchronizeUser() {
Operation operation = mock(Operation.class);
when(userSyncService.synchronizeUsersWithCustomPermissionCheck(any(), any(), any(), any(), any(), any())).thenReturn(operation);
SyncOperationStatus status = mock(SyncOperationStatus.class);
when(operationToSyncOperationStatus.convert(operation)).thenReturn(status);
SynchronizeUserRequest request = mock(SynchronizeUserRequest.class);
assertEquals(status, ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.synchronizeUser(request)));
UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(Set.of(USER_CRN), Set.of(), Optional.empty());
verify(userSyncService, times(1)).synchronizeUsersWithCustomPermissionCheck(ACCOUNT_ID, USER_CRN, Set.of(), userSyncFilter, WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED, AuthorizationResourceAction.DESCRIBE_ENVIRONMENT);
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.
the class FreeIpaSetPasswordAction method action.
public FreeIpaUserSyncTestDto action(TestContext testContext, FreeIpaUserSyncTestDto testDto, FreeIpaClient client) throws Exception {
SetPasswordRequest setPasswordRequest = testDto.setPassword(environmentCrns, newPassword);
Log.when(LOGGER, format(" List of environment Crns: [%s], freeIpa Crn: %s", environmentCrns, testDto.getRequest().getEnvironments()));
Log.whenJson(LOGGER, format(" FreeIPA set password request: %n"), setPasswordRequest);
SyncOperationStatus syncOperationStatus = client.getDefaultClient().getUserV1Endpoint().setPassword(setPasswordRequest);
testDto.setOperationId(syncOperationStatus.getOperationId());
LOGGER.info("Sync is in state: [{}], sync operation: [{}] with type: [{}]", syncOperationStatus.getStatus(), syncOperationStatus.getOperationId(), syncOperationStatus.getSyncOperationType());
Log.when(LOGGER, format(" Sync is in state: [%s], sync operation: [%s] with type: [%s]", syncOperationStatus.getStatus(), syncOperationStatus.getOperationId(), syncOperationStatus.getSyncOperationType()));
return testDto;
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.
the class FreeIpaSynchronizeAllUsersAction method action.
public FreeIpaUserSyncTestDto action(TestContext testContext, FreeIpaUserSyncTestDto testDto, FreeIpaClient client) throws Exception {
Log.when(LOGGER, format(" Environment Crn: [%s], freeIpa Crn: %s", testDto.getEnvironmentCrn(), testDto.getRequest().getEnvironments()));
Log.whenJson(LOGGER, format(" FreeIPA sync request: %n"), testDto.getRequest());
// checking if there is ongoing usersync
EnvironmentUserSyncState environmentUserSyncState = client.getDefaultClient().getUserV1Endpoint().getUserSyncState(testDto.getEnvironmentCrn());
if (UserSyncState.SYNC_IN_PROGRESS.equals(environmentUserSyncState.getState())) {
// sync already in progress, no need to execute another one
testDto.setOperationId(environmentUserSyncState.getLastUserSyncOperationId());
LOGGER.info("Sync is in state: [{}], sync operation: [{}]", environmentUserSyncState.getState(), environmentUserSyncState.getLastUserSyncOperationId());
Log.when(LOGGER, format(" Sync is in state: [%s], sync operation: [%s]", environmentUserSyncState.getState(), environmentUserSyncState.getLastUserSyncOperationId()));
} else {
try {
// need to sync
SyncOperationStatus syncOperationStatus = client.getDefaultClient().getUserV1Endpoint().synchronizeAllUsers(testDto.getRequest());
testDto.setOperationId(syncOperationStatus.getOperationId());
LOGGER.info("Sync is in state: [{}], sync operation id: [{}] with type: [{}]", syncOperationStatus.getStatus(), syncOperationStatus.getOperationId(), syncOperationStatus.getSyncOperationType());
Log.when(LOGGER, format(" Sync is in state: [%s], sync operation id: [%s] with type: [%s]", syncOperationStatus.getStatus(), syncOperationStatus.getOperationId(), syncOperationStatus.getSyncOperationType()));
} catch (ClientErrorException e) {
// still can happen that a concurrent user sync got initiated
if (e.getResponse() != null && HttpStatus.CONFLICT.value() == e.getResponse().getStatus()) {
LOGGER.info("Sync were already initiated for environment {}", testDto.getEnvironmentCrn());
} else {
throw e;
}
}
}
return testDto;
}
Aggregations