directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r1067792 - in /directory/apacheds/trunk: core-integ/src/main/java/org/apache/directory/server/core/integ/ core-integ/src/test/java/org/apache/directory/server/core/authn/ppolicy/ server-integ/src/main/java/org/apache/directory/server/integ/
Date Sun, 06 Feb 2011 22:43:36 GMT
Author: seelmann
Date: Sun Feb  6 22:43:36 2011
New Revision: 1067792

URL: http://svn.apache.org/viewvc?rev=1067792&view=rev
Log:
o Moved network connection methods from core-integ to server-integ
o Changes in PasswordPolicyTest needs review


Modified:
    directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/authn/ppolicy/PasswordPolicyTest.java
    directory/apacheds/trunk/server-integ/src/main/java/org/apache/directory/server/integ/ServerIntegrationUtils.java

Modified: directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java?rev=1067792&r1=1067791&r2=1067792&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
(original)
+++ directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
Sun Feb  6 22:43:36 2011
@@ -21,7 +21,6 @@ package org.apache.directory.server.core
 
 import java.io.File;
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.List;
 
 import javax.naming.NamingException;
@@ -35,7 +34,6 @@ import javax.naming.ldap.LdapName;
 import org.apache.commons.io.FileUtils;
 import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.ldap.client.api.LdapConnectionFactory;
-import org.apache.directory.ldap.client.api.LdapNetworkConnection;
 import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.core.CoreSession;
 import org.apache.directory.server.core.DirectoryService;
@@ -43,7 +41,6 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.LdapPrincipal;
 import org.apache.directory.server.core.jndi.ServerLdapContext;
 import org.apache.directory.server.i18n.I18n;
-import org.apache.directory.server.ldap.LdapServer;
 import org.apache.directory.shared.ldap.model.constants.AuthenticationLevel;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
@@ -70,7 +67,6 @@ public class IntegrationUtils
     /** The class logger */
     private static final Logger LOG = LoggerFactory.getLogger( IntegrationUtils.class );
 
-    private static final List<LdapConnection> openConnections = new ArrayList<LdapConnection>();
 
     /**
      * Deletes the working directory.
@@ -386,59 +382,8 @@ public class IntegrationUtils
     }
 
 
-    public static LdapConnection getNetworkConnectionAs( String host, int port, String dn,
String password ) throws Exception
-    {
-        LdapConnection connection = LdapConnectionFactory.getNetworkConnection( host, port
);
-
-        connection.bind( dn, password );
-        openConnections.add( connection );
-        return connection;
-    }
-
-
-    public static LdapConnection getAdminNetworkConnection( LdapServer ldapServer ) throws
Exception
-    {
-        LdapConnection connection = new LdapNetworkConnection( "localhost", ldapServer.getPort()
);
-
-        connection.setTimeOut( 0 );
-        connection.bind( ServerDNConstants.ADMIN_SYSTEM_DN, "secret" );
-
-        openConnections.add( connection );
-
-        return connection;
-    }
-
-
-    public static LdapConnection getNetworkConnectionAs( LdapServer ldapServer, String userDn,
String password ) throws Exception
-    {
-        return getNetworkConnectionAs( "localhost", ldapServer.getPort(), userDn, password
);
-    }
-
-
     public static void closeConnections()
     {
-
-        for( LdapConnection con : openConnections )
-        {
-            if( con == null )
-            {
-                continue;
-            }
-
-            try
-            {
-                if( con.isConnected() )
-                {
-                    con.close();
-                }
-            }
-            catch( Exception e )
-            {
-                // shouldn't happen, but print the stacktrace so that less pain during development
to find the cause
-                e.printStackTrace();
-            }
-        }
-
-        openConnections.clear();
+        // TODO: is it necessary to close all opened CoreSession connections?
     }
 }

Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/authn/ppolicy/PasswordPolicyTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/authn/ppolicy/PasswordPolicyTest.java?rev=1067792&r1=1067791&r2=1067792&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/authn/ppolicy/PasswordPolicyTest.java
(original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/authn/ppolicy/PasswordPolicyTest.java
Sun Feb  6 22:43:36 2011
@@ -21,8 +21,8 @@
 package org.apache.directory.server.core.authn.ppolicy;
 
 
-import static org.apache.directory.server.core.integ.IntegrationUtils.getAdminNetworkConnection;
-import static org.apache.directory.server.core.integ.IntegrationUtils.getNetworkConnectionAs;
+import static org.apache.directory.server.core.integ.IntegrationUtils.getAdminConnection;
+import static org.apache.directory.server.core.integ.IntegrationUtils.getConnectionAs;
 import static org.apache.directory.shared.ldap.codec.controls.ppolicy.PasswordPolicyErrorEnum.INSUFFICIENT_PASSWORD_QUALITY;
 import static org.apache.directory.shared.ldap.codec.controls.ppolicy.PasswordPolicyErrorEnum.PASSWORD_TOO_SHORT;
 import static org.apache.directory.shared.ldap.codec.controls.ppolicy.PasswordPolicyErrorEnum.PASSWORD_TOO_YOUNG;
@@ -65,6 +65,8 @@ import org.junit.runner.RunWith;
 
 /**
  * Test cases for testing PasswordPolicy implementation.
+ * TODO: currently ignored in MigratedStockCoreSuite
+ * TODO: check if non-network connection can be used for tests
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
@@ -120,7 +122,7 @@ public class PasswordPolicyTest extends 
     @Test
     public void testAddUserWithClearTextPwd() throws Exception
     {
-        LdapConnection connection = getAdminNetworkConnection( ldapServer );
+        LdapConnection connection = getAdminConnection( service );
         
         Dn userDn = new Dn( "cn=user,ou=system" );
         Entry userEntry = LdifUtils.createEntry( userDn, "ObjectClass: top", "ObjectClass:
person", "cn: user",
@@ -146,7 +148,7 @@ public class PasswordPolicyTest extends 
         respCtrl = getPwdRespCtrl( addResp );
         assertNull( respCtrl );
 
-        LdapConnection userConnection = getNetworkConnectionAs( ldapServer, userDn.getName(),
"12345" );
+        LdapConnection userConnection = getConnectionAs( service, userDn.getName(), "12345"
);
         assertNotNull( userConnection );
         assertTrue( userConnection.isAuthenticated() );
     }
@@ -155,7 +157,7 @@ public class PasswordPolicyTest extends 
     @Test
     public void testAddUserWithHashedPwd() throws Exception
     {
-        LdapConnection connection = getAdminNetworkConnection( ldapServer );
+        LdapConnection connection = getAdminConnection( service );
 
         byte[] password = PasswordUtil.createStoragePassword( "12345", LdapSecurityConstants.HASH_METHOD_CRYPT
);
 
@@ -187,7 +189,7 @@ public class PasswordPolicyTest extends 
         respCtrl = getPwdRespCtrl( addResp );
         assertNull( respCtrl );
 
-        LdapConnection userConnection = getNetworkConnectionAs( ldapServer, userDn.getName(),
"12345" );
+        LdapConnection userConnection = getConnectionAs( service, userDn.getName(), "12345"
);
         assertNotNull( userConnection );
         assertTrue( userConnection.isAuthenticated() );
     }
@@ -198,7 +200,7 @@ public class PasswordPolicyTest extends 
     {
         policyConfig.setPwdMinAge( 5 );
 
-        LdapConnection connection = getAdminNetworkConnection( ldapServer );
+        LdapConnection connection = getAdminConnection( service );
 
         Dn userDn = new Dn( "cn=userMinAge,ou=system" );
         Entry userEntry = LdifUtils.createEntry(userDn, "ObjectClass: top", "ObjectClass:
person", "cn: userMinAge",
@@ -230,7 +232,7 @@ public class PasswordPolicyTest extends 
         modResp = connection.modify( modReq );
         assertEquals( ResultCodeEnum.SUCCESS, modResp.getLdapResult().getResultCode() );
 
-        LdapConnection userConnection = getNetworkConnectionAs( ldapServer, userDn.getName(),
"123456" );
+        LdapConnection userConnection = getConnectionAs( service, userDn.getName(), "123456"
);
         assertNotNull( userConnection );
         assertTrue( userConnection.isAuthenticated() );
     }

Modified: directory/apacheds/trunk/server-integ/src/main/java/org/apache/directory/server/integ/ServerIntegrationUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/main/java/org/apache/directory/server/integ/ServerIntegrationUtils.java?rev=1067792&r1=1067791&r2=1067792&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/main/java/org/apache/directory/server/integ/ServerIntegrationUtils.java
(original)
+++ directory/apacheds/trunk/server-integ/src/main/java/org/apache/directory/server/integ/ServerIntegrationUtils.java
Sun Feb  6 22:43:36 2011
@@ -19,7 +19,9 @@
 package org.apache.directory.server.integ;
 
 
+import java.util.ArrayList;
 import java.util.Hashtable;
+import java.util.List;
 
 import javax.naming.Context;
 import javax.naming.ldap.InitialLdapContext;
@@ -28,6 +30,7 @@ import javax.naming.ldap.LdapContext;
 import netscape.ldap.LDAPConnection;
 
 import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.LdapConnectionFactory;
 import org.apache.directory.ldap.client.api.LdapNetworkConnection;
 import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.core.integ.IntegrationUtils;
@@ -48,6 +51,7 @@ public class ServerIntegrationUtils exte
     private static final int DEFAULT_PORT = 10389;
     private static final String DEFAULT_ADMIN = ServerDNConstants.ADMIN_SYSTEM_DN;
     private static final String DEFAULT_PASSWORD = "secret";
+    private static final List<LdapConnection> openConnections = new ArrayList<LdapConnection>();
 
 
     /**
@@ -225,4 +229,59 @@ public class ServerIntegrationUtils exte
         return conn;
     }
 
+    public static LdapConnection getNetworkConnectionAs( String host, int port, String dn,
String password ) throws Exception
+    {
+        LdapConnection connection = LdapConnectionFactory.getNetworkConnection( host, port
);
+
+        connection.bind( dn, password );
+        openConnections.add( connection );
+        return connection;
+    }
+
+
+    public static LdapConnection getAdminNetworkConnection( LdapServer ldapServer ) throws
Exception
+    {
+        LdapConnection connection = new LdapNetworkConnection( "localhost", ldapServer.getPort()
);
+
+        connection.setTimeOut( 0 );
+        connection.bind( ServerDNConstants.ADMIN_SYSTEM_DN, "secret" );
+
+        openConnections.add( connection );
+
+        return connection;
+    }
+
+
+    public static LdapConnection getNetworkConnectionAs( LdapServer ldapServer, String userDn,
String password ) throws Exception
+    {
+        return getNetworkConnectionAs( "localhost", ldapServer.getPort(), userDn, password
);
+    }
+
+
+    public static void closeConnections()
+    {
+
+        for( LdapConnection con : openConnections )
+        {
+            if( con == null )
+            {
+                continue;
+            }
+
+            try
+            {
+                if( con.isConnected() )
+                {
+                    con.close();
+                }
+            }
+            catch( Exception e )
+            {
+                // shouldn't happen, but print the stacktrace so that less pain during development
to find the cause
+                e.printStackTrace();
+            }
+        }
+
+        openConnections.clear();
+    }
 }



Mime
View raw message