use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.
the class EnvironmentUserSyncStateCalculatorTest method internalCalculateEnvironmentUserSyncStateLastSyncRunning.
@Test
void internalCalculateEnvironmentUserSyncStateLastSyncRunning() {
UserSyncStatus userSyncStatus = new UserSyncStatus();
Operation lastSync = new Operation();
lastSync.setOperationId(UUID.randomUUID().toString());
lastSync.setStatus(OperationState.RUNNING);
userSyncStatus.setLastStartedFullSync(lastSync);
EnvironmentUserSyncState result = underTest.internalCalculateEnvironmentUserSyncState(ACCOUNT_ID, ENVIRONMENT_CRN, Optional.of(userSyncStatus));
assertEquals(UserSyncState.SYNC_IN_PROGRESS, result.getState());
assertEquals(lastSync.getOperationId(), result.getLastUserSyncOperationId());
}
use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.
the class EnvironmentUserSyncStateCalculatorTest method internalCalculateEnvironmentUserSyncStateLastSyncCompletedSuccessInSync.
@Test
void internalCalculateEnvironmentUserSyncStateLastSyncCompletedSuccessInSync() {
UserSyncStatus userSyncStatus = new UserSyncStatus();
Operation lastSync = new Operation();
lastSync.setOperationId(UUID.randomUUID().toString());
lastSync.setStatus(OperationState.COMPLETED);
lastSync.setSuccessList(List.of(new SuccessDetails(ENVIRONMENT_CRN)));
userSyncStatus.setLastStartedFullSync(lastSync);
UmsEventGenerationIds current = new UmsEventGenerationIds();
when(umsEventGenerationIdsProvider.getEventGenerationIds(eq(ACCOUNT_ID), any())).thenReturn(current);
when(eventGenerationIdsChecker.isInSync(userSyncStatus, current)).thenReturn(true);
EnvironmentUserSyncState result = underTest.internalCalculateEnvironmentUserSyncState(ACCOUNT_ID, ENVIRONMENT_CRN, Optional.of(userSyncStatus));
assertEquals(UserSyncState.UP_TO_DATE, result.getState());
assertEquals(lastSync.getOperationId(), result.getLastUserSyncOperationId());
}
use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.
the class UserSyncServiceTest method testSyncUsersWithFilterAndMultipleStack.
@Test
public void testSyncUsersWithFilterAndMultipleStack() {
Stack stack = mock(Stack.class);
Stack stack2 = mock(Stack.class);
when(stack.getEnvironmentCrn()).thenReturn(ENV_CRN);
when(stack2.getEnvironmentCrn()).thenReturn(ENV_CRN_2);
when(stackService.getMultipleByEnvironmentCrnOrChildEnvironmantCrnAndAccountId(Set.of(ENV_CRN, ENV_CRN_2), ACCOUNT_ID)).thenReturn(List.of(stack, stack2));
Operation operation = createRunningOperation();
when(operationService.startOperation(anyString(), any(OperationType.class), anyCollection(), anyCollection())).thenReturn(operation);
doAnswer(inv -> {
Runnable runnable = inv.getArgument(2, Runnable.class);
runnable.run();
return null;
}).when(operationService).tryWithOperationCleanup(eq(operation.getOperationId()), eq(ACCOUNT_ID), any(Runnable.class));
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn(INTERNAL_ACTOR);
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
when(entitlementService.usersyncCredentialsUpdateOptimizationEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
when(entitlementService.isFmsToFreeipaBatchCallEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
doAnswer(inv -> {
Runnable runnable = inv.getArgument(0, Runnable.class);
assertEquals(operation.getOperationId(), MDCBuilder.getMdcContextMap().get(LoggerContextKey.OPERATION_ID.toString()));
assertEquals(INTERNAL_ACTOR, ThreadBasedUserCrnProvider.getUserCrn());
runnable.run();
return mock(Future.class);
}).when(asyncTaskExecutor).submit(any(Runnable.class));
Operation result = underTest.synchronizeUsers(ACCOUNT_ID, ACTOR_CRN, Set.of(ENV_CRN, ENV_CRN_2), Set.of("userCrn"), Set.of("machineUserCrn"), WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED);
assertEquals(operation, result);
ArgumentCaptor<UserSyncRequestFilter> requestFilterCaptor = ArgumentCaptor.forClass(UserSyncRequestFilter.class);
verify(userSyncRequestValidator).validateParameters(eq(ACCOUNT_ID), eq(ACTOR_CRN), eq(Set.of(ENV_CRN, ENV_CRN_2)), requestFilterCaptor.capture());
UserSyncRequestFilter requestFilter = requestFilterCaptor.getValue();
assertEquals(requestFilter.getUserCrnFilter(), Set.of("userCrn"));
assertEquals(requestFilter.getMachineUserCrnFilter(), Set.of("machineUserCrn"));
assertTrue(requestFilter.getDeletedWorkloadUser().isEmpty());
verifyNoInteractions(userSyncStatusService);
ArgumentCaptor<UserSyncOptions> syncOptionsCaptor = ArgumentCaptor.forClass(UserSyncOptions.class);
verify(userSyncForEnvService).synchronizeUsers(eq(operation.getOperationId()), eq(ACCOUNT_ID), eq(List.of(stack, stack2)), eq(requestFilter), syncOptionsCaptor.capture(), anyLong());
UserSyncOptions userSyncOptions = syncOptionsCaptor.getValue();
assertFalse(userSyncOptions.isFullSync());
assertTrue(userSyncOptions.isCredentialsUpdateOptimizationEnabled());
assertTrue(userSyncOptions.isFmsToFreeIpaBatchCallEnabled());
}
use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.
the class UserSyncServiceTest method testSyncUsersWithCustomPermissionCheck.
@Test
public void testSyncUsersWithCustomPermissionCheck() {
Stack stack = mock(Stack.class);
when(stack.getEnvironmentCrn()).thenReturn(ENV_CRN);
when(stackService.getMultipleByEnvironmentCrnOrChildEnvironmantCrnAndAccountId(Set.of(), ACCOUNT_ID)).thenReturn(List.of(stack));
Operation operation = createRunningOperation();
when(operationService.startOperation(anyString(), any(OperationType.class), anyCollection(), anyCollection())).thenReturn(operation);
doAnswer(inv -> {
Runnable runnable = inv.getArgument(2, Runnable.class);
runnable.run();
return null;
}).when(operationService).tryWithOperationCleanup(eq(operation.getOperationId()), eq(ACCOUNT_ID), any(Runnable.class));
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn(INTERNAL_ACTOR);
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
UserSyncStatus userSyncStatus = new UserSyncStatus();
when(userSyncStatusService.getOrCreateForStack(stack)).thenReturn(userSyncStatus);
when(entitlementService.usersyncCredentialsUpdateOptimizationEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
when(entitlementService.isFmsToFreeipaBatchCallEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
doAnswer(inv -> {
Runnable runnable = inv.getArgument(0, Runnable.class);
assertEquals(operation.getOperationId(), MDCBuilder.getMdcContextMap().get(LoggerContextKey.OPERATION_ID.toString()));
assertEquals(INTERNAL_ACTOR, ThreadBasedUserCrnProvider.getUserCrn());
runnable.run();
return mock(Future.class);
}).when(asyncTaskExecutor).submit(any(Runnable.class));
UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(Set.of(), Set.of(), Optional.empty());
doAnswer(inv -> {
Runnable runnable = inv.getArgument(1, Runnable.class);
runnable.run();
return null;
}).when(customCheckUtil).run(eq(ACTOR_CRN), any(Runnable.class));
Operation result = underTest.synchronizeUsersWithCustomPermissionCheck(ACCOUNT_ID, ACTOR_CRN, Set.of(), userSyncFilter, WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED, AuthorizationResourceAction.DESCRIBE_ENVIRONMENT);
assertEquals(operation, result);
ArgumentCaptor<UserSyncRequestFilter> requestFilterCaptor = ArgumentCaptor.forClass(UserSyncRequestFilter.class);
verify(userSyncRequestValidator).validateParameters(eq(ACCOUNT_ID), eq(ACTOR_CRN), eq(Set.of()), requestFilterCaptor.capture());
UserSyncRequestFilter requestFilter = requestFilterCaptor.getValue();
assertTrue(requestFilter.getUserCrnFilter().isEmpty());
assertTrue(requestFilter.getMachineUserCrnFilter().isEmpty());
assertTrue(requestFilter.getDeletedWorkloadUser().isEmpty());
assertEquals(operation, userSyncStatus.getLastStartedFullSync());
verify(userSyncStatusService).save(userSyncStatus);
ArgumentCaptor<UserSyncOptions> syncOptionsCaptor = ArgumentCaptor.forClass(UserSyncOptions.class);
verify(userSyncForEnvService).synchronizeUsers(eq(operation.getOperationId()), eq(ACCOUNT_ID), eq(List.of(stack)), eq(requestFilter), syncOptionsCaptor.capture(), anyLong());
UserSyncOptions userSyncOptions = syncOptionsCaptor.getValue();
assertTrue(userSyncOptions.isFullSync());
assertTrue(userSyncOptions.isCredentialsUpdateOptimizationEnabled());
assertTrue(userSyncOptions.isFmsToFreeIpaBatchCallEnabled());
verify(commonPermissionCheckingUtils).checkPermissionForUserOnResources(AuthorizationResourceAction.DESCRIBE_ENVIRONMENT, ACTOR_CRN, List.of(ENV_CRN));
}
use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.
the class UserSyncAcceptorTest method testSingleUserAlwaysAcccepted.
@Test
void testSingleUserAlwaysAcccepted() {
Operation syncOperation = mock(Operation.class);
when(syncOperation.getUserList()).thenReturn(List.of("userA"));
Operation runningSyncOperation = mock(Operation.class);
assertFalse(userSyncAcceptor.doOperationsConflict(syncOperation, runningSyncOperation));
}
Aggregations