use of com.sequenceiq.freeipa.client.model.Group in project cloudbreak by hortonworks.
the class UserSyncOperationsTest method testRemoveUsersFromGroupsSingle.
@Test
public void testRemoveUsersFromGroupsSingle() throws Exception {
Multimap<String, String> groupMapping = setupGroupMapping(5, MAX_SUBJECTS_PER_REQUEST * 2);
Multimap<String, String> warnings = ArrayListMultimap.create();
ArgumentCaptor<List<Object>> flagsCaptor = ArgumentCaptor.forClass(List.class);
ArgumentCaptor<Map<String, Object>> paramsCaptor = ArgumentCaptor.forClass(Map.class);
RPCResponse<Object> response1 = new RPCResponse<>();
response1.setResult(new Group());
RPCResponse<Object> response2 = new RPCResponse<>();
response2.setResult(new Group());
when(freeIpaClient.invoke(eq("group_remove_member"), flagsCaptor.capture(), paramsCaptor.capture(), eq(Group.class))).thenReturn(response1, response2);
underTest.removeUsersFromGroups(false, freeIpaClient, groupMapping, warnings::put);
assertTrue(warnings.isEmpty());
verifyNoInteractions(batchPartitionSizeProperties);
verify(freeIpaClient, never()).callBatch(any(), any(), any(), any(), any());
List<List<Object>> flagsList = flagsCaptor.getAllValues();
Map<String, Long> flagCount = flagsList.stream().flatMap(Collection::stream).map(o -> (String) o).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
assertEquals(5, flagCount.size());
assertTrue(flagCount.keySet().containsAll(Set.of("group1", "group2", "group3", "group4", "group0")));
flagCount.forEach((flag, count) -> assertEquals(2, count, flag + " size should be 2"));
List<Map<String, Object>> paramsList = paramsCaptor.getAllValues();
assertEquals(10, paramsList.size());
paramsList.forEach(map -> {
assertEquals(10, ((List<String>) map.get("user")).size());
assertTrue(((List<String>) map.get("user")).stream().allMatch(user -> user.startsWith("user")));
});
verify(interruptChecker, times(20)).throwTimeoutExIfInterrupted();
}
use of com.sequenceiq.freeipa.client.model.Group in project cloudbreak by hortonworks.
the class SudoRuleServiceTest method shouldThrowIllegalStateExceptionInCaseOfExistingSudoRuleButNotAllHostGroup.
@Test
public void shouldThrowIllegalStateExceptionInCaseOfExistingSudoRuleButNotAllHostGroup() throws FreeIpaClientException {
Optional<SudoRule> sudoRule = Optional.of(new SudoRule());
when(stack.getEnvironmentCrn()).thenReturn(ENV_CRN);
when(virtualGroupService.getVirtualGroup(any(), eq(UmsVirtualGroupRight.ALLOW_PRIVILEGED_OS_OPERATIONS))).thenReturn(GROUP);
when(freeIpaClient.groupShow(GROUP)).thenReturn(mock(Group.class));
when(freeIpaClient.sudoRuleShow(RULE_NAME)).thenReturn(sudoRule);
assertThrows(IllegalStateException.class, () -> victim.setupSudoRule(stack, freeIpaClient));
}
use of com.sequenceiq.freeipa.client.model.Group in project cloudbreak by hortonworks.
the class SudoRuleServiceTest method shouldCreateValidSudoRuleCommandAndGroupAssignment.
@Test
public void shouldCreateValidSudoRuleCommandAndGroupAssignment() throws Exception {
SudoRule sudoRule = aValidSudoRule();
when(stack.getEnvironmentCrn()).thenReturn(ENV_CRN);
when(virtualGroupService.getVirtualGroup(any(), eq(UmsVirtualGroupRight.ALLOW_PRIVILEGED_OS_OPERATIONS))).thenReturn(GROUP);
when(freeIpaClient.groupShow(GROUP)).thenReturn(mock(Group.class));
when(freeIpaClient.sudoRuleShow(RULE_NAME)).thenReturn(Optional.empty());
when(freeIpaClient.sudoRuleAdd(RULE_NAME, true)).thenReturn(sudoRule);
when(freeIpaClient.sudoCommandFindAll()).thenReturn(Set.of());
victim.setupSudoRule(stack, freeIpaClient);
verify(freeIpaClient).sudoCommandAdd(ALLOW_COMMAND1);
verify(freeIpaClient).sudoCommandAdd(ALLOW_COMMAND2);
verify(freeIpaClient).sudoCommandAdd(DENY_COMMAND1);
verify(freeIpaClient).sudoCommandAdd(DENY_COMMAND2);
verify(freeIpaClient).sudoRuleAddAllowCommand(RULE_NAME, ALLOW_COMMAND1);
verify(freeIpaClient).sudoRuleAddAllowCommand(RULE_NAME, ALLOW_COMMAND2);
verify(freeIpaClient).sudoRuleAddDenyCommand(RULE_NAME, DENY_COMMAND1);
verify(freeIpaClient).sudoRuleAddDenyCommand(RULE_NAME, DENY_COMMAND2);
verify(freeIpaClient).sudoRuleAddGroup(RULE_NAME, GROUP);
}
use of com.sequenceiq.freeipa.client.model.Group in project cloudbreak by hortonworks.
the class FreeipaClientTestService method checkUsersInGroup.
public Boolean checkUsersInGroup(String environmentCrn, Set<String> requestedUsers, String requestedGroup) {
FreeIpaClient freeIpaClient = getClientByEnvironmentCrn(environmentCrn);
try {
LOGGER.info("Checking if group [{}] has users [{}] in environment {}", requestedGroup, Joiner.on(",").join(requestedUsers), environmentCrn);
Group freeipaGroup = freeIpaClient.groupShow(requestedGroup);
LOGGER.debug("Group [{}] found in freeipa, it has users [{}].", freeipaGroup.getCn(), freeipaGroup.getMemberUser());
return freeipaGroup.getMemberUser() != null && freeipaGroup.getMemberUser().containsAll(requestedUsers);
} catch (FreeIpaClientException e) {
if (FreeIpaClientExceptionUtil.isNotFoundException(e)) {
LOGGER.debug("Group [{}] not found in freeipa", requestedGroup);
return false;
}
LOGGER.error("Show group FreeIPA call failed!", e);
throw new InternalServerErrorException("Show group FreeIPA call failed!");
}
}
use of com.sequenceiq.freeipa.client.model.Group in project cloudbreak by hortonworks.
the class GroupAddMemberOperationTest method testInvoke.
@Test
public void testInvoke() throws FreeIpaClientException {
Map warnings = Maps.newHashMap();
RPCResponse<Object> rpcResponse = new RPCResponse<>();
Group group = new Group();
group.setMemberUser(USERS);
rpcResponse.setResult(group);
when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenReturn(rpcResponse);
GroupAddMemberOperation.create(GROUP_NAME, USERS, warnings::put).invoke(freeIpaClient);
verify(freeIpaClient).invoke(eq("group_add_member"), anyList(), any(), any());
assertEquals(0, warnings.size());
}
Aggregations