@Test void testRemoveUsersFromGroupsNullMembersInResponse() throws Exception { Multimap<String, String> groupMapping = setupGroupMapping(1, 1); FreeIpaClient freeIpaClient = mock(FreeIpaClient.class); Group removeResponseGroup = mock(Group.class, RETURNS_DEEP_STUBS); RPCResponse<Group> mockRemoveResponse = mock(RPCResponse.class); when(mockRemoveResponse.getResult()).thenReturn(removeResponseGroup); when(removeResponseGroup.getMemberUser()).thenReturn(null); when(freeIpaClient.groupRemoveMembers(any(), any())).thenReturn(mockRemoveResponse); Multimap<String, String> warnings = ArrayListMultimap.create(); underTest.removeUsersFromGroups(freeIpaClient, groupMapping, warnings::put); assertTrue(warnings.isEmpty()); }
@VisibleForTesting void removeUsersFromGroups(FreeIpaClient freeIpaClient, Multimap<String, String> groupMapping, BiConsumer<String, String> warnings) throws FreeIpaClientException { for (String group : groupMapping.keySet()) { for (List<String> users : Iterables.partition(groupMapping.get(group), maxSubjectsPerRequest)) { LOGGER.debug("removing users {} from group {}", users, group); try { RPCResponse<Group> groupRemoveMembersResponse = freeIpaClient.groupRemoveMembers(group, users); List<String> members = Optional.ofNullable(groupRemoveMembersResponse.getResult().getMemberUser()).orElse(List.of()); if (Collections.disjoint(members, users)) { LOGGER.debug("Successfully removed users {} from {}", users, groupRemoveMembersResponse.getResult()); } else { LOGGER.error("Failed to remove {} from group '{}': {}", users, group, groupRemoveMembersResponse.getFailed()); warnings.accept(group, String.format("Failed to remove users from group: %s", groupRemoveMembersResponse.getFailed())); } } catch (FreeIpaClientException e) { LOGGER.error("Failed to remove {} from group '{}'", users, group, e); warnings.accept(group, String.format("Failed to remove users %s from group: %s", users, e.getMessage())); checkIfClientStillUsable(e); } } } }
UserSyncService { @VisibleForTesting void removeUsersFromGroups(FreeIpaClient freeIpaClient, Multimap<String, String> groupMapping, BiConsumer<String, String> warnings) throws FreeIpaClientException { for (String group : groupMapping.keySet()) { for (List<String> users : Iterables.partition(groupMapping.get(group), maxSubjectsPerRequest)) { LOGGER.debug("removing users {} from group {}", users, group); try { RPCResponse<Group> groupRemoveMembersResponse = freeIpaClient.groupRemoveMembers(group, users); List<String> members = Optional.ofNullable(groupRemoveMembersResponse.getResult().getMemberUser()).orElse(List.of()); if (Collections.disjoint(members, users)) { LOGGER.debug("Successfully removed users {} from {}", users, groupRemoveMembersResponse.getResult()); } else { LOGGER.error("Failed to remove {} from group '{}': {}", users, group, groupRemoveMembersResponse.getFailed()); warnings.accept(group, String.format("Failed to remove users from group: %s", groupRemoveMembersResponse.getFailed())); } } catch (FreeIpaClientException e) { LOGGER.error("Failed to remove {} from group '{}'", users, group, e); warnings.accept(group, String.format("Failed to remove users %s from group: %s", users, e.getMessage())); checkIfClientStillUsable(e); } } } } }
UserSyncService { @VisibleForTesting void removeUsersFromGroups(FreeIpaClient freeIpaClient, Multimap<String, String> groupMapping, BiConsumer<String, String> warnings) throws FreeIpaClientException { for (String group : groupMapping.keySet()) { for (List<String> users : Iterables.partition(groupMapping.get(group), maxSubjectsPerRequest)) { LOGGER.debug("removing users {} from group {}", users, group); try { RPCResponse<Group> groupRemoveMembersResponse = freeIpaClient.groupRemoveMembers(group, users); List<String> members = Optional.ofNullable(groupRemoveMembersResponse.getResult().getMemberUser()).orElse(List.of()); if (Collections.disjoint(members, users)) { LOGGER.debug("Successfully removed users {} from {}", users, groupRemoveMembersResponse.getResult()); } else { LOGGER.error("Failed to remove {} from group '{}': {}", users, group, groupRemoveMembersResponse.getFailed()); warnings.accept(group, String.format("Failed to remove users from group: %s", groupRemoveMembersResponse.getFailed())); } } catch (FreeIpaClientException e) { LOGGER.error("Failed to remove {} from group '{}'", users, group, e); warnings.accept(group, String.format("Failed to remove users %s from group: %s", users, e.getMessage())); checkIfClientStillUsable(e); } } } }  }
UserSyncService { @VisibleForTesting void removeUsersFromGroups(FreeIpaClient freeIpaClient, Multimap<String, String> groupMapping, BiConsumer<String, String> warnings) throws FreeIpaClientException { for (String group : groupMapping.keySet()) { for (List<String> users : Iterables.partition(groupMapping.get(group), maxSubjectsPerRequest)) { LOGGER.debug("removing users {} from group {}", users, group); try { RPCResponse<Group> groupRemoveMembersResponse = freeIpaClient.groupRemoveMembers(group, users); List<String> members = Optional.ofNullable(groupRemoveMembersResponse.getResult().getMemberUser()).orElse(List.of()); if (Collections.disjoint(members, users)) { LOGGER.debug("Successfully removed users {} from {}", users, groupRemoveMembersResponse.getResult()); } else { LOGGER.error("Failed to remove {} from group '{}': {}", users, group, groupRemoveMembersResponse.getFailed()); warnings.accept(group, String.format("Failed to remove users from group: %s", groupRemoveMembersResponse.getFailed())); } } catch (FreeIpaClientException e) { LOGGER.error("Failed to remove {} from group '{}'", users, group, e); warnings.accept(group, String.format("Failed to remove users %s from group: %s", users, e.getMessage())); checkIfClientStillUsable(e); } } } }  Operation synchronizeUsers(String accountId, String actorCrn, Set<String> environmentCrnFilter,
            Set<String> userCrnFilter, Set<String> machineUserCrnFilter); Operation synchronizeUsersWithCustomPermissionCheck(String accountId, String actorCrn, Set<String> environmentCrnFilter,
            UserSyncRequestFilter userSyncFilter, AuthorizationResourceAction action); }
UserSyncService { @VisibleForTesting void removeUsersFromGroups(FreeIpaClient freeIpaClient, Multimap<String, String> groupMapping, BiConsumer<String, String> warnings) throws FreeIpaClientException { for (String group : groupMapping.keySet()) { for (List<String> users : Iterables.partition(groupMapping.get(group), maxSubjectsPerRequest)) { LOGGER.debug("removing users {} from group {}", users, group); try { RPCResponse<Group> groupRemoveMembersResponse = freeIpaClient.groupRemoveMembers(group, users); List<String> members = Optional.ofNullable(groupRemoveMembersResponse.getResult().getMemberUser()).orElse(List.of()); if (Collections.disjoint(members, users)) { LOGGER.debug("Successfully removed users {} from {}", users, groupRemoveMembersResponse.getResult()); } else { LOGGER.error("Failed to remove {} from group '{}': {}", users, group, groupRemoveMembersResponse.getFailed()); warnings.accept(group, String.format("Failed to remove users from group: %s", groupRemoveMembersResponse.getFailed())); } } catch (FreeIpaClientException e) { LOGGER.error("Failed to remove {} from group '{}'", users, group, e); warnings.accept(group, String.format("Failed to remove users %s from group: %s", users, e.getMessage())); checkIfClientStillUsable(e); } } } }  Operation synchronizeUsers(String accountId, String actorCrn, Set<String> environmentCrnFilter,
            Set<String> userCrnFilter, Set<String> machineUserCrnFilter); Operation synchronizeUsersWithCustomPermissionCheck(String accountId, String actorCrn, Set<String> environmentCrnFilter,
            UserSyncRequestFilter userSyncFilter, AuthorizationResourceAction action);  }