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());
}
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());
}
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);
}
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);
}
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());
}
Aggregations