summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Zschocke <florian.zschocke@devolo.de>2016-11-26 17:35:21 +0100
committerFlorian Zschocke <florian.zschocke@devolo.de>2016-12-06 15:34:56 +0100
commitcb89090d936ff8383d26f69eaeae6717d3a701e1 (patch)
tree50104f19c11970f577dc8731ddcb2b050e5a6c84
parentf639d966cb5e7026cb30e6b25be55fb681feb896 (diff)
downloadgitblit-cb89090d936ff8383d26f69eaeae6717d3a701e1.tar.gz
gitblit-cb89090d936ff8383d26f69eaeae6717d3a701e1.zip
Use dynamic port selection for LDAP listeners in LDAP tests.
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.
-rw-r--r--src/test/java/com/gitblit/tests/LdapBasedUnitTest.java21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/test/java/com/gitblit/tests/LdapBasedUnitTest.java b/src/test/java/com/gitblit/tests/LdapBasedUnitTest.java
index cf3ab1fa..7aec50e6 100644
--- a/src/test/java/com/gitblit/tests/LdapBasedUnitTest.java
+++ b/src/test/java/com/gitblit/tests/LdapBasedUnitTest.java
@@ -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;