Search in sources :

Example 26 with User

use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.

the class CleanupServiceTest method testRemoveUsersWhenNoClusterNameProvided.

@Test
public void testRemoveUsersWhenNoClusterNameProvided() 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);
    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(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(0)).delete("envCrn", "accountId", "test-wl-1");
    verify(ldapConfigService, times(0)).delete("envCrn", "accountId", "test-wl-1");
}
Also used : User(com.sequenceiq.freeipa.client.model.User) Set(java.util.Set) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Map(java.util.Map) Test(org.junit.Test)

Example 27 with User

use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.

the class CleanupServiceTest method createUser.

private User createUser(String userId) {
    User user = new User();
    user.setUid(userId);
    return user;
}
Also used : User(com.sequenceiq.freeipa.client.model.User)

Example 28 with User

use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.

the class CleanupServiceTest method testRemoveUsersWhenLdapConfigAlreadyDeleted.

@Test
public void testRemoveUsersWhenLdapConfigAlreadyDeleted() 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("Ldap config not found")).when(ldapConfigService).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");
}
Also used : User(com.sequenceiq.freeipa.client.model.User) Set(java.util.Set) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Map(java.util.Map) Test(org.junit.Test)

Example 29 with User

use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.

the class UserMetadataConverterTest method testToUserMetadataJsonValidInput.

private void testToUserMetadataJsonValidInput(String crn, long workloadCredentialsVersion) {
    UserMetadata input = new UserMetadata(crn, workloadCredentialsVersion);
    String encoded = underTest.toUserMetadataJson(input);
    assertTrue(encoded.contains(crn));
    assertTrue(encoded.contains(makeValidEncodedMeta(workloadCredentialsVersion)));
    User user = new User();
    user.setUid("username");
    user.setTitle(encoded);
    Optional<UserMetadata> decoded = underTest.toUserMetadata(user);
    assertTrue(decoded.isPresent());
    assertEquals(input, decoded.get());
}
Also used : User(com.sequenceiq.freeipa.client.model.User) UserMetadata(com.sequenceiq.freeipa.service.freeipa.user.model.UserMetadata)

Example 30 with User

use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.

the class SetPasswordHandlerTest method getIpaUser.

private User getIpaUser(String uid) {
    User user = new User();
    user.setUid(uid);
    return user;
}
Also used : User(com.sequenceiq.freeipa.client.model.User)

Aggregations

User (com.sequenceiq.freeipa.client.model.User)38 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)15 Test (org.junit.jupiter.api.Test)13 Map (java.util.Map)11 RPCResponse (com.sequenceiq.cloudbreak.client.RPCResponse)10 Set (java.util.Set)8 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)7 FmsUser (com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser)7 List (java.util.List)7 Test (org.junit.Test)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 UserMetadata (com.sequenceiq.freeipa.service.freeipa.user.model.UserMetadata)4 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)3 SetPasswordRequest (com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordRequest)3 FmsGroup (com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup)3 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)2 HashMultimap (com.google.common.collect.HashMultimap)2 Multimap (com.google.common.collect.Multimap)2 JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)2 FreeIpaErrorCodes (com.sequenceiq.freeipa.client.FreeIpaErrorCodes)2