use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.
the class CleanupServiceTest method testRemoveUsersForCluster.
@Test
public void testRemoveUsersForCluster() throws FreeIpaClientException {
Set<String> usersNames = Set.of("ldapbind-test-wl-1", "kerberosbind-test-wl-1");
Set<User> ipaUsers = Set.of(createUser("ldapbind-test-wl-1"), createUser("ldapbind-test-wl-2"), createUser("kerberosbind-test-wl-1"), createUser("kerberosbind-test-wl-2"), createUser("mockuser0"), createUser("csso_khorvath"));
FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);
when(freeIpaClient.userFindAll()).thenReturn(ipaUsers);
when(stackService.getStackById(anyLong())).thenReturn(createStack());
Pair<Set<String>, Map<String, String>> result = cleanupService.removeUsers(STACK_ID, usersNames, "test-wl-1", ENV_CRN);
verify(freeIpaClient, times(1)).deleteUser("ldapbind-test-wl-1");
verify(freeIpaClient, times(1)).deleteUser("kerberosbind-test-wl-1");
verifyUserDeleteNotInvoked(freeIpaClient, "ldapbind-test-wl-2", "kerberosbind-test-wl-2", "mockuser0", "csso_khorvath");
assertEquals(2, result.getFirst().size());
assertTrue(result.getFirst().stream().anyMatch("ldapbind-test-wl-1"::equals));
assertTrue(result.getFirst().stream().anyMatch("kerberosbind-test-wl-1"::equals));
verify(kerberosConfigService, times(1)).delete("envCrn", "accountId", "test-wl-1");
verify(ldapConfigService, times(1)).delete("envCrn", "accountId", "test-wl-1");
}
use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.
the class CleanupServiceTest method testRemoveUsersWhenKerberosConfigAlreadyDeleted.
@Test
public void testRemoveUsersWhenKerberosConfigAlreadyDeleted() throws FreeIpaClientException {
Set<String> usersNames = Set.of("ldapbind-test-wl-1", "kerberosbind-test-wl-1");
Set<User> ipaUsers = Set.of(createUser("ldapbind-test-wl-1"), createUser("ldapbind-test-wl-2"), createUser("kerberosbind-test-wl-1"), createUser("kerberosbind-test-wl-2"), createUser("mockuser0"), createUser("csso_khorvath"));
FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);
when(freeIpaClient.userFindAll()).thenReturn(ipaUsers);
when(stackService.getStackById(anyLong())).thenReturn(createStack());
doThrow(new NotFoundException("Kerberos config not found")).when(kerberosConfigService).delete("envCrn", "accountId", "test-wl-1");
Pair<Set<String>, Map<String, String>> result = cleanupService.removeUsers(STACK_ID, usersNames, "test-wl-1", ENV_CRN);
verify(freeIpaClient, times(1)).deleteUser("ldapbind-test-wl-1");
verify(freeIpaClient, times(1)).deleteUser("kerberosbind-test-wl-1");
verifyUserDeleteNotInvoked(freeIpaClient, "ldapbind-test-wl-2", "kerberosbind-test-wl-2", "mockuser0", "csso_khorvath");
assertEquals(2, result.getFirst().size());
assertTrue(result.getFirst().stream().anyMatch("ldapbind-test-wl-1"::equals));
assertTrue(result.getFirst().stream().anyMatch("kerberosbind-test-wl-1"::equals));
verify(kerberosConfigService, times(1)).delete("envCrn", "accountId", "test-wl-1");
verify(ldapConfigService, times(1)).delete("envCrn", "accountId", "test-wl-1");
}
use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.
the class CleanupServiceTest method testRemoveUsersWhenNoClusterNameProvidedAndDeleteFails.
@Test
public void testRemoveUsersWhenNoClusterNameProvidedAndDeleteFails() throws FreeIpaClientException {
Set<String> usersNames = Set.of("ldapbind-test-wl-1", "kerberosbind-test-wl-1");
Set<User> ipaUsers = Set.of(createUser("ldapbind-test-wl-1"), createUser("ldapbind-test-wl-2"), createUser("kerberosbind-test-wl-1"), createUser("kerberosbind-test-wl-2"), createUser("mockuser0"), createUser("csso_khorvath"));
FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);
when(freeIpaClient.userFindAll()).thenReturn(ipaUsers);
doThrow(new FreeIpaClientException("Connection failed")).when(freeIpaClient).deleteUser(anyString());
Pair<Set<String>, Map<String, String>> result = cleanupService.removeUsers(STACK_ID, usersNames, "", ENV_CRN);
verify(freeIpaClient, times(1)).deleteUser("ldapbind-test-wl-1");
verify(freeIpaClient, times(1)).deleteUser("kerberosbind-test-wl-1");
verifyUserDeleteNotInvoked(freeIpaClient, "ldapbind-test-wl-2", "kerberosbind-test-wl-2", "mockuser0", "csso_khorvath");
assertEquals(0, result.getFirst().size());
assertEquals(2, result.getSecond().size());
assertEquals("Connection failed", result.getSecond().get("ldapbind-test-wl-1"));
assertEquals("Connection failed", result.getSecond().get("kerberosbind-test-wl-1"));
verify(kerberosConfigService, times(0)).delete("envCrn", "accountId", "test-wl-1");
verify(ldapConfigService, times(0)).delete("envCrn", "accountId", "test-wl-1");
}
use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.
the class SetPasswordHandlerTest method testWithPasswordHashSupportWithUmsPasswordWithUpdateOptimizationIpaCredentialsUpToDate.
@Test
void testWithPasswordHashSupportWithUmsPasswordWithUpdateOptimizationIpaCredentialsUpToDate() throws FreeIpaClientException, IOException {
SetPasswordRequest request = new SetPasswordRequest(1L, "environment", USER, USER_CRN, "password", Optional.empty());
FreeIpaClient mockFreeIpaClient = newfreeIpaClient(true);
when(freeIpaClientFactory.getFreeIpaClientForStack(any())).thenReturn(mockFreeIpaClient);
setupMocksForPasswordHashSupport(true, true);
User user = getIpaUser(USER);
when(mockFreeIpaClient.userFind(USER)).thenReturn(Optional.of(user));
UserMetadata userMetadata = new UserMetadata(USER_CRN, UMS_WORKLOAD_CREDENTIALS_VERSION);
doReturn(Optional.of(userMetadata)).when(userMetadataConverter).toUserMetadata(argThat(matchesUser(user)));
underTest.accept(new Event<>(request));
verify(workloadCredentialService, times(0)).setWorkloadCredential(eq(true), any(), any());
verify(mockFreeIpaClient, times(0)).userSetPasswordWithExpiration(any(), any(), any());
}
use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.
the class SetPasswordHandlerTest method testWithPasswordHashSupportWithUmsPasswordWithUpdateOptimizationIpaCredentialsVersionUnknown.
@Test
void testWithPasswordHashSupportWithUmsPasswordWithUpdateOptimizationIpaCredentialsVersionUnknown() throws FreeIpaClientException, IOException {
SetPasswordRequest request = new SetPasswordRequest(1L, "environment", USER, USER_CRN, "password", Optional.empty());
FreeIpaClient mockFreeIpaClient = newfreeIpaClient(true);
when(freeIpaClientFactory.getFreeIpaClientForStack(any())).thenReturn(mockFreeIpaClient);
setupMocksForPasswordHashSupport(true, true);
User user = getIpaUser(USER);
when(mockFreeIpaClient.userFind(USER)).thenReturn(Optional.of(user));
doReturn(Optional.empty()).when(userMetadataConverter).toUserMetadata(argThat(matchesUser(user)));
underTest.accept(new Event<>(request));
verify(workloadCredentialService, times(1)).setWorkloadCredential(eq(true), any(), any());
verify(mockFreeIpaClient, times(0)).userSetPasswordWithExpiration(any(), any(), any());
}
Aggregations