summaryrefslogtreecommitdiffstats
path: root/src/test/java/com/gitblit/tests/LdapAuthenticationTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/gitblit/tests/LdapAuthenticationTest.java')
-rw-r--r--src/test/java/com/gitblit/tests/LdapAuthenticationTest.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/test/java/com/gitblit/tests/LdapAuthenticationTest.java b/src/test/java/com/gitblit/tests/LdapAuthenticationTest.java
index e4dc2db2..b037754c 100644
--- a/src/test/java/com/gitblit/tests/LdapAuthenticationTest.java
+++ b/src/test/java/com/gitblit/tests/LdapAuthenticationTest.java
@@ -32,6 +32,7 @@ import com.gitblit.Constants.AccountType;
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
import com.gitblit.auth.LdapAuthProvider;
+import com.gitblit.manager.AuthenticationManager;
import com.gitblit.manager.IUserManager;
import com.gitblit.manager.RuntimeManager;
import com.gitblit.manager.UserManager;
@@ -67,6 +68,8 @@ public class LdapAuthenticationTest extends GitblitUnitTest {
private static InMemoryDirectoryServer ds;
private IUserManager userManager;
+
+ private AuthenticationManager auth;
private MemorySettings settings;
@@ -89,6 +92,7 @@ public class LdapAuthenticationTest extends GitblitUnitTest {
FileUtils.copyFile(new File(RESOURCE_DIR + "users.conf"), usersConf);
settings = getSettings();
ldap = newLdapAuthentication(settings);
+ auth = newAuthenticationManager(settings);
}
private LdapAuthProvider newLdapAuthentication(IStoredSettings settings) {
@@ -98,6 +102,13 @@ public class LdapAuthenticationTest extends GitblitUnitTest {
ldap.setup(runtime, userManager);
return ldap;
}
+
+ private AuthenticationManager newAuthenticationManager(IStoredSettings settings) {
+ RuntimeManager runtime = new RuntimeManager(settings, GitBlitSuite.BASEFOLDER).start();
+ AuthenticationManager auth = new AuthenticationManager(runtime, userManager);
+ auth.addAuthenticationProvider(newLdapAuthentication(settings));
+ return auth;
+ }
private MemorySettings getSettings() {
Map<String, Object> backingMap = new HashMap<String, Object>();
@@ -223,6 +234,31 @@ public class LdapAuthenticationTest extends GitblitUnitTest {
assertEquals("Number of ldap groups in gitblit team model", 1, countLdapTeamsInUserManager());
}
+ @Test
+ public void testAuthenticationManager() {
+ UserModel userOneModel = auth.authenticate("UserOne", "userOnePassword".toCharArray());
+ assertNotNull(userOneModel);
+ assertNotNull(userOneModel.getTeam("git_admins"));
+ assertNotNull(userOneModel.getTeam("git_users"));
+ assertTrue(userOneModel.canAdmin);
+
+ UserModel userOneModelFailedAuth = auth.authenticate("UserOne", "userTwoPassword".toCharArray());
+ assertNull(userOneModelFailedAuth);
+
+ UserModel userTwoModel = auth.authenticate("UserTwo", "userTwoPassword".toCharArray());
+ assertNotNull(userTwoModel);
+ assertNotNull(userTwoModel.getTeam("git_users"));
+ assertNull(userTwoModel.getTeam("git_admins"));
+ assertNotNull(userTwoModel.getTeam("git admins"));
+ assertTrue(userTwoModel.canAdmin);
+
+ UserModel userThreeModel = auth.authenticate("UserThree", "userThreePassword".toCharArray());
+ assertNotNull(userThreeModel);
+ assertNotNull(userThreeModel.getTeam("git_users"));
+ assertNull(userThreeModel.getTeam("git_admins"));
+ assertTrue(userThreeModel.canAdmin);
+ }
+
private int countLdapUsersInUserManager() {
int ldapAccountCount = 0;
for (UserModel userModel : userManager.getAllUsers()) {