James Moger
2013-01-05 9e186eedf1a09ca7ac4fbdea32b00e7e5331f7eb
tests/com/gitblit/tests/LdapUserServiceTest.java
@@ -31,6 +31,7 @@
import com.gitblit.LdapUserService;
import com.gitblit.models.UserModel;
import com.gitblit.tests.mock.MemorySettings;
import com.gitblit.utils.StringUtils;
import com.unboundid.ldap.listener.InMemoryDirectoryServer;
import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig;
import com.unboundid.ldap.listener.InMemoryListenerConfig;
@@ -47,11 +48,13 @@
   
   private LdapUserService ldapUserService;
   
   static int ldapPort = 1389;
   @BeforeClass
   public static void createInMemoryLdapServer() throws Exception {
      InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=MyDomain");
      config.addAdditionalBindCredentials("cn=Directory Manager", "password");
      config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("default", 389));
      config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("default", ldapPort));
      config.setSchema(null);
      
      InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config);
@@ -66,8 +69,8 @@
   }
   
   private MemorySettings getSettings() {
      Map<Object, Object> backingMap = new HashMap<Object, Object>();
      backingMap.put("realm.ldap.server", "ldap://localhost:389");
      Map<String, Object> backingMap = new HashMap<String, Object>();
      backingMap.put("realm.ldap.server", "ldap://localhost:" + ldapPort);
      backingMap.put("realm.ldap.domain", "");
      backingMap.put("realm.ldap.username", "cn=Directory Manager");
      backingMap.put("realm.ldap.password", "password");
@@ -152,5 +155,20 @@
      UserModel userOneModel = ldapUserService.authenticate("*)(userPassword=userOnePassword", "userOnePassword".toCharArray());
      assertNull(userOneModel);
   }
   @Test
   public void testLocalAccount() {
      UserModel localAccount = new UserModel("bruce");
      localAccount.displayName = "Bruce Campbell";
      localAccount.password = StringUtils.MD5_TYPE + StringUtils.getMD5("gimmesomesugar");
      ldapUserService.deleteUser(localAccount.username);
      assertTrue("Failed to add local account",
            ldapUserService.updateUserModel(localAccount));
      assertEquals("Accounts are not equal!",
            localAccount,
            ldapUserService.authenticate(localAccount.username, "gimmesomesugar".toCharArray()));
      assertTrue("Failed to delete local account!",
            ldapUserService.deleteUser(localAccount.username));
   }
}