directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r666331 - in /directory/studio/trunk: connection-core/src/main/java/org/apache/directory/studio/connection/core/ connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ test-integration-core/src/main/java/org/apac...
Date Tue, 10 Jun 2008 21:22:27 GMT
Author: seelmann
Date: Tue Jun 10 14:22:27 2008
New Revision: 666331

URL: http://svn.apache.org/viewvc?rev=666331&view=rev
Log:
Fixed NPE, added some tests

Modified:
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/Utils.java
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java
    directory/studio/trunk/test-integration-core/src/main/java/org/apache/directory/studio/test/integration/core/JNDIConnectionWrapperTest.java

Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/Utils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/Utils.java?rev=666331&r1=666330&r2=666331&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/Utils.java
(original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/Utils.java
Tue Jun 10 14:22:27 2008
@@ -155,7 +155,10 @@
         catch ( InvalidNameException e )
         {
         }
-        url.setAttributes( Arrays.asList( attributes ) );
+        if ( attributes != null )
+        {
+            url.setAttributes( Arrays.asList( attributes ) );
+        }
         url.setScope( scope );
         url.setFilter( filter );
         return url;

Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java?rev=666331&r1=666330&r2=666331&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java
(original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java
Tue Jun 10 14:22:27 2008
@@ -39,7 +39,6 @@
 import javax.naming.ldap.Control;
 import javax.naming.ldap.InitialLdapContext;
 import javax.naming.ldap.LdapContext;
-import javax.naming.ldap.LdapName;
 import javax.naming.ldap.ManageReferralControl;
 import javax.naming.ldap.StartTlsRequest;
 import javax.naming.ldap.StartTlsResponse;
@@ -302,7 +301,7 @@
                     searchCtx.addToEnvironment( Context.REFERRAL, REFERRAL_THROW );
 
                     // perform the search
-                    NamingEnumeration<SearchResult> ne = searchCtx.search( new LdapName(
searchBase ), filter,
+                    NamingEnumeration<SearchResult> ne = searchCtx.search( new LdapDN(
searchBase ), filter,
                         searchControls );
                     namingEnumeration = new StudioNamingEnumeration( connection, ne, searchBase,
filter,
                         searchControls, aliasesDereferencingMethod, referralsHandlingMethod,
controls, requestNum,
@@ -454,7 +453,7 @@
                     modCtx.addToEnvironment( Context.REFERRAL, REFERRAL_THROW );
 
                     // perform modification
-                    modCtx.modifyAttributes( new LdapName( dn ), modificationItems );
+                    modCtx.modifyAttributes( new LdapDN( dn ), modificationItems );
                 }
                 catch ( ReferralException re )
                 {
@@ -555,7 +554,7 @@
                     }
 
                     // rename entry
-                    modCtx.rename( new LdapName( oldDn ), new LdapName( newDn ) );
+                    modCtx.rename( new LdapDN( oldDn ), new LdapDN( newDn ) );
                 }
                 catch ( ReferralException re )
                 {
@@ -645,7 +644,7 @@
                     modCtx.addToEnvironment( Context.REFERRAL, REFERRAL_THROW );
 
                     // create entry
-                    modCtx.createSubcontext( new LdapName( dn ), attributes );
+                    modCtx.createSubcontext( new LdapDN( dn ), attributes );
                 }
                 catch ( ReferralException re )
                 {
@@ -733,7 +732,7 @@
                     modCtx.addToEnvironment( Context.REFERRAL, REFERRAL_THROW );
 
                     // delete entry
-                    modCtx.destroySubcontext( new LdapName( dn ) );
+                    modCtx.destroySubcontext( new LdapDN( dn ) );
                 }
                 catch ( ReferralException re )
                 {
@@ -915,14 +914,23 @@
             IAuthHandler authHandler = ConnectionCorePlugin.getDefault().getAuthHandler();
             if ( authHandler == null )
             {
-                monitor.reportError( Messages.model__no_auth_handler, new Exception() );
+                NamingException namingException = new NamingException(  Messages.model__no_auth_handler
);
+                monitor.reportError( Messages.model__no_auth_handler, namingException );
+                throw namingException;
             }
             ICredentials credentials = authHandler.getCredentials( connection.getConnectionParameter()
);
             if ( credentials == null )
             {
+                CancelException cancelException = new CancelException();
                 monitor.setCanceled( true );
-                monitor.reportError( Messages.model__no_credentials, new CancelException()
);
-                throw new CancelException();
+                monitor.reportError( Messages.model__no_credentials, cancelException );
+                throw cancelException;
+            }
+            if ( credentials.getBindPrincipal() == null || credentials.getBindPassword()
== null )
+            {
+                NamingException namingException = new NamingException(  Messages.model__no_credentials
);
+                monitor.reportError( Messages.model__no_credentials, namingException );
+                throw namingException;
             }
             bindPrincipal = credentials.getBindPrincipal();
             bindCredentials = credentials.getBindPassword();

Modified: directory/studio/trunk/test-integration-core/src/main/java/org/apache/directory/studio/test/integration/core/JNDIConnectionWrapperTest.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/test-integration-core/src/main/java/org/apache/directory/studio/test/integration/core/JNDIConnectionWrapperTest.java?rev=666331&r1=666330&r2=666331&view=diff
==============================================================================
--- directory/studio/trunk/test-integration-core/src/main/java/org/apache/directory/studio/test/integration/core/JNDIConnectionWrapperTest.java
(original)
+++ directory/studio/trunk/test-integration-core/src/main/java/org/apache/directory/studio/test/integration/core/JNDIConnectionWrapperTest.java
Tue Jun 10 14:22:27 2008
@@ -21,6 +21,16 @@
 package org.apache.directory.studio.test.integration.core;
 
 
+import java.net.ConnectException;
+import java.net.UnknownHostException;
+
+import javax.naming.AuthenticationException;
+import javax.naming.CommunicationException;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
 import org.apache.directory.server.unit.AbstractServerTest;
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
@@ -29,6 +39,8 @@
 import org.apache.directory.studio.connection.core.IAuthHandler;
 import org.apache.directory.studio.connection.core.ICredentials;
 import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.connection.core.Connection.AliasDereferencingMethod;
+import org.apache.directory.studio.connection.core.Connection.ReferralHandlingMethod;
 import org.apache.directory.studio.connection.core.ConnectionParameter.AuthenticationMethod;
 import org.apache.directory.studio.connection.core.ConnectionParameter.EncryptionMethod;
 import org.apache.directory.studio.connection.core.io.jndi.JNDIConnectionWrapper;
@@ -36,8 +48,7 @@
 
 
 /**
- * 
- * TODO JNDIConnectionWrapperTest.
+ * Tests the {@link JNDIConnectionWrapper}.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
@@ -54,7 +65,7 @@
 
 
     /**
-     * Connects to the server.
+     * Tests connecting to the server.
      */
     public void testConnect()
     {
@@ -72,11 +83,53 @@
 
         connectionWrapper.disconnect();
         assertFalse( connectionWrapper.isConnected() );
+
+        // TODO: SSL, StartTLS
+    }
+
+
+    /**
+     * Test failed connections to the server.
+     */
+    public void testConnectFailures()
+    {
+        StudioProgressMonitor monitor = null;
+        ConnectionParameter connectionParameter = null;
+        Connection connection = null;
+        JNDIConnectionWrapper connectionWrapper = null;
+
+        // invalid port
+        monitor = getProgressMonitor();
+        connectionParameter = new ConnectionParameter( null, "localhost", ldapServer.getIpPort()
+ 1,
+            EncryptionMethod.NONE, AuthenticationMethod.NONE, null, null, null, true, null
);
+        connection = new Connection( connectionParameter );
+        connectionWrapper = connection.getJNDIConnectionWrapper();
+        connectionWrapper.connect( monitor );
+        assertFalse( connectionWrapper.isConnected() );
+        assertNotNull( monitor.getException() );
+        assertTrue( monitor.getException() instanceof CommunicationException );
+        assertNotNull( monitor.getException().getCause() );
+        assertTrue( monitor.getException().getCause() instanceof ConnectException );
+
+        // unknown host
+        monitor = getProgressMonitor();
+        connectionParameter = new ConnectionParameter( null, "555.555.555.555", ldapServer.getIpPort(),
+            EncryptionMethod.NONE, AuthenticationMethod.NONE, null, null, null, true, null
);
+        connection = new Connection( connectionParameter );
+        connectionWrapper = connection.getJNDIConnectionWrapper();
+        connectionWrapper.connect( monitor );
+        assertFalse( connectionWrapper.isConnected() );
+        assertNotNull( monitor.getException() );
+        assertTrue( monitor.getException() instanceof CommunicationException );
+        assertNotNull( monitor.getException().getCause() );
+        assertTrue( monitor.getException().getCause() instanceof UnknownHostException );
+
+        // TODO: SSL, StartTLS
     }
 
 
     /**
-     * Binds to the server.
+     * Test binding to the server.
      */
     public void testBind()
     {
@@ -85,14 +138,7 @@
             EncryptionMethod.NONE, AuthenticationMethod.SIMPLE, "uid=admin,ou=system", "secret",
null, true, null );
         Connection connection = new Connection( connectionParameter );
         JNDIConnectionWrapper connectionWrapper = connection.getJNDIConnectionWrapper();
-        IAuthHandler authHandler = new IAuthHandler()
-        {
-            public ICredentials getCredentials( ConnectionParameter connectionParameter )
-            {
-                return new Credentials( connectionParameter.getBindPrincipal(), connectionParameter.getBindPassword(),
-                    connectionParameter );
-            }
-        };
+        IAuthHandler authHandler = getAuthHandler();
         ConnectionCorePlugin.getDefault().setAuthHandler( authHandler );
 
         assertFalse( connectionWrapper.isConnected() );
@@ -105,6 +151,71 @@
         connectionWrapper.unbind();
         connectionWrapper.disconnect();
         assertFalse( connectionWrapper.isConnected() );
+
+    }
+
+
+    /**
+     * Test failed binds to the server.
+     */
+    public void testBindFailures()
+    {
+        StudioProgressMonitor monitor = null;
+        ConnectionParameter connectionParameter = null;
+        Connection connection = null;
+        JNDIConnectionWrapper connectionWrapper = null;
+
+        // simple auth without principal and credential
+        monitor = getProgressMonitor();
+        connectionParameter = new ConnectionParameter( null, "localhost", ldapServer.getIpPort(),
+            EncryptionMethod.NONE, AuthenticationMethod.SIMPLE, null, null, null, true, null
);
+        connection = new Connection( connectionParameter );
+        connectionWrapper = connection.getJNDIConnectionWrapper();
+        connectionWrapper.connect( monitor );
+        connectionWrapper.bind( monitor );
+        assertFalse( connectionWrapper.isConnected() );
+        assertNotNull( monitor.getException() );
+        assertTrue( monitor.getException() instanceof NamingException );
+
+        // simple auth with invalid principal and credential
+        monitor = getProgressMonitor();
+        connectionParameter = new ConnectionParameter( null, "localhost", ldapServer.getIpPort(),
+            EncryptionMethod.NONE, AuthenticationMethod.SIMPLE, "uid=admin,ou=system", "bar",
null, true, null );
+        connection = new Connection( connectionParameter );
+        connectionWrapper = connection.getJNDIConnectionWrapper();
+        connectionWrapper.connect( monitor );
+        connectionWrapper.bind( monitor );
+        assertFalse( connectionWrapper.isConnected() );
+        assertNotNull( monitor.getException() );
+        assertTrue( monitor.getException() instanceof AuthenticationException );
+    }
+
+
+    /**
+     * Test searching.
+     */
+    public void testSearch()
+    {
+        StudioProgressMonitor monitor = null;
+        ConnectionParameter connectionParameter = null;
+        Connection connection = null;
+        JNDIConnectionWrapper connectionWrapper = null;
+
+        // simple auth without principal and credential
+        monitor = getProgressMonitor();
+        connectionParameter = new ConnectionParameter( null, "localhost", ldapServer.getIpPort(),
+            EncryptionMethod.NONE, AuthenticationMethod.SIMPLE, "uid=admin,ou=system", "secret",
null, true, null );
+        connection = new Connection( connectionParameter );
+        connectionWrapper = connection.getJNDIConnectionWrapper();
+        connectionWrapper.connect( monitor );
+        connectionWrapper.bind( monitor );
+        assertTrue( connectionWrapper.isConnected() );
+        assertNull( monitor.getException() );
+
+        SearchControls searchControls = new SearchControls();
+        NamingEnumeration<SearchResult> result = connectionWrapper.search( "ou=system",
"objectClass=*",
+            searchControls, AliasDereferencingMethod.NEVER, ReferralHandlingMethod.IGNORE,
null, monitor, null );
+        assertNotNull( result );
     }
 
 
@@ -123,4 +234,18 @@
         return monitor;
     }
 
+
+    private IAuthHandler getAuthHandler()
+    {
+        IAuthHandler authHandler = new IAuthHandler()
+        {
+            public ICredentials getCredentials( ConnectionParameter connectionParameter )
+            {
+                return new Credentials( connectionParameter.getBindPrincipal(), connectionParameter.getBindPassword(),
+                    connectionParameter );
+            }
+        };
+        return authHandler;
+    }
+
 }



Mime
View raw message