summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/config/test-users.conf5
-rw-r--r--src/test/java/com/gitblit/tests/LdapAuthenticationTest.java43
-rw-r--r--src/test/resources/ldap/adduser.ldif11
-rw-r--r--src/test/resources/ldap/users.conf19
4 files changed, 73 insertions, 5 deletions
diff --git a/src/test/config/test-users.conf b/src/test/config/test-users.conf
index 59b6df49..1d01f846 100644
--- a/src/test/config/test-users.conf
+++ b/src/test/config/test-users.conf
@@ -4,6 +4,11 @@
accountType = LOCAL
role = "#admin"
role = "#notfederated"
+[user "sampleuser"]
+ password = sampleuser
+ cookie = 6e07ed42149fc166206319faffdfba2e2ec82e43
+ accountType = LOCAL
+ role = "#none"
[team "admins"]
role = "#none"
accountType = LOCAL
diff --git a/src/test/java/com/gitblit/tests/LdapAuthenticationTest.java b/src/test/java/com/gitblit/tests/LdapAuthenticationTest.java
index 3cd2dc72..4c78643d 100644
--- a/src/test/java/com/gitblit/tests/LdapAuthenticationTest.java
+++ b/src/test/java/com/gitblit/tests/LdapAuthenticationTest.java
@@ -24,8 +24,10 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import com.gitblit.Constants.AccountType;
import com.gitblit.IStoredSettings;
import com.gitblit.auth.LdapAuthProvider;
+import com.gitblit.manager.IUserManager;
import com.gitblit.manager.RuntimeManager;
import com.gitblit.manager.UserManager;
import com.gitblit.models.UserModel;
@@ -33,6 +35,8 @@ import com.gitblit.tests.mock.MemorySettings;
import com.unboundid.ldap.listener.InMemoryDirectoryServer;
import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig;
import com.unboundid.ldap.listener.InMemoryListenerConfig;
+import com.unboundid.ldap.sdk.SearchResult;
+import com.unboundid.ldap.sdk.SearchScope;
import com.unboundid.ldif.LDIFReader;
/**
@@ -50,6 +54,10 @@ public class LdapAuthenticationTest extends GitblitUnitTest {
static int ldapPort = 1389;
+ private static InMemoryDirectoryServer ds;
+
+ private IUserManager userManager;
+
@BeforeClass
public static void createInMemoryLdapServer() throws Exception {
InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=MyDomain");
@@ -57,7 +65,7 @@ public class LdapAuthenticationTest extends GitblitUnitTest {
config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("default", ldapPort));
config.setSchema(null);
- InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config);
+ ds = new InMemoryDirectoryServer(config);
ds.importFromLDIF(true, new LDIFReader(new FileInputStream(RESOURCE_DIR + "sampledata.ldif")));
ds.startListening();
}
@@ -69,9 +77,9 @@ public class LdapAuthenticationTest extends GitblitUnitTest {
public LdapAuthProvider newLdapAuthentication(IStoredSettings settings) {
RuntimeManager runtime = new RuntimeManager(settings, GitBlitSuite.BASEFOLDER).start();
- UserManager users = new UserManager(runtime).start();
+ userManager = new UserManager(runtime).start();
LdapAuthProvider ldap = new LdapAuthProvider();
- ldap.setup(runtime, users);
+ ldap.setup(runtime, userManager);
return ldap;
}
@@ -91,6 +99,9 @@ public class LdapAuthenticationTest extends GitblitUnitTest {
backingMap.put("realm.ldap.admins", "UserThree @Git_Admins \"@Git Admins\"");
backingMap.put("realm.ldap.displayName", "displayName");
backingMap.put("realm.ldap.email", "email");
+ backingMap.put("realm.ldap.synchronizeUsers.enable", "true");
+ backingMap.put("realm.ldap.uid", "sAMAccountName");
+ backingMap.put("realm.ldap.ldapCachePeriod", "0 MINUTES");
MemorySettings ms = new MemorySettings(backingMap);
return ms;
@@ -162,4 +173,30 @@ public class LdapAuthenticationTest extends GitblitUnitTest {
assertNull(userOneModel);
}
+ @Test
+ public void checkIfSevenUsersLoadedFromLdap() throws Exception {
+ SearchResult searchResult = ds.search("OU=Users,OU=UserControl,OU=MyOrganization,DC=MyDomain", SearchScope.SUB, "objectClass=person");
+ assertEquals("Number of ldap users in gitblit user model", searchResult.getEntryCount(), countLdapUsersInUserManager());
+ }
+
+ @Test
+ public void addingUserInLdapShouldUpdateGitBlitUsersAndGroups() throws Exception {
+ ds.addEntries(LDIFReader.readEntries(RESOURCE_DIR + "adduser.ldif"));
+ for(String user : userManager.getAllUsernames()) {
+ System.out.println(user);
+ }
+ ldap.synchronizeWithLdapService();
+ assertEquals("Number of ldap users in gitblit user model", 5, countLdapUsersInUserManager());
+ }
+
+ private int countLdapUsersInUserManager() {
+ int ldapAccountCount = 0;
+ for (UserModel userModel : userManager.getAllUsers()) {
+ if (AccountType.LDAP.equals(userModel.accountType)) {
+ ldapAccountCount++;
+ }
+ }
+ return ldapAccountCount;
+ }
+
}
diff --git a/src/test/resources/ldap/adduser.ldif b/src/test/resources/ldap/adduser.ldif
new file mode 100644
index 00000000..e7e3520b
--- /dev/null
+++ b/src/test/resources/ldap/adduser.ldif
@@ -0,0 +1,11 @@
+dn: CN=UserFive,OU=Canada,OU=Users,OU=UserControl,OU=MyOrganization,DC=MyDomain
+objectClass: user
+objectClass: person
+sAMAccountName: UserFive
+userPassword: userFivePassword
+displayName: User Five
+givenName: User
+surname: Five
+personalTitle: Miss
+email: userfive@gitblit.com
+memberOf: CN=Git_Users,OU=Groups,OU=UserControl,OU=MyOrganization,DC=MyDomain \ No newline at end of file
diff --git a/src/test/resources/ldap/users.conf b/src/test/resources/ldap/users.conf
index b4b4a6ea..7d1e3197 100644
--- a/src/test/resources/ldap/users.conf
+++ b/src/test/resources/ldap/users.conf
@@ -7,10 +7,17 @@
[user "userthree"]
password = "#externalAccount"
cookie = d7d3894fc517612aa6c595555b6e1ab8e147e597
- displayName = User Three
+ displayName = Mrs. User Three
emailAddress = userthree@gitblit.com
accountType = LDAP
role = "#admin"
+[user "userfive"]
+ password = "#externalAccount"
+ cookie = 220bafef069b8b399b2597644015b6b0f4667982
+ displayName = Miss. User Five
+ emailAddress = userfive@gitblit.com
+ accountType = LDAP
+ role = "#none"
[user "userone"]
password = "#externalAccount"
cookie = c97cd38e50858cd0b389ec61b18fb9a89b4da54c
@@ -21,7 +28,7 @@
[user "usertwo"]
password = "#externalAccount"
cookie = 498ca9bd2841d39050fa45d1d737b9f9f767858d
- displayName = User Two
+ displayName = Mr. User Two
emailAddress = usertwo@gitblit.com
accountType = LDAP
role = "#admin"
@@ -37,6 +44,13 @@
cookie = dd94709528bb1c83d08f3088d4043f4742891f4f
accountType = LOCAL
role = "#create"
+[user "userfour"]
+ password = "#externalAccount"
+ cookie = d4fca47ebc70f0495947f8b6158ac6edb546e2fe
+ displayName = Miss. User Four
+ emailAddress = userfour@gitblit.com
+ accountType = LDAP
+ role = "#none"
[team "Git_Admins"]
role = "#none"
accountType = LOCAL
@@ -47,6 +61,7 @@
user = userone
user = usertwo
user = userthree
+ user = userfour
[team "Git Admins"]
role = "#none"
accountType = LOCAL