@Test void testApplyStateDifferenceToIpa() throws FreeIpaClientException { FmsGroup groupToAdd1 = new FmsGroup().withName("groupToAdd1"); FmsGroup groupToAdd2 = new FmsGroup().withName("groupToAdd2"); FmsGroup groupToRemove1 = new FmsGroup().withName("groupToRemove1"); FmsGroup groupToRemove2 = new FmsGroup().withName("groupToRemove2"); FmsUser userToAdd1 = new FmsUser().withName("userToAdd1").withFirstName("clark").withLastName("kent"); FmsUser userToAdd2 = new FmsUser().withName("userToAdd2").withFirstName("peter").withLastName("parker"); String userToRemove1 = "userToRemove1"; String userToRemove2 = "userToRemove2"; Multimap<String, String> warnings = ArrayListMultimap.create(); FreeIpaClient freeIpaClient = mock(FreeIpaClient.class); Group addResponseGroup = mock(Group.class, RETURNS_DEEP_STUBS); RPCResponse<Group> mockAddResponse = mock(RPCResponse.class); when(mockAddResponse.getResult()).thenReturn(addResponseGroup); when(addResponseGroup.getMemberUser().containsAll(anyCollection())).thenReturn(true); when(freeIpaClient.groupAddMembers(anyString(), anyCollection())).thenReturn(mockAddResponse); 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(anyString(), anyCollection())).thenReturn(mockRemoveResponse); UsersStateDifference usersStateDifference = new UsersStateDifference( ImmutableSet.of(groupToAdd1, groupToAdd2), ImmutableSet.of(groupToRemove1, groupToRemove2), ImmutableSet.of(userToAdd1, userToAdd2), ImmutableSet.of(userToRemove1, userToRemove2), ImmutableMultimap.<String, String>builder() .put(groupToAdd1.getName(), userToAdd1.getName()) .put(groupToAdd2.getName(), userToAdd2.getName()) .build(), ImmutableMultimap.<String, String>builder() .put(groupToRemove1.getName(), userToRemove1) .put(groupToRemove2.getName(), userToRemove2) .build() ); underTest.applyStateDifferenceToIpa(ENV_CRN, freeIpaClient, usersStateDifference, warnings::put); verify(freeIpaClient).groupAdd(groupToAdd1.getName()); verify(freeIpaClient).groupAdd(groupToAdd2.getName()); verify(freeIpaClient).userAdd(userToAdd1.getName(), userToAdd1.getFirstName(), userToAdd1.getLastName()); verify(freeIpaClient).userAdd(userToAdd2.getName(), userToAdd2.getFirstName(), userToAdd2.getLastName()); verify(freeIpaClient).groupAddMembers(groupToAdd1.getName(), usersStateDifference.getGroupMembershipToAdd().get(groupToAdd1.getName())); verify(freeIpaClient).groupAddMembers(groupToAdd2.getName(), usersStateDifference.getGroupMembershipToAdd().get(groupToAdd2.getName())); verify(freeIpaClient).groupRemoveMembers(groupToRemove1.getName(), usersStateDifference.getGroupMembershipToRemove().get(groupToRemove1.getName())); verify(freeIpaClient).groupRemoveMembers(groupToRemove2.getName(), usersStateDifference.getGroupMembershipToRemove().get(groupToRemove2.getName())); verify(freeIpaClient).deleteUser(userToRemove1); verify(freeIpaClient).deleteUser(userToRemove2); verify(freeIpaClient).deleteGroup(groupToRemove1.getName()); verify(freeIpaClient).deleteGroup(groupToRemove2.getName()); verifyNoMoreInteractions(freeIpaClient); }
@VisibleForTesting void applyStateDifferenceToIpa(String environmentCrn, FreeIpaClient freeIpaClient, UsersStateDifference stateDifference, BiConsumer<String, String> warnings) throws FreeIpaClientException { LOGGER.info("Applying state difference to environment {}.", environmentCrn); LOGGER.debug("Starting {} ...", LogEvent.ADD_GROUPS); addGroups(freeIpaClient, stateDifference.getGroupsToAdd(), warnings); LOGGER.debug("Finished {}.", LogEvent.ADD_GROUPS); LOGGER.debug("Starting {} ...", LogEvent.ADD_USERS); addUsers(freeIpaClient, stateDifference.getUsersToAdd(), warnings); LOGGER.debug("Finished {}.", LogEvent.ADD_USERS); LOGGER.debug("Starting {} ...", LogEvent.ADD_USERS_TO_GROUPS); addUsersToGroups(freeIpaClient, stateDifference.getGroupMembershipToAdd(), warnings); LOGGER.debug("Finished {}.", LogEvent.ADD_USERS_TO_GROUPS); LOGGER.debug("Starting {} ...", LogEvent.REMOVE_USERS_FROM_GROUPS); removeUsersFromGroups(freeIpaClient, stateDifference.getGroupMembershipToRemove(), warnings); LOGGER.debug("Finished {}.", LogEvent.REMOVE_USERS_FROM_GROUPS); LOGGER.debug("Starting {} ...", LogEvent.REMOVE_USERS); removeUsers(freeIpaClient, stateDifference.getUsersToRemove(), warnings); LOGGER.debug("Finished {}.", LogEvent.REMOVE_USERS); LOGGER.debug("Starting {} ...", LogEvent.REMOVE_GROUPS); removeGroups(freeIpaClient, stateDifference.getGroupsToRemove(), warnings); LOGGER.debug("Finished {}.", LogEvent.REMOVE_GROUPS); }
UserSyncService { @VisibleForTesting void applyStateDifferenceToIpa(String environmentCrn, FreeIpaClient freeIpaClient, UsersStateDifference stateDifference, BiConsumer<String, String> warnings) throws FreeIpaClientException { LOGGER.info("Applying state difference to environment {}.", environmentCrn); LOGGER.debug("Starting {} ...", LogEvent.ADD_GROUPS); addGroups(freeIpaClient, stateDifference.getGroupsToAdd(), warnings); LOGGER.debug("Finished {}.", LogEvent.ADD_GROUPS); LOGGER.debug("Starting {} ...", LogEvent.ADD_USERS); addUsers(freeIpaClient, stateDifference.getUsersToAdd(), warnings); LOGGER.debug("Finished {}.", LogEvent.ADD_USERS); LOGGER.debug("Starting {} ...", LogEvent.ADD_USERS_TO_GROUPS); addUsersToGroups(freeIpaClient, stateDifference.getGroupMembershipToAdd(), warnings); LOGGER.debug("Finished {}.", LogEvent.ADD_USERS_TO_GROUPS); LOGGER.debug("Starting {} ...", LogEvent.REMOVE_USERS_FROM_GROUPS); removeUsersFromGroups(freeIpaClient, stateDifference.getGroupMembershipToRemove(), warnings); LOGGER.debug("Finished {}.", LogEvent.REMOVE_USERS_FROM_GROUPS); LOGGER.debug("Starting {} ...", LogEvent.REMOVE_USERS); removeUsers(freeIpaClient, stateDifference.getUsersToRemove(), warnings); LOGGER.debug("Finished {}.", LogEvent.REMOVE_USERS); LOGGER.debug("Starting {} ...", LogEvent.REMOVE_GROUPS); removeGroups(freeIpaClient, stateDifference.getGroupsToRemove(), warnings); LOGGER.debug("Finished {}.", LogEvent.REMOVE_GROUPS); } }
UserSyncService { @VisibleForTesting void applyStateDifferenceToIpa(String environmentCrn, FreeIpaClient freeIpaClient, UsersStateDifference stateDifference, BiConsumer<String, String> warnings) throws FreeIpaClientException { LOGGER.info("Applying state difference to environment {}.", environmentCrn); LOGGER.debug("Starting {} ...", LogEvent.ADD_GROUPS); addGroups(freeIpaClient, stateDifference.getGroupsToAdd(), warnings); LOGGER.debug("Finished {}.", LogEvent.ADD_GROUPS); LOGGER.debug("Starting {} ...", LogEvent.ADD_USERS); addUsers(freeIpaClient, stateDifference.getUsersToAdd(), warnings); LOGGER.debug("Finished {}.", LogEvent.ADD_USERS); LOGGER.debug("Starting {} ...", LogEvent.ADD_USERS_TO_GROUPS); addUsersToGroups(freeIpaClient, stateDifference.getGroupMembershipToAdd(), warnings); LOGGER.debug("Finished {}.", LogEvent.ADD_USERS_TO_GROUPS); LOGGER.debug("Starting {} ...", LogEvent.REMOVE_USERS_FROM_GROUPS); removeUsersFromGroups(freeIpaClient, stateDifference.getGroupMembershipToRemove(), warnings); LOGGER.debug("Finished {}.", LogEvent.REMOVE_USERS_FROM_GROUPS); LOGGER.debug("Starting {} ...", LogEvent.REMOVE_USERS); removeUsers(freeIpaClient, stateDifference.getUsersToRemove(), warnings); LOGGER.debug("Finished {}.", LogEvent.REMOVE_USERS); LOGGER.debug("Starting {} ...", LogEvent.REMOVE_GROUPS); removeGroups(freeIpaClient, stateDifference.getGroupsToRemove(), warnings); LOGGER.debug("Finished {}.", LogEvent.REMOVE_GROUPS); }  }
UserSyncService { @VisibleForTesting void applyStateDifferenceToIpa(String environmentCrn, FreeIpaClient freeIpaClient, UsersStateDifference stateDifference, BiConsumer<String, String> warnings) throws FreeIpaClientException { LOGGER.info("Applying state difference to environment {}.", environmentCrn); LOGGER.debug("Starting {} ...", LogEvent.ADD_GROUPS); addGroups(freeIpaClient, stateDifference.getGroupsToAdd(), warnings); LOGGER.debug("Finished {}.", LogEvent.ADD_GROUPS); LOGGER.debug("Starting {} ...", LogEvent.ADD_USERS); addUsers(freeIpaClient, stateDifference.getUsersToAdd(), warnings); LOGGER.debug("Finished {}.", LogEvent.ADD_USERS); LOGGER.debug("Starting {} ...", LogEvent.ADD_USERS_TO_GROUPS); addUsersToGroups(freeIpaClient, stateDifference.getGroupMembershipToAdd(), warnings); LOGGER.debug("Finished {}.", LogEvent.ADD_USERS_TO_GROUPS); LOGGER.debug("Starting {} ...", LogEvent.REMOVE_USERS_FROM_GROUPS); removeUsersFromGroups(freeIpaClient, stateDifference.getGroupMembershipToRemove(), warnings); LOGGER.debug("Finished {}.", LogEvent.REMOVE_USERS_FROM_GROUPS); LOGGER.debug("Starting {} ...", LogEvent.REMOVE_USERS); removeUsers(freeIpaClient, stateDifference.getUsersToRemove(), warnings); LOGGER.debug("Finished {}.", LogEvent.REMOVE_USERS); LOGGER.debug("Starting {} ...", LogEvent.REMOVE_GROUPS); removeGroups(freeIpaClient, stateDifference.getGroupsToRemove(), warnings); LOGGER.debug("Finished {}.", LogEvent.REMOVE_GROUPS); }  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 applyStateDifferenceToIpa(String environmentCrn, FreeIpaClient freeIpaClient, UsersStateDifference stateDifference, BiConsumer<String, String> warnings) throws FreeIpaClientException { LOGGER.info("Applying state difference to environment {}.", environmentCrn); LOGGER.debug("Starting {} ...", LogEvent.ADD_GROUPS); addGroups(freeIpaClient, stateDifference.getGroupsToAdd(), warnings); LOGGER.debug("Finished {}.", LogEvent.ADD_GROUPS); LOGGER.debug("Starting {} ...", LogEvent.ADD_USERS); addUsers(freeIpaClient, stateDifference.getUsersToAdd(), warnings); LOGGER.debug("Finished {}.", LogEvent.ADD_USERS); LOGGER.debug("Starting {} ...", LogEvent.ADD_USERS_TO_GROUPS); addUsersToGroups(freeIpaClient, stateDifference.getGroupMembershipToAdd(), warnings); LOGGER.debug("Finished {}.", LogEvent.ADD_USERS_TO_GROUPS); LOGGER.debug("Starting {} ...", LogEvent.REMOVE_USERS_FROM_GROUPS); removeUsersFromGroups(freeIpaClient, stateDifference.getGroupMembershipToRemove(), warnings); LOGGER.debug("Finished {}.", LogEvent.REMOVE_USERS_FROM_GROUPS); LOGGER.debug("Starting {} ...", LogEvent.REMOVE_USERS); removeUsers(freeIpaClient, stateDifference.getUsersToRemove(), warnings); LOGGER.debug("Finished {}.", LogEvent.REMOVE_USERS); LOGGER.debug("Starting {} ...", LogEvent.REMOVE_GROUPS); removeGroups(freeIpaClient, stateDifference.getGroupsToRemove(), warnings); LOGGER.debug("Finished {}.", LogEvent.REMOVE_GROUPS); }  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);  }