TlsGuardingConnection doesn't do a TLS handshake on reused connections
Added test case.
@@ -22,12 +22,15 @@ import org.apache.directory.ldap.client.api.LdapConnectionConfig;
import org.apache.directory.ldap.client.api.LdapConnectionValidator;
import org.apache.directory.ldap.client.api.LdapNetworkConnection;
import org.apache.directory.ldap.client.api.LookupLdapConnectionValidator;
+import org.apache.directory.ldap.client.api.NoVerificationTrustManager;
import org.apache.jackrabbit.oak.security.authentication.ldap.LdapServerClassLoader;
import org.jetbrains.annotations.NotNull;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
+import javax.net.ssl.TrustManager;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -97,6 +100,21 @@ public class PoolableUnboundConnectionFactoryTest {
assertConnection(factory.create());
}
+ //OAK-9519: make sure that calling startTls on a secured connection is a noop.
+ @Test
+ public void testStartTls() throws Exception {
+ when(config.getLdapHost()).thenReturn(PROXY.host);
+ when(config.getLdapPort()).thenReturn(PROXY.port);
+
+ when(config.isUseTls()).thenReturn(true);
+ when(config.getTrustManagers()).thenReturn(new TrustManager[] {new NoVerificationTrustManager()});
+ LdapNetworkConnection lc = (LdapNetworkConnection) factory.create();
+ assertTrue(lc.isConnected());
+ lc.startTls();
+ assertTrue(lc.isSecured());
+ lc.startTls();
+ }
+
private static void assertConnection(@NotNull LdapConnection lc) {
assertTrue(lc instanceof LdapNetworkConnection);
}
