use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.
the class FreeIpaUsersStateProviderTest method testGetUserStateUserWithNullGroups.
@Test
void testGetUserStateUserWithNullGroups() throws Exception {
String username = "userNull";
Set<com.sequenceiq.freeipa.client.model.User> usersFindAll = Set.of(createIpaUser(username, null));
Set<com.sequenceiq.freeipa.client.model.Group> groupsFindAll = IPA_UNMANAGED_GROUPS.stream().map(this::createIpaGroup).collect(Collectors.toSet());
when(freeIpaClient.userFindAll()).thenReturn(usersFindAll);
when(freeIpaClient.groupFindAll()).thenReturn(groupsFindAll);
UsersState ipaState = underTest.getUsersState(freeIpaClient);
assertEquals(1, ipaState.getUsers().size());
FmsUser ipaUser = ipaState.getUsers().asList().get(0);
assertEquals(username, ipaUser.getName());
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.
the class UserSyncForStackServiceTest method testSynchronizeStackForDeleteUser.
@Test
public void testSynchronizeStackForDeleteUser() throws FreeIpaClientException, TimeoutException {
UsersState usersState = mock(UsersState.class);
when(usersState.getUsers()).thenReturn(ImmutableSet.of(new FmsUser().withName("deleteMe")));
when(usersState.getGroups()).thenReturn(ImmutableSet.of());
when(usersState.getGroupMembership()).thenReturn(ImmutableMultimap.of("deleteMe", "group"));
when(freeIpaUsersStateProvider.getFilteredFreeIpaState(FREE_IPA_CLIENT, Set.of("deleteMe"))).thenReturn(usersState);
UsersStateDifference usersStateDifference = mock(UsersStateDifference.class);
ArgumentCaptor<Collection<String>> captor = ArgumentCaptor.forClass(Collection.class);
when(userStateDifferenceCalculator.forDeletedUser(eq("deleteMe"), captor.capture())).thenReturn(usersStateDifference);
SyncStatusDetail result = underTest.synchronizeStackForDeleteUser(STACK, "deleteMe");
verify(stateApplier).applyStateDifferenceToIpa(eq(ENV_CRN), eq(FREE_IPA_CLIENT), eq(usersStateDifference), any(), eq(false));
assertTrue(captor.getValue().contains("group"));
assertEquals(1, captor.getValue().size());
assertEquals(ENV_CRN, result.getEnvironmentCrn());
assertEquals(COMPLETED, result.getStatus());
assertTrue(result.getWarnings().isEmpty());
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.
the class FmsUserConverter method createFmsUser.
private FmsUser createFmsUser(String workloadUsername, String firstName, String lastName, UserManagementProto.ActorState.Value actorState) {
checkArgument(StringUtils.isNotBlank(workloadUsername));
FmsUser fmsUser = new FmsUser();
fmsUser.withName(workloadUsername);
fmsUser.withFirstName(StringUtils.defaultIfBlank(StringUtils.strip(firstName), NONE_STRING));
fmsUser.withLastName(StringUtils.defaultIfBlank(StringUtils.strip(lastName), NONE_STRING));
fmsUser.withState(toFmsUserState(actorState));
return fmsUser;
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.
the class UserSyncOperationsTest method testAddUsersBatch.
@Test
public void testAddUsersBatch() throws FreeIpaClientException, TimeoutException {
Multimap<String, String> warnings = ArrayListMultimap.create();
FmsUser user1 = new FmsUser().withName("user_1").withFirstName("User_1").withLastName("Test1").withState(FmsUser.State.ENABLED);
FmsUser user2 = new FmsUser().withName("user_2").withFirstName("User_2").withLastName("Test2").withState(FmsUser.State.DISABLED);
Set<FmsUser> users = Set.of(user1, user2);
when(batchPartitionSizeProperties.getByOperation("user_add")).thenReturn(3);
underTest.addUsers(true, freeIpaClient, users, warnings::put);
assertTrue(warnings.isEmpty());
ArgumentCaptor<List<Object>> operationsCaptor = ArgumentCaptor.forClass(List.class);
verify(freeIpaClient).callBatch(any(), operationsCaptor.capture(), eq(3), eq(Set.of(FreeIpaErrorCodes.DUPLICATE_ENTRY)), any());
List<Object> operations = operationsCaptor.getValue();
assertEquals(2, operations.size());
Object user1oper = operations.stream().filter(op -> {
Map<String, Object> operation = (Map<String, Object>) op;
List<Object> params = (List<Object>) operation.get("params");
return "user_1".equals(((List<String>) params.get(0)).get(0));
}).findFirst().get();
Map<String, Object> operation1 = (Map<String, Object>) user1oper;
List<Object> params1 = (List<Object>) operation1.get("params");
Map<String, Object> attribs1 = (Map<String, Object>) params1.get(1);
assertEquals("User_1", attribs1.get("givenname"));
assertEquals("Test1", attribs1.get("sn"));
assertTrue(((List<String>) attribs1.get("setattr")).contains("nsAccountLock=false"));
Object user2oper = operations.stream().filter(op -> {
Map<String, Object> operation = (Map<String, Object>) op;
List<Object> params = (List<Object>) operation.get("params");
return "user_2".equals(((List<String>) params.get(0)).get(0));
}).findFirst().get();
Map<String, Object> operation2 = (Map<String, Object>) user2oper;
List<Object> params2 = (List<Object>) operation2.get("params");
Map<String, Object> attribs2 = (Map<String, Object>) params2.get(1);
assertEquals("User_2", attribs2.get("givenname"));
assertEquals("Test2", attribs2.get("sn"));
assertTrue(((List<String>) attribs2.get("setattr")).contains("nsAccountLock=true"));
verify(interruptChecker, times(2)).throwTimeoutExIfInterrupted();
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.
the class FmsUserConverterTest method testUserToFmsUser.
@Test
public void testUserToFmsUser() {
String firstName = "Foo";
String lastName = "Bar";
String workloadUsername = "foobar";
UserManagementProto.User umsUser = UserManagementProto.User.newBuilder().setFirstName(firstName).setLastName(lastName).setWorkloadUsername(workloadUsername).setState(UserManagementProto.ActorState.Value.ACTIVE).build();
FmsUser fmsUser = underTest.toFmsUser(umsUser);
assertEquals(workloadUsername, fmsUser.getName());
assertEquals(firstName, fmsUser.getFirstName());
assertEquals(lastName, fmsUser.getLastName());
assertEquals(FmsUser.State.ENABLED, fmsUser.getState());
}
Aggregations