Search in sources :

Example 16 with FmsUser

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

the class FmsUserConverterTest method testUserToFmsUserControlPlaneLockedOutState.

@Test
public void testUserToFmsUserControlPlaneLockedOutState() {
    String workloadUsername = "foobar";
    UserManagementProto.User umsUser = UserManagementProto.User.newBuilder().setWorkloadUsername(workloadUsername).setState(UserManagementProto.ActorState.Value.CONTROL_PLANE_LOCKED_OUT).build();
    FmsUser fmsUser = underTest.toFmsUser(umsUser);
    assertEquals(workloadUsername, fmsUser.getName());
    assertEquals(underTest.NONE_STRING, fmsUser.getFirstName());
    assertEquals(underTest.NONE_STRING, fmsUser.getLastName());
    assertEquals(FmsUser.State.ENABLED, fmsUser.getState());
}
Also used : FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) UserManagementProto(com.cloudera.thunderhead.service.usermanagement.UserManagementProto) Test(org.junit.jupiter.api.Test)

Example 17 with FmsUser

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

the class FmsUserConverterTest method testUserSyncActorDetailsToFmsUserMissingState.

@Test
public void testUserSyncActorDetailsToFmsUserMissingState() {
    String workloadUsername = "foobar";
    UserManagementProto.UserSyncActorDetails actorDetails = UserManagementProto.UserSyncActorDetails.newBuilder().setWorkloadUsername(workloadUsername).build();
    FmsUser fmsUser = underTest.toFmsUser(actorDetails);
    assertEquals(workloadUsername, fmsUser.getName());
    assertEquals(underTest.NONE_STRING, fmsUser.getFirstName());
    assertEquals(underTest.NONE_STRING, fmsUser.getLastName());
    assertEquals(FmsUser.State.ENABLED, fmsUser.getState());
}
Also used : FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) UserManagementProto(com.cloudera.thunderhead.service.usermanagement.UserManagementProto) Test(org.junit.jupiter.api.Test)

Example 18 with FmsUser

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

the class FreeIpaUsersStateProviderTest method testFromIpaUserDisabled.

@Test
void testFromIpaUserDisabled() {
    com.sequenceiq.freeipa.client.model.User ipaUser = createIpaUser("uid", List.of("group1", "group2"), USER_DISABLED);
    FmsUser fmsUser = underTest.fromIpaUser(ipaUser);
    assertEquals(fmsUser.getName(), ipaUser.getUid());
    assertEquals(fmsUser.getLastName(), ipaUser.getSn());
    assertEquals(fmsUser.getFirstName(), ipaUser.getGivenname());
    assertEquals(fmsUser.getState(), FmsUser.State.DISABLED);
}
Also used : FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) Test(org.junit.jupiter.api.Test)

Example 19 with FmsUser

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

the class FreeIpaUsersStateProviderTest method testFromIpaUserEnabled.

@Test
void testFromIpaUserEnabled() {
    com.sequenceiq.freeipa.client.model.User ipaUser = createIpaUser("uid", List.of("group1", "group2"), USER_ENABLED);
    FmsUser fmsUser = underTest.fromIpaUser(ipaUser);
    assertEquals(fmsUser.getName(), ipaUser.getUid());
    assertEquals(fmsUser.getLastName(), ipaUser.getSn());
    assertEquals(fmsUser.getFirstName(), ipaUser.getGivenname());
    assertEquals(fmsUser.getState(), FmsUser.State.ENABLED);
}
Also used : FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) Test(org.junit.jupiter.api.Test)

Example 20 with FmsUser

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

the class FreeIpaUsersStateProviderTest method testGetFilteredFreeIpaState.

@Test
void testGetFilteredFreeIpaState() throws Exception {
    List<String> user1GroupNames = List.of("group1", "group2");
    List<String> user2GroupNames = List.of("group2", "group3", IPA_UNMANAGED_GROUPS.get(0));
    List<String> groupsWithoutMembers = List.of("group4");
    com.sequenceiq.freeipa.client.model.User user1 = createIpaUser("user1", user1GroupNames);
    String userNotFound = "userNotFound";
    Set<com.sequenceiq.freeipa.client.model.Group> groupsFindAll = Stream.of(user1GroupNames.stream(), user2GroupNames.stream(), groupsWithoutMembers.stream(), IPA_UNMANAGED_GROUPS.stream()).flatMap(groupName -> groupName).map(this::createIpaGroup).collect(Collectors.toSet());
    JsonRpcClientException jsonRpcException = new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), "group not found", null);
    FreeIpaClientException notFoundException = new FreeIpaClientException("Invoke FreeIPA failed", jsonRpcException);
    when(freeIpaClient.userShow(user1.getUid())).thenReturn(user1);
    when(freeIpaClient.userShow(userNotFound)).thenThrow(notFoundException);
    when(freeIpaClient.groupFindAll()).thenReturn(groupsFindAll);
    Set<String> expectedUsers = Sets.newHashSet(user1.getUid());
    Set<String> expectedGroups = groupsFindAll.stream().map(com.sequenceiq.freeipa.client.model.Group::getCn).filter(groupName -> !IPA_UNMANAGED_GROUPS.contains(groupName)).collect(Collectors.toSet());
    UserMetadata user1Metadata = new UserMetadata("user1-crn", 1L);
    doReturn(Optional.of(user1Metadata)).when(userMetadataConverter).toUserMetadata(argThat(arg -> user1.getUid().equals(arg.getUid())));
    Map<String, UserMetadata> expectedUserMetadata = Map.of(user1.getUid(), user1Metadata);
    UsersState ipaState = underTest.getFilteredFreeIpaState(freeIpaClient, Set.of(user1.getUid(), userNotFound));
    for (FmsUser fmsUser : ipaState.getUsers()) {
        assertTrue(expectedUsers.contains(fmsUser.getName()));
        expectedUsers.remove(fmsUser.getName());
    }
    assertTrue(expectedUsers.isEmpty());
    for (FmsGroup fmsGroup : ipaState.getGroups()) {
        assertTrue(expectedGroups.contains(fmsGroup.getName()));
        expectedGroups.remove(fmsGroup.getName());
    }
    assertTrue(expectedGroups.isEmpty());
    assertEquals(expectedUserMetadata, ipaState.getUserMetadataMap());
}
Also used : FmsGroup(com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup) IPA_UNMANAGED_GROUPS(com.sequenceiq.freeipa.client.FreeIpaChecks.IPA_UNMANAGED_GROUPS) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) Pair(org.apache.commons.lang3.tuple.Pair) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) UserMetadata(com.sequenceiq.freeipa.service.freeipa.user.model.UserMetadata) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) UserMetadataConverter(com.sequenceiq.freeipa.service.freeipa.user.conversion.UserMetadataConverter) Mockito.doReturn(org.mockito.Mockito.doReturn) Stack(com.sequenceiq.freeipa.entity.Stack) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) IPA_PROTECTED_USERS(com.sequenceiq.freeipa.client.FreeIpaChecks.IPA_PROTECTED_USERS) Set(java.util.Set) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) FreeIpaErrorCodes(com.sequenceiq.freeipa.client.FreeIpaErrorCodes) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientFactory(com.sequenceiq.freeipa.service.freeipa.FreeIpaClientFactory) Optional(java.util.Optional) FmsGroup(com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup) FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) FmsGroup(com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup) UserMetadata(com.sequenceiq.freeipa.service.freeipa.user.model.UserMetadata) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Test(org.junit.jupiter.api.Test)

Aggregations

FmsUser (com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser)42 Test (org.junit.jupiter.api.Test)33 UserManagementProto (com.cloudera.thunderhead.service.usermanagement.UserManagementProto)23 UsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UsersState)8 FmsGroup (com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup)6 UmsUsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState)5 List (java.util.List)5 Map (java.util.Map)5 UserMetadata (com.sequenceiq.freeipa.service.freeipa.user.model.UserMetadata)4 UsersStateDifference (com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference)3 Collection (java.util.Collection)3 Set (java.util.Set)3 Maps (com.google.common.collect.Maps)2 Sets (com.google.common.collect.Sets)2 JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)2 IPA_PROTECTED_USERS (com.sequenceiq.freeipa.client.FreeIpaChecks.IPA_PROTECTED_USERS)2 IPA_UNMANAGED_GROUPS (com.sequenceiq.freeipa.client.FreeIpaChecks.IPA_UNMANAGED_GROUPS)2 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)2 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)2 FreeIpaErrorCodes (com.sequenceiq.freeipa.client.FreeIpaErrorCodes)2