Search in sources :

Example 11 with SyncStatusDetail

use of com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail 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 12 with SyncStatusDetail

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

the class UserSyncForStackServiceTest method testSynchronizeStackForDeleteUserEmpty.

@Test
public void testSynchronizeStackForDeleteUserEmpty() throws FreeIpaClientException {
    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("deleteMe"))).thenReturn(usersState);
    SyncStatusDetail result = underTest.synchronizeStackForDeleteUser(STACK, "deleteMe");
    verifyNoInteractions(stateApplier);
    assertEquals(ENV_CRN, result.getEnvironmentCrn());
    assertEquals(COMPLETED, result.getStatus());
    assertTrue(result.getWarnings().isEmpty());
}
Also used : SyncStatusDetail(com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) Test(org.junit.jupiter.api.Test)

Example 13 with SyncStatusDetail

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

the class UserSyncForStackServiceTest method testSynchronizeStackForDeleteUserFailure.

@Test
public void testSynchronizeStackForDeleteUserFailure() throws FreeIpaClientException {
    when(freeIpaClientFactory.getFreeIpaClientForStack(STACK)).thenThrow(new FreeIpaClientException("totty"));
    SyncStatusDetail result = underTest.synchronizeStackForDeleteUser(STACK, "deleteMe");
    verifyNoInteractions(stateApplier);
    assertEquals(ENV_CRN, result.getEnvironmentCrn());
    assertEquals(FAILED, result.getStatus());
    assertTrue(result.getWarnings().isEmpty());
}
Also used : SyncStatusDetail(com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Test(org.junit.jupiter.api.Test)

Example 14 with SyncStatusDetail

use of com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail 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 15 with SyncStatusDetail

use of com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail 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

SyncStatusDetail (com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail)18 UmsUsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState)13 Test (org.junit.jupiter.api.Test)13 UserSyncOptions (com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions)11 Stack (com.sequenceiq.freeipa.entity.Stack)7 UsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UsersState)7 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)6 UsersStateDifference (com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference)6 Collection (java.util.Collection)6 Future (java.util.concurrent.Future)6 UserSyncStatus (com.sequenceiq.freeipa.entity.UserSyncStatus)5 UmsEventGenerationIds (com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds)5 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)4 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)4 Callable (java.util.concurrent.Callable)4 TimeoutException (java.util.concurrent.TimeoutException)4 Json (com.sequenceiq.cloudbreak.common.json.Json)3 ArrayList (java.util.ArrayList)3 Optional (java.util.Optional)3 ExecutionException (java.util.concurrent.ExecutionException)3