| | |
| | | */ |
| | | package com.gitblit.tests; |
| | | |
| | | import static org.junit.Assert.*; |
| | | import static org.junit.Assert.assertNotNull; |
| | | import static org.junit.Assert.assertNull; |
| | | import static org.junit.Assert.assertTrue; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | |
| | | import com.unboundid.ldap.listener.InMemoryDirectoryServer; |
| | | import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig; |
| | | import com.unboundid.ldap.listener.InMemoryListenerConfig; |
| | | import com.unboundid.ldap.sdk.LDAPConnection; |
| | | import com.unboundid.ldif.LDIFReader; |
| | | |
| | | /** |
| | |
| | | |
| | | private LdapUserService ldapUserService; |
| | | |
| | | int ldapPort = 1389; |
| | | |
| | | @Before |
| | | public 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); |
| | |
| | | @Before |
| | | public void createLdapUserService() { |
| | | Map<Object, Object> backingMap = new HashMap<Object, Object>(); |
| | | backingMap.put("realm.ldap.server", "ldap://localhost:389"); |
| | | 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"); |
| | |
| | | backingMap.put("realm.ldap.accountPattern", "(&(objectClass=person)(sAMAccountName=${username}))"); |
| | | backingMap.put("realm.ldap.groupBase", "OU=Groups,OU=UserControl,OU=MyOrganization,DC=MyDomain"); |
| | | backingMap.put("realm.ldap.groupPattern", "(&(objectClass=group)(member=${dn}))"); |
| | | backingMap.put("realm.ldap.admins", "UserThree @Git_Admins"); |
| | | backingMap.put("realm.ldap.admins", "UserThree @Git_Admins \"@Git Admins\""); |
| | | |
| | | MemorySettings ms = new MemorySettings(backingMap); |
| | | |
| | |
| | | assertNotNull(userTwoModel); |
| | | assertNotNull(userTwoModel.getTeam("git_users")); |
| | | assertNull(userTwoModel.getTeam("git_admins")); |
| | | assertFalse(userTwoModel.canAdmin); |
| | | assertNotNull(userTwoModel.getTeam("git admins")); |
| | | assertTrue(userTwoModel.canAdmin); |
| | | |
| | | UserModel userThreeModel = ldapUserService.authenticate("UserThree", "userThreePassword".toCharArray()); |
| | | assertNotNull(userThreeModel); |