Test failure: security.authentication.ldap.LdapProviderTest (Address already in use)
Test failure: LdapDefaultLoginModuleTest address already in use
Ignore tests in the case of a BindException
package org.apache.jackrabbit.oak.security.authentication.ldap;
+import static org.junit.Assume.assumeFalse;
+
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.net.BindException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -40,6 +43,7 @@ import org.apache.commons.io.FileUtils;
import org.apache.directory.api.ldap.model.constants.SupportedSaslMechanisms;
import org.apache.directory.api.ldap.model.entry.DefaultEntry;
import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.exception.LdapConfigurationException;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.ldif.LdifEntry;
import org.apache.directory.api.ldap.model.ldif.LdifReader;
@@ -228,10 +232,28 @@ public abstract class AbstractServer {
directoryService.startup();
setupExamplePartition();
- ldapServer.start();
+ startLdapServer();
setContexts(ServerDNConstants.ADMIN_SYSTEM_DN, "secret");
}
+ /**
+ * Start the LDAP server assuming we can bind to the previously reserved port.
+ * Given that there is a small race between when the port was reserved and when the
+ * socket is actually bound this can still fail. For now we are ignoring this rare
+ * case and skip the test. See OAK-5542.
+ * @throws Exception
+ */
+ private void startLdapServer() throws Exception {
+ try {
+ ldapServer.start();
+ } catch (LdapConfigurationException e) {
+ Throwable cause = e.getCause();
+ assumeFalse("Ignoring this test as the server port is already in use (OAK-5542): " + cause,
+ cause instanceof BindException);
+ throw e;
+ }
+ }
+
protected void setupLdapServer() throws Exception {
ldapServer.setTransports(new TcpTransport(port));
ldapServer.setDirectoryService(directoryService);
