Search in sources :

Example 21 with UmsUsersState

use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState in project cloudbreak by hortonworks.

the class UserSyncForEnvServiceTest method testSyncUsersDoesntTimeout.

@Test
public void testSyncUsersDoesntTimeout() {
    ReflectionTestUtils.setField(underTest, "operationTimeout", 0L);
    Stack stack1 = mock(Stack.class);
    when(stack1.getEnvironmentCrn()).thenReturn(ENV_CRN);
    UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(Set.of(), Set.of(), Optional.empty());
    UserSyncOptions options = new UserSyncOptions(true, true, WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED);
    doAnswer(inv -> {
        inv.getArgument(2, Runnable.class).run();
        return null;
    }).when(operationService).tryWithOperationCleanup(eq(OPERATION_ID), eq(ACCOUNT_ID), any(Runnable.class));
    UmsUsersState umsUsersState1 = mock(UmsUsersState.class);
    when(umsUsersStateProviderDispatcher.getEnvToUmsUsersStateMap(eq(ACCOUNT_ID), eq(Set.of(ENV_CRN)), eq(Set.of()), eq(Set.of()), any())).thenReturn(Map.of(ENV_CRN, umsUsersState1));
    when(userSyncForStackService.synchronizeStack(stack1, umsUsersState1, options)).thenReturn(new SyncStatusDetail(ENV_CRN, SynchronizationStatus.COMPLETED, "", ImmutableMultimap.of()));
    Future<SyncStatusDetail> future = mock(Future.class);
    when(asyncTaskExecutor.submit(any(Callable.class))).thenAnswer(inv -> {
        SyncStatusDetail result = (SyncStatusDetail) inv.getArgument(0, Callable.class).call();
        when(future.get(anyLong(), eq(TimeUnit.MILLISECONDS))).thenReturn(result);
        return future;
    });
    when(umsEventGenerationIdsProvider.getEventGenerationIds(eq(ACCOUNT_ID), any(Optional.class))).thenReturn(new UmsEventGenerationIds());
    when(userSyncStatusService.getOrCreateForStack(stack1)).thenReturn(new UserSyncStatus());
    when(entitlementService.isUserSyncThreadTimeoutEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
    underTest.synchronizeUsers(OPERATION_ID, ACCOUNT_ID, List.of(stack1), userSyncFilter, options, System.currentTimeMillis());
    ArgumentCaptor<Collection> successCaptor = ArgumentCaptor.forClass(Collection.class);
    ArgumentCaptor<Collection> failureCaptor = ArgumentCaptor.forClass(Collection.class);
    verify(operationService).completeOperation(eq(ACCOUNT_ID), eq(OPERATION_ID), successCaptor.capture(), failureCaptor.capture());
    verify(future, never()).cancel(true);
    verify(future, never()).cancel(false);
    assertTrue(failureCaptor.getValue().isEmpty());
    assertTrue(successCaptor.getValue().contains(new SuccessDetails(ENV_CRN)));
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) Optional(java.util.Optional) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Callable(java.util.concurrent.Callable) Stack(com.sequenceiq.freeipa.entity.Stack) UmsEventGenerationIds(com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds) SyncStatusDetail(com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail) UserSyncOptions(com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions) Collection(java.util.Collection) Test(org.junit.jupiter.api.Test)

Example 22 with UmsUsersState

use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState in project cloudbreak by hortonworks.

the class UserSyncForStackServiceTest method testSynchronizeStackSuccessFullAtFirst.

@Test
public void testSynchronizeStackSuccessFullAtFirst() throws Exception {
    UmsUsersState umsUsersState = mock(UmsUsersState.class);
    UserSyncOptions options = new UserSyncOptions(true, false, WorkloadCredentialsUpdateType.FORCE_UPDATE);
    UsersState usersState = mock(UsersState.class);
    when(usersState.getUsers()).thenReturn(ImmutableSet.of());
    when(usersState.getGroups()).thenReturn(ImmutableSet.of());
    when(freeIpaUsersStateProvider.getUsersState(FREE_IPA_CLIENT)).thenReturn(usersState);
    UsersStateDifference usersStateDifference = mock(UsersStateDifference.class);
    when(userStateDifferenceCalculator.fromUmsAndIpaUsersStates(umsUsersState, usersState, options)).thenReturn(usersStateDifference);
    when(entitlementService.cloudIdentityMappingEnabled(ACCOUNT)).thenReturn(TRUE);
    when(entitlementService.isEnvironmentPrivilegedUserEnabled(ACCOUNT)).thenReturn(TRUE);
    SyncStatusDetail result = underTest.synchronizeStack(STACK, umsUsersState, options);
    verify(freeIpaUsersStateProvider, never()).getFilteredFreeIpaState(any(), any());
    verify(stateApplier).applyDifference(eq(umsUsersState), eq(ENV_CRN), any(), eq(usersStateDifference), eq(options), eq(FREE_IPA_CLIENT));
    verifyNoMoreInteractions(stateApplier);
    verify(cloudIdentitySyncService).syncCloudIdentities(eq(STACK), eq(umsUsersState), any());
    verify(sudoRuleService).setupSudoRule(STACK, FREE_IPA_CLIENT);
    assertEquals(ENV_CRN, result.getEnvironmentCrn());
    assertEquals(COMPLETED, result.getStatus());
    assertTrue(result.getWarnings().isEmpty());
}
Also used : SyncStatusDetail(com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UserSyncOptions(com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UsersStateDifference(com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference) Test(org.junit.jupiter.api.Test)

Example 23 with UmsUsersState

use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState in project cloudbreak by hortonworks.

the class UserSyncForStackServiceTest method testSynchronizeFailsToSetupSudoRules.

@Test
public void testSynchronizeFailsToSetupSudoRules() throws Exception {
    UmsUsersState umsUsersState = mock(UmsUsersState.class);
    UserSyncOptions options = new UserSyncOptions(true, false, WorkloadCredentialsUpdateType.FORCE_UPDATE);
    UsersState usersState = mock(UsersState.class);
    when(usersState.getUsers()).thenReturn(ImmutableSet.of());
    when(usersState.getGroups()).thenReturn(ImmutableSet.of());
    when(freeIpaUsersStateProvider.getUsersState(FREE_IPA_CLIENT)).thenReturn(usersState);
    UsersStateDifference usersStateDifference = mock(UsersStateDifference.class);
    when(userStateDifferenceCalculator.fromUmsAndIpaUsersStates(umsUsersState, usersState, options)).thenReturn(usersStateDifference);
    when(entitlementService.cloudIdentityMappingEnabled(ACCOUNT)).thenReturn(TRUE);
    when(entitlementService.isEnvironmentPrivilegedUserEnabled(ACCOUNT)).thenReturn(TRUE);
    doThrow(new Exception(ERROR_MESSAGE)).when(sudoRuleService).setupSudoRule(STACK, FREE_IPA_CLIENT);
    SyncStatusDetail result = underTest.synchronizeStack(STACK, umsUsersState, options);
    verify(freeIpaUsersStateProvider, never()).getFilteredFreeIpaState(any(), any());
    verify(stateApplier).applyDifference(eq(umsUsersState), eq(ENV_CRN), any(), eq(usersStateDifference), eq(options), eq(FREE_IPA_CLIENT));
    verifyNoMoreInteractions(stateApplier);
    verify(cloudIdentitySyncService).syncCloudIdentities(eq(STACK), eq(umsUsersState), any());
    assertEquals(ENV_CRN, result.getEnvironmentCrn());
    assertEquals(FAILED, result.getStatus());
    assertTrue(result.getWarnings().get(ENV_CRN).contains(ERROR_MESSAGE));
}
Also used : SyncStatusDetail(com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UserSyncOptions(com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UsersStateDifference(com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference) TimeoutException(java.util.concurrent.TimeoutException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Test(org.junit.jupiter.api.Test)

Example 24 with UmsUsersState

use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState in project cloudbreak by hortonworks.

the class UserSyncForStackServiceTest method testSynchronizeStackFailsPartial.

@Test
public void testSynchronizeStackFailsPartial() throws FreeIpaClientException, TimeoutException {
    UmsUsersState umsUsersState = mock(UmsUsersState.class);
    when(umsUsersState.getRequestedWorkloadUsernames()).thenReturn(ImmutableSet.of("user1", "user2"));
    UserSyncOptions options = new UserSyncOptions(false, false, WorkloadCredentialsUpdateType.FORCE_UPDATE);
    UsersState usersState = mock(UsersState.class);
    when(usersState.getUsers()).thenReturn(ImmutableSet.of());
    when(usersState.getGroups()).thenReturn(ImmutableSet.of());
    when(freeIpaUsersStateProvider.getFilteredFreeIpaState(FREE_IPA_CLIENT, Set.of("user1", "user2"))).thenReturn(usersState);
    UsersStateDifference usersStateDifference = mock(UsersStateDifference.class);
    when(userStateDifferenceCalculator.fromUmsAndIpaUsersStates(umsUsersState, usersState, options)).thenReturn(usersStateDifference);
    doAnswer(invocation -> {
        Multimap<String, String> warnings = invocation.getArgument(2, Multimap.class);
        warnings.put(ENV_CRN, "failed");
        return null;
    }).when(stateApplier).applyDifference(eq(umsUsersState), eq(ENV_CRN), any(), eq(usersStateDifference), eq(options), eq(FREE_IPA_CLIENT));
    SyncStatusDetail result = underTest.synchronizeStack(STACK, umsUsersState, options);
    verify(freeIpaUsersStateProvider, never()).getUsersState(any());
    verify(stateApplier).applyDifference(eq(umsUsersState), eq(ENV_CRN), any(), eq(usersStateDifference), eq(options), eq(FREE_IPA_CLIENT));
    verifyNoMoreInteractions(stateApplier);
    verifyNoInteractions(cloudIdentitySyncService);
    verifyNoInteractions(sudoRuleService);
    assertEquals(ENV_CRN, result.getEnvironmentCrn());
    assertEquals(FAILED, result.getStatus());
    assertFalse(result.getWarnings().isEmpty());
}
Also used : SyncStatusDetail(com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UserSyncOptions(com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UsersStateDifference(com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference) Test(org.junit.jupiter.api.Test)

Example 25 with UmsUsersState

use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState in project cloudbreak by hortonworks.

the class UserSyncForStackServiceTest method testSynchronizeStackFailsToGetClient.

@Test
public void testSynchronizeStackFailsToGetClient() throws FreeIpaClientException {
    UmsUsersState umsUsersState = mock(UmsUsersState.class);
    UserSyncOptions options = new UserSyncOptions(false, false, WorkloadCredentialsUpdateType.FORCE_UPDATE);
    when(freeIpaClientFactory.getFreeIpaClientForStack(STACK)).thenThrow(new FreeIpaClientException("potty"));
    SyncStatusDetail result = underTest.synchronizeStack(STACK, umsUsersState, options);
    assertEquals(ENV_CRN, result.getEnvironmentCrn());
    assertEquals(FAILED, result.getStatus());
    assertTrue(result.getWarnings().isEmpty());
}
Also used : SyncStatusDetail(com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UserSyncOptions(com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Test(org.junit.jupiter.api.Test)

Aggregations

UmsUsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState)30 Test (org.junit.jupiter.api.Test)23 UsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UsersState)19 UserSyncOptions (com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions)14 SyncStatusDetail (com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail)11 UsersStateDifference (com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference)9 Stack (com.sequenceiq.freeipa.entity.Stack)8 UmsEventGenerationIds (com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds)7 Collection (java.util.Collection)7 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)5 List (java.util.List)5 Optional (java.util.Optional)5 Callable (java.util.concurrent.Callable)5 Future (java.util.concurrent.Future)5 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)4 FmsGroup (com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup)4 FmsUser (com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser)4 Set (java.util.Set)4 TimeoutException (java.util.concurrent.TimeoutException)4 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)3