You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2019/01/08 13:33:32 UTC

[directory-server] 03/03: Fixed the tests after the change in the default config that now use a default TrustManager

This is an automated email from the ASF dual-hosted git repository.

elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-server.git

commit c93fbc1c877f708d21f9e33113e489108b259526
Author: Emmanuel Lecharny <el...@apache.org>
AuthorDate: Tue Jan 8 14:33:27 2019 +0100

    Fixed the tests after the change in the default config that now use a
    default TrustManager
---
 .../shared/client/api/LdapSSLConnectionTest.java   | 16 +++++++--
 .../apache/directory/server/ssl/KeyStoreIT.java    | 39 ++++++++++++++++------
 2 files changed, 41 insertions(+), 14 deletions(-)

diff --git a/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapSSLConnectionTest.java b/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapSSLConnectionTest.java
index fc23bd3..07360de 100644
--- a/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapSSLConnectionTest.java
+++ b/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapSSLConnectionTest.java
@@ -27,6 +27,8 @@ import static org.junit.Assert.assertEquals;
 
 import java.util.List;
 
+import javax.net.ssl.X509TrustManager;
+
 import org.apache.directory.api.ldap.codec.api.SchemaBinaryAttributeDetector;
 import org.apache.directory.api.ldap.model.constants.SupportedSaslMechanisms;
 import org.apache.directory.api.ldap.model.entry.Entry;
@@ -135,8 +137,10 @@ public class LdapSSLConnectionTest extends AbstractLdapTestUnit
     @Test
     public void testBindRequestSSLAuto() throws Exception
     {
+        sslConfig.setTrustManagers( new X509TrustManager[] { new NoVerificationTrustManager() } );
+
         try ( LdapNetworkConnection connection = 
-            new LdapNetworkConnection( Network.LOOPBACK_HOSTNAME, getLdapServer().getPortSSL(), true ) )
+            new LdapNetworkConnection( sslConfig ) )
         {
             connection.bind( "uid=admin,ou=system", "secret" );
             assertTrue( connection.getConfig().isUseSsl() );
@@ -219,8 +223,10 @@ public class LdapSSLConnectionTest extends AbstractLdapTestUnit
     @Test
     public void testStartTLSAfterBind() throws Exception
     {
+        tlsConfig.setTrustManagers( new X509TrustManager[] { new NoVerificationTrustManager() } );
+
         try ( LdapNetworkConnection connection = 
-            new LdapNetworkConnection( Network.LOOPBACK_HOSTNAME, getLdapServer().getPort() ) )
+            new LdapNetworkConnection( tlsConfig ) )
         {
             connection.connect();
 
@@ -255,8 +261,10 @@ public class LdapSSLConnectionTest extends AbstractLdapTestUnit
     @Test
     public void testStartTLS() throws Exception
     {
+        tlsConfig.setTrustManagers( new X509TrustManager[] { new NoVerificationTrustManager() } );
+
         try ( LdapNetworkConnection connection = 
-            new LdapNetworkConnection( Network.LOOPBACK_HOSTNAME, getLdapServer().getPort() ) )
+            new LdapNetworkConnection( tlsConfig ) )
         {
             assertFalse( connection.isConnected() );
             
@@ -354,6 +362,8 @@ public class LdapSSLConnectionTest extends AbstractLdapTestUnit
         sslConfig.setLdapHost( Network.LOOPBACK_HOSTNAME );
         sslConfig.setUseSsl( true );
         sslConfig.setLdapPort( getLdapServer().getPortSSL() );
+        sslConfig.setTrustManagers( new X509TrustManager[] { new NoVerificationTrustManager() } );
+
 
         try ( LdapNetworkConnection connection = new LdapNetworkConnection( sslConfig ) )
         {
diff --git a/server-integ/src/test/java/org/apache/directory/server/ssl/KeyStoreIT.java b/server-integ/src/test/java/org/apache/directory/server/ssl/KeyStoreIT.java
index da11dca..01bb016 100644
--- a/server-integ/src/test/java/org/apache/directory/server/ssl/KeyStoreIT.java
+++ b/server-integ/src/test/java/org/apache/directory/server/ssl/KeyStoreIT.java
@@ -35,12 +35,14 @@ import java.security.cert.X509Certificate;
 
 import javax.net.ssl.TrustManager;
 import javax.net.ssl.TrustManagerFactory;
+import javax.net.ssl.X509TrustManager;
 
 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.LdapException;
 import org.apache.directory.ldap.client.api.LdapConnectionConfig;
 import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.apache.directory.ldap.client.api.NoVerificationTrustManager;
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
 import org.apache.directory.server.core.annotations.CreateDS;
@@ -121,8 +123,12 @@ public class KeyStoreIT extends AbstractLdapTestUnit
     @Test
     public void testLdaps_DefaultAdminCert_NoVerificationTrustManager() throws Exception
     {
+        LdapConnectionConfig config = ldapsConnectionConfig();
+        
+        config.setTrustManagers( new X509TrustManager[] { new NoVerificationTrustManager() } );
+        
         try (
-            LdapNetworkConnection conn = new LdapNetworkConnection( ldapsConectionConfig() ); )
+            LdapNetworkConnection conn = new LdapNetworkConnection( config ); )
         {
             conn.connect();
             assertTrue( conn.isConnected() );
@@ -138,8 +144,12 @@ public class KeyStoreIT extends AbstractLdapTestUnit
     @Test
     public void testStartTls_DefaultAdminCert_NoVerificationTrustManager() throws Exception
     {
+        LdapConnectionConfig config = startTlsConnectionConfig();
+        
+        config.setTrustManagers( new X509TrustManager[] { new NoVerificationTrustManager() } );
+
         try (
-            LdapNetworkConnection conn = new LdapNetworkConnection( startTlsConectionConfig() ); )
+            LdapNetworkConnection conn = new LdapNetworkConnection( config ); )
         {
             conn.startTls();
             assertTrue( conn.isConnected() );
@@ -155,8 +165,7 @@ public class KeyStoreIT extends AbstractLdapTestUnit
     @Test
     public void testLdaps_DefaultAdminCert_DefaultTrustManager() throws Exception
     {
-        LdapConnectionConfig config = ldapsConectionConfig();
-        config.setTrustManagers( defaultTrustManagers() );
+        LdapConnectionConfig config = ldapsConnectionConfig();
 
         try (
             LdapNetworkConnection conn = new LdapNetworkConnection( config ); )
@@ -184,7 +193,7 @@ public class KeyStoreIT extends AbstractLdapTestUnit
     @Test
     public void testStartTls_DefaultAdminCert_DefaultTrustManager() throws Exception
     {
-        LdapConnectionConfig config = startTlsConectionConfig();
+        LdapConnectionConfig config = startTlsConnectionConfig();
         config.setTrustManagers( defaultTrustManagers() );
 
         try (
@@ -214,8 +223,12 @@ public class KeyStoreIT extends AbstractLdapTestUnit
     {
         assertTrue( getLdapServer().isStarted() );
 
+        LdapConnectionConfig config = ldapsConnectionConfig();
+        
+        config.setTrustManagers( new X509TrustManager[] { new NoVerificationTrustManager() } );
+
         try (
-            LdapNetworkConnection conn = new LdapNetworkConnection( ldapsConectionConfig() ); )
+            LdapNetworkConnection conn = new LdapNetworkConnection( config ); )
         {
             conn.connect();
             assertTrue( conn.isConnected() );
@@ -233,8 +246,12 @@ public class KeyStoreIT extends AbstractLdapTestUnit
     {
         assertTrue( getLdapServer().isStarted() );
 
+        LdapConnectionConfig config = startTlsConnectionConfig();
+        
+        config.setTrustManagers( new X509TrustManager[] { new NoVerificationTrustManager() } );
+
         try (
-            LdapNetworkConnection conn = new LdapNetworkConnection( startTlsConectionConfig() ); )
+            LdapNetworkConnection conn = new LdapNetworkConnection( config ); )
         {
             conn.startTls();
             assertTrue( conn.isConnected() );
@@ -252,7 +269,7 @@ public class KeyStoreIT extends AbstractLdapTestUnit
     {
         assertTrue( getLdapServer().isStarted() );
 
-        LdapConnectionConfig config = ldapsConectionConfig();
+        LdapConnectionConfig config = ldapsConnectionConfig();
         config.setTrustManagers( defaultTrustManagers() );
 
         try (
@@ -282,7 +299,7 @@ public class KeyStoreIT extends AbstractLdapTestUnit
     {
         assertTrue( getLdapServer().isStarted() );
 
-        LdapConnectionConfig config = startTlsConectionConfig();
+        LdapConnectionConfig config = startTlsConnectionConfig();
         config.setTrustManagers( defaultTrustManagers() );
 
         try (
@@ -347,7 +364,7 @@ public class KeyStoreIT extends AbstractLdapTestUnit
     }
 
 
-    private LdapConnectionConfig startTlsConectionConfig()
+    private LdapConnectionConfig startTlsConnectionConfig()
     {
         LdapConnectionConfig config = new LdapConnectionConfig();
         config.setTimeout( 1000 );
@@ -358,7 +375,7 @@ public class KeyStoreIT extends AbstractLdapTestUnit
     }
 
 
-    private LdapConnectionConfig ldapsConectionConfig()
+    private LdapConnectionConfig ldapsConnectionConfig()
     {
         LdapConnectionConfig config = new LdapConnectionConfig();
         config.setTimeout( 1000 );