Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync org admins #849

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Refactoring
  • Loading branch information
dankle committed Dec 14, 2023
commit bfd64e62926b0a2990996f25ed7933ad2aff51f3
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,14 @@ public List<UserItem> listOrgOwners() {
* @param ldapGroupUsers
* @param ownerRoleUsers
*/
Tuple2<List, List> checkOrgOwnerDiscrepancies(List<UserItem> ldapGroupUsers, List<UserItem> ownerRoleUsers) {
List<UserItem> diffUsersOnlyInLdapGroup = ldapGroupUsers.stream()
.filter(item -> !ownerRoleUsers.contains(item))
.toList();

List<UserItem> checkOrgOwnerDiscrepancies(List<UserItem> ldapGroupUsers, List<UserItem> ownerRoleUsers) {
List<UserItem> diffUsersWithOwnerRoleAndNotInLdap = ownerRoleUsers.stream()
.filter(item -> !ldapGroupUsers.contains(item))
.toList();


log.info("checkOrgOwnerDiscrepancies -> done, {} user(s) only in ldapGroup not registered as owners", diffUsersOnlyInLdapGroup.stream().map(Object::toString).collect(Collectors.joining(", ")));
log.info("checkOrgOwnerDiscrepancies -> done, {} user(s) only registered as owners not in ldapGroup", diffUsersWithOwnerRoleAndNotInLdap.stream().map(Object::toString).collect(Collectors.joining(", ")));

return new Tuple2<>(diffUsersOnlyInLdapGroup, diffUsersWithOwnerRoleAndNotInLdap);
return diffUsersWithOwnerRoleAndNotInLdap;
}

static class UserItem implements Comparable<UserItem> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.walmartlabs.concord.server.user.UserManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import scala.Tuple2;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -26,26 +25,6 @@ public void init() {
mock(UserManager.class));
}

@Test
void checkOrgOwnerDiscrepanciesDiffUsersOnlyInLdap() {
UserLdapGroupSynchronizer.UserItem user1 = new UserLdapGroupSynchronizer.UserItem(UUID.randomUUID(), "admin", "domain", false);
UserLdapGroupSynchronizer.UserItem user2 = new UserLdapGroupSynchronizer.UserItem(UUID.randomUUID(), "testUser", null, false);

List<UserLdapGroupSynchronizer.UserItem> ldapGroupUsers = new ArrayList<>();
ldapGroupUsers.add(user1);
ldapGroupUsers.add(user2);

List<UserLdapGroupSynchronizer.UserItem> ownerRoleUsers = new ArrayList<>();
ownerRoleUsers.add(user1);

List<UserLdapGroupSynchronizer.UserItem> usersOnlyInLdapGroup = new ArrayList<>();
usersOnlyInLdapGroup.add(user2);

Tuple2<List, List> values = userLdapGroupSynchronizer.checkOrgOwnerDiscrepancies(ldapGroupUsers, ownerRoleUsers);
assertTrue(values._1().equals(usersOnlyInLdapGroup));
assertTrue(values._2().isEmpty());
}

@Test
void checkOrgOwnerDiscrepanciesDiffOwnersNotInLdap() {
UserLdapGroupSynchronizer.UserItem user1 = new UserLdapGroupSynchronizer.UserItem(UUID.randomUUID(), "admin", "domain", false);
Expand All @@ -61,9 +40,7 @@ void checkOrgOwnerDiscrepanciesDiffOwnersNotInLdap() {
List<UserLdapGroupSynchronizer.UserItem> ownersNotInLdapGroup = new ArrayList<>();
ownersNotInLdapGroup.add(user2);

Tuple2<List, List> values = userLdapGroupSynchronizer.checkOrgOwnerDiscrepancies(ldapGroupUsers, ownerRoleUsers);
assertTrue(values._1().isEmpty());
assertTrue(values._2().equals(ownersNotInLdapGroup));
assertTrue(userLdapGroupSynchronizer.checkOrgOwnerDiscrepancies(ldapGroupUsers, ownerRoleUsers).equals(ownersNotInLdapGroup));
}

@Test
Expand All @@ -79,8 +56,6 @@ void checkOrgOwnerDiscrepanciesNoDiff() {
ownerRoleUsers.add(user1);
ownerRoleUsers.add(user2);

Tuple2<List, List> values = userLdapGroupSynchronizer.checkOrgOwnerDiscrepancies(ldapGroupUsers, ownerRoleUsers);
assertTrue(values._1().isEmpty());
assertTrue(values._2().isEmpty());
assertTrue(userLdapGroupSynchronizer.checkOrgOwnerDiscrepancies(ldapGroupUsers, ownerRoleUsers).isEmpty());
}
}