From f6d7de15b1471b1c101362dbaf598de8031e6540 Mon Sep 17 00:00:00 2001 From: Alfred Schmid Date: Mon, 3 Feb 2014 10:01:04 +0100 Subject: Load empty groups as empty teams from ldap, when ldap user synchronization is enabled. --- .../com/gitblit/tests/LdapAuthenticationTest.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/test/java/com') diff --git a/src/test/java/com/gitblit/tests/LdapAuthenticationTest.java b/src/test/java/com/gitblit/tests/LdapAuthenticationTest.java index ce3615e0..670dde00 100644 --- a/src/test/java/com/gitblit/tests/LdapAuthenticationTest.java +++ b/src/test/java/com/gitblit/tests/LdapAuthenticationTest.java @@ -34,6 +34,7 @@ import com.gitblit.auth.LdapAuthProvider; import com.gitblit.manager.IUserManager; import com.gitblit.manager.RuntimeManager; import com.gitblit.manager.UserManager; +import com.gitblit.models.TeamModel; import com.gitblit.models.UserModel; import com.gitblit.tests.mock.MemorySettings; import com.unboundid.ldap.listener.InMemoryDirectoryServer; @@ -208,6 +209,23 @@ public class LdapAuthenticationTest extends GitblitUnitTest { assertEquals("Number of ldap users in gitblit user model", 6, countLdapUsersInUserManager()); } + @Test + public void addingGroupsInLdapShouldNotUpdateGitBlitUsersAndGroups() throws Exception { + settings.put("realm.ldap.ldapCachePeriod", "0 MINUTES"); + ds.addEntries(LDIFReader.readEntries(RESOURCE_DIR + "addgroup.ldif")); + ldap.synchronizeWithLdapService(); + assertEquals("Number of ldap groups in gitblit team model", 0, countLdapTeamsInUserManager()); + } + + @Test + public void addingGroupsInLdapShouldUpdateGitBlitUsersAndGroups() throws Exception { + settings.put("realm.ldap.synchronizeUsers.enable", "true"); + settings.put("realm.ldap.ldapCachePeriod", "0 MINUTES"); + ds.addEntries(LDIFReader.readEntries(RESOURCE_DIR + "addgroup.ldif")); + ldap.synchronizeWithLdapService(); + assertEquals("Number of ldap groups in gitblit team model", 1, countLdapTeamsInUserManager()); + } + private int countLdapUsersInUserManager() { int ldapAccountCount = 0; for (UserModel userModel : userManager.getAllUsers()) { @@ -218,4 +236,14 @@ public class LdapAuthenticationTest extends GitblitUnitTest { return ldapAccountCount; } + private int countLdapTeamsInUserManager() { + int ldapAccountCount = 0; + for (TeamModel teamModel : userManager.getAllTeams()) { + if (AccountType.LDAP.equals(teamModel.accountType)) { + ldapAccountCount++; + } + } + return ldapAccountCount; + } + } -- cgit v1.2.3