From 9effe1630d97039b3e01cd9b58ed07e75be1d63c Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Mon, 25 Feb 2013 08:40:30 -0500 Subject: [PATCH] Merge pull request #75 from thefake/master --- tests/com/gitblit/tests/LdapUserServiceTest.java | 24 +++++++++++++++++++++--- 1 files changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/com/gitblit/tests/LdapUserServiceTest.java b/tests/com/gitblit/tests/LdapUserServiceTest.java index c7e95c3..a928f4a 100644 --- a/tests/com/gitblit/tests/LdapUserServiceTest.java +++ b/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)); + } } -- Gitblit v1.9.1