Browse Source

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.
tags/merged--sshLdapAuthenticator
Florian Zschocke 7 years ago
parent
commit
cb89090d93
1 changed files with 11 additions and 10 deletions
  1. 11
    10
      src/test/java/com/gitblit/tests/LdapBasedUnitTest.java

+ 11
- 10
src/test/java/com/gitblit/tests/LdapBasedUnitTest.java View 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;

Loading…
Cancel
Save