]> source.dussan.org Git - gitblit.git/commitdiff
Use dynamic port selection for LDAP listeners in LDAP tests.
authorFlorian Zschocke <florian.zschocke@devolo.de>
Sat, 26 Nov 2016 16:35:21 +0000 (17:35 +0100)
committerFlorian Zschocke <florian.zschocke@devolo.de>
Tue, 6 Dec 2016 14:34:56 +0000 (15:34 +0100)
Instead of using fixed ports for the listeners of the in-memory
LDAP server, let the listeners select ports and then save them in
the authentication mode instance. This way we prevent port collisions,
which especially showed up under Windows.

src/test/java/com/gitblit/tests/LdapBasedUnitTest.java

index cf3ab1fa0a44140f7a20443dba1a67607654ba40..7aec50e6e3fbfdb5fd11562c86cffc1742a3c873 100644 (file)
@@ -74,9 +74,9 @@ public abstract class LdapBasedUnitTest extends GitblitUnitTest {
         *
         */
        protected enum AuthMode {
-               ANONYMOUS(1389),
-               DS_MANAGER(2389),
-               USR_MANAGER(3389);
+               ANONYMOUS,
+               DS_MANAGER,
+               USR_MANAGER;
 
 
                private int ldapPort;
@@ -84,7 +84,7 @@ public abstract class LdapBasedUnitTest extends GitblitUnitTest {
                private InMemoryDirectoryServerSnapshot dsSnapshot;
                private BindTracker bindTracker;
 
-               AuthMode(int port) {
+               void setLdapPort(int port) {
                        this.ldapPort = port;
                }
 
@@ -151,23 +151,26 @@ public abstract class LdapBasedUnitTest extends GitblitUnitTest {
        public static void ldapInit() throws Exception {
                InMemoryDirectoryServer ds;
                InMemoryDirectoryServerConfig config = createInMemoryLdapServerConfig(AuthMode.ANONYMOUS);
-               config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("default", AuthMode.ANONYMOUS.ldapPort()));
+               config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("anonymous"));
                ds = createInMemoryLdapServer(config);
                AuthMode.ANONYMOUS.setDS(ds);
+               AuthMode.ANONYMOUS.setLdapPort(ds.getListenPort("anonymous"));
 
 
                config = createInMemoryLdapServerConfig(AuthMode.DS_MANAGER);
-               config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("default", AuthMode.DS_MANAGER.ldapPort()));
+               config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("ds_manager"));
                config.setAuthenticationRequiredOperationTypes(EnumSet.allOf(OperationType.class));
                ds = createInMemoryLdapServer(config);
                AuthMode.DS_MANAGER.setDS(ds);
+               AuthMode.DS_MANAGER.setLdapPort(ds.getListenPort("ds_manager"));
 
 
                config = createInMemoryLdapServerConfig(AuthMode.USR_MANAGER);
-               config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("default", AuthMode.USR_MANAGER.ldapPort()));
+               config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("usr_manager"));
                config.setAuthenticationRequiredOperationTypes(EnumSet.allOf(OperationType.class));
                ds = createInMemoryLdapServer(config);
                AuthMode.USR_MANAGER.setDS(ds);
+               AuthMode.USR_MANAGER.setLdapPort(ds.getListenPort("usr_manager"));
 
        }
 
@@ -220,19 +223,17 @@ public abstract class LdapBasedUnitTest extends GitblitUnitTest {
        protected MemorySettings getSettings() {
                Map<String, Object> backingMap = new HashMap<String, Object>();
                backingMap.put(Keys.realm.userService, usersConf.getAbsolutePath());
+               backingMap.put(Keys.realm.ldap.server, "ldap://localhost:" + authMode.ldapPort());
                switch(authMode) {
                case ANONYMOUS:
-                       backingMap.put(Keys.realm.ldap.server, "ldap://localhost:" + authMode.ldapPort());
                        backingMap.put(Keys.realm.ldap.username, "");
                        backingMap.put(Keys.realm.ldap.password, "");
                        break;
                case DS_MANAGER:
-                       backingMap.put(Keys.realm.ldap.server, "ldap://localhost:" + authMode.ldapPort());
                        backingMap.put(Keys.realm.ldap.username, DIRECTORY_MANAGER);
                        backingMap.put(Keys.realm.ldap.password, "password");
                        break;
                case USR_MANAGER:
-                       backingMap.put(Keys.realm.ldap.server, "ldap://localhost:" + authMode.ldapPort());
                        backingMap.put(Keys.realm.ldap.username, USER_MANAGER);
                        backingMap.put(Keys.realm.ldap.password, "passwd");
                        break;