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 2012/10/07 12:30:26 UTC
svn commit: r1395268 - in
/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core:
jndi/SimpleBindJndiIT.java operations/bind/SimpleBindIT.java
suites/MigratedStockCoreISuite.java suites/StockCoreISuite.java
Author: elecharny
Date: Sun Oct 7 10:30:25 2012
New Revision: 1395268
URL: http://svn.apache.org/viewvc?rev=1395268&view=rev
Log:
Migrated teh SimpleBindIT test to use the API
Added:
directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/SimpleBindJndiIT.java (with props)
Modified:
directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/bind/SimpleBindIT.java
directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/MigratedStockCoreISuite.java
directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/StockCoreISuite.java
Added: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/SimpleBindJndiIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/SimpleBindJndiIT.java?rev=1395268&view=auto
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/SimpleBindJndiIT.java (added)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/SimpleBindJndiIT.java Sun Oct 7 10:30:25 2012
@@ -0,0 +1,461 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.server.core.jndi;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Hashtable;
+
+import javax.naming.AuthenticationException;
+import javax.naming.Context;
+import javax.naming.InvalidNameException;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.OperationNotSupportedException;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.server.core.annotations.CreateDS;
+import org.apache.directory.server.core.api.DirectoryService;
+import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
+import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.server.core.integ.IntegrationUtils;
+import org.apache.directory.server.core.jndi.CoreContextFactory;
+import org.apache.directory.shared.ldap.model.constants.JndiPropertyConstants;
+import org.apache.directory.shared.ldap.model.exception.LdapUnwillingToPerformException;
+import org.apache.directory.shared.ldap.model.message.AliasDerefMode;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test the Simple BindRequest
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(FrameworkRunner.class)
+@CreateDS(name = "SimpleBindIT", allowAnonAccess = true)
+public class SimpleBindJndiIT extends AbstractLdapTestUnit
+{
+
+ /**
+ * A method to do a search
+ */
+ private NamingEnumeration<SearchResult> search( DirContext ctx, String baseDn, String filter, int scope )
+ throws NamingException
+ {
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope( scope );
+ controls.setDerefLinkFlag( false );
+ controls.setReturningAttributes( new String[]
+ { "*", "+" } );
+ ctx.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
+ .getJndiValue() );
+
+ NamingEnumeration<SearchResult> list = ctx.search( baseDn, filter, controls );
+ return list;
+ }
+
+
+ /**
+ * try to connect using a known user/password and read an entry.
+ *
+ * @throws Exception on error
+ */
+ @Test
+ public void testSimpleBindAPrincipalAPassword()
+ {
+ // We will bind using JNDI
+ // Set up the environment for creating the initial context
+ Hashtable<String, Object> env = new Hashtable<String, Object>();
+ env.put( DirectoryService.JNDI_KEY, getService() );
+ env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
+ env.put( Context.PROVIDER_URL, "ou=system" );
+
+ // Authenticate as admin and password "secret"
+ env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+ env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
+ env.put( Context.SECURITY_CREDENTIALS, "secret" );
+
+ DirContext ctx = null;
+
+ // Create the initial context
+ try
+ {
+ ctx = new InitialDirContext( env );
+ }
+ catch ( NamingException ne )
+ {
+ fail();
+ }
+
+ try
+ {
+ ctx.close();
+ }
+ catch ( NamingException ne )
+ {
+ fail();
+ }
+ }
+
+
+ /**
+ * try to connect using a known user but with a bad password: we should get a invalidCredentials error.
+ *
+ * @throws Exception on error
+ */
+ @Test
+ public void testSimpleBindAPrincipalBadPassword()
+ {
+ // We will bind using JNDI
+ // Set up the environment for creating the initial context
+ Hashtable<String, Object> env = new Hashtable<String, Object>();
+ env.put( DirectoryService.JNDI_KEY, getService() );
+ env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
+ env.put( Context.PROVIDER_URL, "ou=system" );
+
+ // Authenticate as admin and password "badsecret"
+ env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+ env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
+ env.put( Context.SECURITY_CREDENTIALS, "badsecret" );
+
+ // Create the initial context
+ try
+ {
+ new InitialDirContext( env );
+
+ // We should not be connected
+ fail();
+ }
+ catch ( AuthenticationException ae )
+ {
+ assertTrue( true );
+ }
+ catch ( NamingException ne )
+ {
+ fail();
+ }
+ }
+
+
+ /**
+ * try to connect using a user with an invalid Dn: we should get a invalidDNSyntax error.
+ *
+ * @throws Exception on error
+ */
+ @Test
+ public void testSimpleBindBadPrincipalAPassword()
+ {
+ // We will bind using JNDI
+ // Set up the environment for creating the initial context
+ Hashtable<String, Object> env = new Hashtable<String, Object>();
+ env.put( DirectoryService.JNDI_KEY, getService() );
+ env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
+ env.put( Context.PROVIDER_URL, "ou=system" );
+
+ // Authenticate as admin and password "secret"
+ env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+ env.put( Context.SECURITY_PRINCIPAL, "admin" );
+ env.put( Context.SECURITY_CREDENTIALS, "secret" );
+
+ // Create the initial context
+ try
+ {
+ new InitialDirContext( env );
+
+ // We should not be connected
+ fail();
+ }
+ catch ( InvalidNameException ine )
+ {
+ assertTrue( true );
+ }
+ catch ( NamingException ne )
+ {
+ fail();
+ }
+ }
+
+
+ /**
+ * try to connect using a unknown user: we should get a invalidCredentials error.
+ *
+ * @throws Exception on error
+ */
+ @Test
+ public void testSimpleBindUnknowPrincipalAPassword()
+ {
+ // We will bind using JNDI
+ // Set up the environment for creating the initial context
+ Hashtable<String, Object> env = new Hashtable<String, Object>();
+ env.put( DirectoryService.JNDI_KEY, getService() );
+ env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
+ env.put( Context.PROVIDER_URL, "ou=system" );
+
+ // Authenticate as uid=unknown and password "secret"
+ env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+ env.put( Context.SECURITY_PRINCIPAL, "uid=unknown,ou=system" );
+ env.put( Context.SECURITY_CREDENTIALS, "secret" );
+
+ // Create the initial context
+ try
+ {
+ new InitialDirContext( env );
+
+ // We should not be connected
+ fail();
+ }
+ catch ( AuthenticationException ae )
+ {
+ // lae.printStackTrace();
+ assertTrue( org.apache.directory.server.i18n.I18n.err( org.apache.directory.server.i18n.I18n.ERR_229 ), ae
+ .getMessage().startsWith( org.apache.directory.server.i18n.I18n.ERR_229.getErrorCode() ) );
+ }
+ catch ( NamingException ne )
+ {
+ fail();
+ }
+ }
+
+
+ /**
+ * covers the anonymous authentication : we should be able to read the rootDSE, but that's it
+ *
+ * @throws Exception on error
+ */
+ @Test
+ public void testSimpleBindNoPrincipalNoPassword()
+ {
+ // We will bind using JNDI
+ // Set up the environment for creating the initial context
+ Hashtable<String, Object> env = new Hashtable<String, Object>();
+ env.put( DirectoryService.JNDI_KEY, getService() );
+ env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
+
+ // Bind on the rootDSE
+ env.put( Context.PROVIDER_URL, "" );
+
+ // Authenticate with no principal and no password : this is an anonymous bind
+ env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+ env.put( Context.SECURITY_PRINCIPAL, "" );
+ env.put( Context.SECURITY_CREDENTIALS, "" );
+
+ DirContext ctx = null;
+
+ // Create the initial context
+ try
+ {
+ ctx = new InitialDirContext( env );
+ }
+ catch ( NamingException ne )
+ {
+ ne.printStackTrace();
+ fail();
+ }
+
+ // We should be anonymous here.
+ // Check that we can read the rootDSE
+ try
+ {
+ NamingEnumeration<SearchResult> list = search( ctx, "", "(ObjectClass=*)", SearchControls.OBJECT_SCOPE );
+
+ assertNotNull( list );
+
+ while ( list.hasMore() )
+ {
+ SearchResult result = list.next();
+ assertNotNull( result );
+ }
+ }
+ catch ( NamingException ne )
+ {
+ fail();
+ }
+
+ // Check that we cannot read another entry being anonymous
+ try
+ {
+ NamingEnumeration<SearchResult> list = search( ctx, "uid=admin, ou=system", "(ObjectClass=*)",
+ SearchControls.OBJECT_SCOPE );
+
+ assertNotNull( list );
+ assertFalse( list.hasMore() );
+ }
+ catch ( NamingException ne )
+ {
+ fail();
+ }
+
+ try
+ {
+ ctx.close();
+ }
+ catch ( NamingException ne )
+ {
+ fail();
+ }
+ }
+
+
+ /**
+ * covers the Unauthenticated case : we should get a UnwillingToPerform error.
+ *
+ * @throws Exception on error
+ */
+ @Test
+ public void testSimpleBindAPrincipalNoPassword()
+ {
+ // We will bind using JNDI
+ // Set up the environment for creating the initial context
+ Hashtable<String, Object> env = new Hashtable<String, Object>();
+ env.put( DirectoryService.JNDI_KEY, getService() );
+ env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
+
+ // Bind on the rootDSE
+ env.put( Context.PROVIDER_URL, "" );
+
+ // Authenticate as admin and password "secret"
+ env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+ env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
+ env.put( Context.SECURITY_CREDENTIALS, "" );
+
+ // Create the initial context
+ try
+ {
+ new InitialDirContext( env );
+ }
+ catch ( OperationNotSupportedException onse )
+ {
+ assertEquals( "Cannot Bind for Dn uid=admin,ou=system", onse.getMessage() );
+ }
+ catch ( NamingException ne )
+ {
+ fail();
+ }
+ }
+
+
+ /**
+ * covers the Unauthenticated case : we should get a UnwillingToPerform error.
+ *
+ * @throws Exception on error
+ */
+ @Test( expected = LdapUnwillingToPerformException.class )
+ public void testSimpleBindAPrincipalNullPassword() throws Exception
+ {
+ LdapConnection connection = IntegrationUtils.getConnectionAs( getService(), "uid=admin,ou=system", null );
+ assertFalse( connection.isAuthenticated() );
+
+ connection = IntegrationUtils.getConnectionAs( getService(), "uid=admin,ou=system", "secret" );
+
+ connection.bind( "uid=admin,ou=system", null );
+ }
+
+
+ /**
+ * not allowed by the server. We should get a invalidCredentials error.
+ *
+ * @throws Exception on error
+ */
+ @Test
+ public void testSimpleBindNoPrincipalAPassword() throws Exception
+ {
+ // We will bind using JNDI
+ // Set up the environment for creating the initial context
+ Hashtable<String, Object> env = new Hashtable<String, Object>();
+ env.put( DirectoryService.JNDI_KEY, getService() );
+ env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
+
+ // Bind on the rootDSE
+ env.put( Context.PROVIDER_URL, "" );
+
+ // Authenticate as admin and password "secret"
+ env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+ env.put( Context.SECURITY_PRINCIPAL, "" );
+ env.put( Context.SECURITY_CREDENTIALS, "secret" );
+
+ // Create the initial context
+ try
+ {
+ new InitialDirContext( env );
+ }
+ catch ( NameNotFoundException nnfe )
+ {
+ fail();
+ }
+ catch ( AuthenticationException ne )
+ {
+ assertTrue( true );
+ }
+ }
+
+
+ /**
+ * try to connect using a known user/password and read an entry.
+ *
+ * @throws Exception on error
+ */
+ @Test
+ public void testSimpleBindWithDoubleQuote()
+ {
+ // We will bind using JNDI
+ // Set up the environment for creating the initial context
+ Hashtable<String, Object> env = new Hashtable<String, Object>();
+ env.put( DirectoryService.JNDI_KEY, getService() );
+ env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
+ env.put( Context.PROVIDER_URL, "ou=system" );
+
+ // Authenticate as admin and password "secret"
+ env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+ env.put( Context.SECURITY_PRINCIPAL, "uid=\"admin\",ou=\"system\"" );
+ env.put( Context.SECURITY_CREDENTIALS, "secret" );
+
+ DirContext ctx = null;
+
+ // Create the initial context
+ try
+ {
+ ctx = new InitialDirContext( env );
+ }
+ catch ( NamingException ne )
+ {
+ fail();
+ }
+
+ try
+ {
+ ctx.close();
+ }
+ catch ( NamingException ne )
+ {
+ fail();
+ }
+ }
+}
Propchange: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/SimpleBindJndiIT.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/bind/SimpleBindIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/bind/SimpleBindIT.java?rev=1395268&r1=1395267&r2=1395268&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/bind/SimpleBindIT.java (original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/bind/SimpleBindIT.java Sun Oct 7 10:30:25 2012
@@ -23,11 +23,14 @@ package org.apache.directory.server.core
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.io.IOException;
import java.util.Hashtable;
+/*
import javax.naming.AuthenticationException;
import javax.naming.Context;
import javax.naming.InvalidNameException;
@@ -39,6 +42,7 @@ import javax.naming.directory.DirContext
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
+*/
import org.apache.directory.ldap.client.api.LdapConnection;
import org.apache.directory.server.core.annotations.CreateDS;
@@ -48,14 +52,20 @@ import org.apache.directory.server.core.
import org.apache.directory.server.core.integ.IntegrationUtils;
import org.apache.directory.server.core.jndi.CoreContextFactory;
import org.apache.directory.shared.ldap.model.constants.JndiPropertyConstants;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.exception.LdapAuthenticationException;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
import org.apache.directory.shared.ldap.model.exception.LdapUnwillingToPerformException;
import org.apache.directory.shared.ldap.model.message.AliasDerefMode;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
- * Test the Simple BindRequest
+ * Test the Simple BindRequest using the API.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@@ -63,10 +73,26 @@ import org.junit.runner.RunWith;
@CreateDS(name = "SimpleBindIT", allowAnonAccess = true)
public class SimpleBindIT extends AbstractLdapTestUnit
{
+ /** The ldap connection */
+ private LdapConnection connection;
+
+
+ @Before
+ public void setup() throws Exception
+ {
+ connection = IntegrationUtils.getAdminConnection( getService() );
+ }
+
+
+ @After
+ public void shutdown() throws Exception
+ {
+ connection.close();
+ }
/**
* A method to do a search
- */
+ *
private NamingEnumeration<SearchResult> search( DirContext ctx, String baseDn, String filter, int scope )
throws NamingException
{
@@ -85,44 +111,15 @@ public class SimpleBindIT extends Abstra
/**
* try to connect using a known user/password and read an entry.
- *
- * @throws Exception on error
*/
@Test
- public void testSimpleBindAPrincipalAPassword()
+ public void testSimpleBindAPrincipalAPassword() throws LdapException, IOException
{
- // We will bind using JNDI
- // Set up the environment for creating the initial context
- Hashtable<String, Object> env = new Hashtable<String, Object>();
- env.put( DirectoryService.JNDI_KEY, getService() );
- env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
- env.put( Context.PROVIDER_URL, "ou=system" );
-
- // Authenticate as admin and password "secret"
- env.put( Context.SECURITY_AUTHENTICATION, "simple" );
- env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
- env.put( Context.SECURITY_CREDENTIALS, "secret" );
-
- DirContext ctx = null;
-
- // Create the initial context
- try
- {
- ctx = new InitialDirContext( env );
- }
- catch ( NamingException ne )
- {
- fail();
- }
-
- try
- {
- ctx.close();
- }
- catch ( NamingException ne )
- {
- fail();
- }
+ connection.bind( "uid=admin,ou=system", "secret" );
+
+ Entry entry = connection.lookup( "uid=admin,ou=system" );
+
+ assertNotNull( entry );
}
@@ -131,37 +128,10 @@ public class SimpleBindIT extends Abstra
*
* @throws Exception on error
*/
- @Test
- public void testSimpleBindAPrincipalBadPassword()
+ @Test( expected=LdapAuthenticationException.class )
+ public void testSimpleBindAPrincipalBadPassword() throws LdapException, IOException
{
- // We will bind using JNDI
- // Set up the environment for creating the initial context
- Hashtable<String, Object> env = new Hashtable<String, Object>();
- env.put( DirectoryService.JNDI_KEY, getService() );
- env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
- env.put( Context.PROVIDER_URL, "ou=system" );
-
- // Authenticate as admin and password "badsecret"
- env.put( Context.SECURITY_AUTHENTICATION, "simple" );
- env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
- env.put( Context.SECURITY_CREDENTIALS, "badsecret" );
-
- // Create the initial context
- try
- {
- new InitialDirContext( env );
-
- // We should not be connected
- fail();
- }
- catch ( AuthenticationException ae )
- {
- assertTrue( true );
- }
- catch ( NamingException ne )
- {
- fail();
- }
+ connection.bind( "uid=admin,ou=system", "badsecret" );
}
@@ -170,37 +140,10 @@ public class SimpleBindIT extends Abstra
*
* @throws Exception on error
*/
- @Test
- public void testSimpleBindBadPrincipalAPassword()
+ @Test( expected=LdapInvalidDnException.class )
+ public void testSimpleBindBadPrincipalAPassword() throws LdapException, IOException
{
- // We will bind using JNDI
- // Set up the environment for creating the initial context
- Hashtable<String, Object> env = new Hashtable<String, Object>();
- env.put( DirectoryService.JNDI_KEY, getService() );
- env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
- env.put( Context.PROVIDER_URL, "ou=system" );
-
- // Authenticate as admin and password "secret"
- env.put( Context.SECURITY_AUTHENTICATION, "simple" );
- env.put( Context.SECURITY_PRINCIPAL, "admin" );
- env.put( Context.SECURITY_CREDENTIALS, "secret" );
-
- // Create the initial context
- try
- {
- new InitialDirContext( env );
-
- // We should not be connected
- fail();
- }
- catch ( InvalidNameException ine )
- {
- assertTrue( true );
- }
- catch ( NamingException ne )
- {
- fail();
- }
+ connection.bind( "admin", "badsecret" );
}
@@ -209,39 +152,10 @@ public class SimpleBindIT extends Abstra
*
* @throws Exception on error
*/
- @Test
- public void testSimpleBindUnknowPrincipalAPassword()
+ @Test( expected=LdapAuthenticationException.class )
+ public void testSimpleBindUnknowPrincipalAPassword() throws LdapException, IOException
{
- // We will bind using JNDI
- // Set up the environment for creating the initial context
- Hashtable<String, Object> env = new Hashtable<String, Object>();
- env.put( DirectoryService.JNDI_KEY, getService() );
- env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
- env.put( Context.PROVIDER_URL, "ou=system" );
-
- // Authenticate as uid=unknown and password "secret"
- env.put( Context.SECURITY_AUTHENTICATION, "simple" );
- env.put( Context.SECURITY_PRINCIPAL, "uid=unknown,ou=system" );
- env.put( Context.SECURITY_CREDENTIALS, "secret" );
-
- // Create the initial context
- try
- {
- new InitialDirContext( env );
-
- // We should not be connected
- fail();
- }
- catch ( AuthenticationException ae )
- {
- // lae.printStackTrace();
- assertTrue( org.apache.directory.server.i18n.I18n.err( org.apache.directory.server.i18n.I18n.ERR_229 ), ae
- .getMessage().startsWith( org.apache.directory.server.i18n.I18n.ERR_229.getErrorCode() ) );
- }
- catch ( NamingException ne )
- {
- fail();
- }
+ connection.bind( (String)null, "secret" );
}
@@ -251,76 +165,18 @@ public class SimpleBindIT extends Abstra
* @throws Exception on error
*/
@Test
- public void testSimpleBindNoPrincipalNoPassword()
+ public void testSimpleBindNoPrincipalNoPassword() throws LdapException, IOException
{
- // We will bind using JNDI
- // Set up the environment for creating the initial context
- Hashtable<String, Object> env = new Hashtable<String, Object>();
- env.put( DirectoryService.JNDI_KEY, getService() );
- env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
-
- // Bind on the rootDSE
- env.put( Context.PROVIDER_URL, "" );
-
- // Authenticate with no principal and no password : this is an anonymous bind
- env.put( Context.SECURITY_AUTHENTICATION, "simple" );
- env.put( Context.SECURITY_PRINCIPAL, "" );
- env.put( Context.SECURITY_CREDENTIALS, "" );
-
- DirContext ctx = null;
-
- // Create the initial context
- try
- {
- ctx = new InitialDirContext( env );
- }
- catch ( NamingException ne )
- {
- ne.printStackTrace();
- fail();
- }
+ connection.bind( (String)null, null );
// We should be anonymous here.
// Check that we can read the rootDSE
- try
- {
- NamingEnumeration<SearchResult> list = search( ctx, "", "(ObjectClass=*)", SearchControls.OBJECT_SCOPE );
-
- assertNotNull( list );
-
- while ( list.hasMore() )
- {
- SearchResult result = list.next();
- assertNotNull( result );
- }
- }
- catch ( NamingException ne )
- {
- fail();
- }
+ Entry rootDse = connection.lookup( "" );
+ assertNotNull( rootDse );
// Check that we cannot read another entry being anonymous
- try
- {
- NamingEnumeration<SearchResult> list = search( ctx, "uid=admin, ou=system", "(ObjectClass=*)",
- SearchControls.OBJECT_SCOPE );
-
- assertNotNull( list );
- assertFalse( list.hasMore() );
- }
- catch ( NamingException ne )
- {
- fail();
- }
-
- try
- {
- ctx.close();
- }
- catch ( NamingException ne )
- {
- fail();
- }
+ Entry entry = connection.lookup( "uid=admin,ou=system" );
+ assertNull( entry );
}
@@ -329,36 +185,10 @@ public class SimpleBindIT extends Abstra
*
* @throws Exception on error
*/
- @Test
- public void testSimpleBindAPrincipalNoPassword()
+ @Test( expected=LdapUnwillingToPerformException.class )
+ public void testSimpleBindAPrincipalNoPassword() throws LdapException, IOException
{
- // We will bind using JNDI
- // Set up the environment for creating the initial context
- Hashtable<String, Object> env = new Hashtable<String, Object>();
- env.put( DirectoryService.JNDI_KEY, getService() );
- env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
-
- // Bind on the rootDSE
- env.put( Context.PROVIDER_URL, "" );
-
- // Authenticate as admin and password "secret"
- env.put( Context.SECURITY_AUTHENTICATION, "simple" );
- env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
- env.put( Context.SECURITY_CREDENTIALS, "" );
-
- // Create the initial context
- try
- {
- new InitialDirContext( env );
- }
- catch ( OperationNotSupportedException onse )
- {
- assertEquals( "Cannot Bind for Dn uid=admin,ou=system", onse.getMessage() );
- }
- catch ( NamingException ne )
- {
- fail();
- }
+ connection.bind( "uid=admin,ou=system", null );
}
@@ -384,36 +214,10 @@ public class SimpleBindIT extends Abstra
*
* @throws Exception on error
*/
- @Test
- public void testSimpleBindNoPrincipalAPassword() throws Exception
+ @Test( expected=LdapAuthenticationException.class )
+ public void testSimpleBindNoPrincipalAPassword() throws LdapException, IOException
{
- // We will bind using JNDI
- // Set up the environment for creating the initial context
- Hashtable<String, Object> env = new Hashtable<String, Object>();
- env.put( DirectoryService.JNDI_KEY, getService() );
- env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
-
- // Bind on the rootDSE
- env.put( Context.PROVIDER_URL, "" );
-
- // Authenticate as admin and password "secret"
- env.put( Context.SECURITY_AUTHENTICATION, "simple" );
- env.put( Context.SECURITY_PRINCIPAL, "" );
- env.put( Context.SECURITY_CREDENTIALS, "secret" );
-
- // Create the initial context
- try
- {
- new InitialDirContext( env );
- }
- catch ( NameNotFoundException nnfe )
- {
- fail();
- }
- catch ( AuthenticationException ne )
- {
- assertTrue( true );
- }
+ connection.bind( "", "secret" );
}
@@ -423,39 +227,11 @@ public class SimpleBindIT extends Abstra
* @throws Exception on error
*/
@Test
- public void testSimpleBindWithDoubleQuote()
+ public void testSimpleBindWithDoubleQuote() throws LdapException, IOException
{
- // We will bind using JNDI
- // Set up the environment for creating the initial context
- Hashtable<String, Object> env = new Hashtable<String, Object>();
- env.put( DirectoryService.JNDI_KEY, getService() );
- env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
- env.put( Context.PROVIDER_URL, "ou=system" );
-
- // Authenticate as admin and password "secret"
- env.put( Context.SECURITY_AUTHENTICATION, "simple" );
- env.put( Context.SECURITY_PRINCIPAL, "uid=\"admin\",ou=\"system\"" );
- env.put( Context.SECURITY_CREDENTIALS, "secret" );
-
- DirContext ctx = null;
-
- // Create the initial context
- try
- {
- ctx = new InitialDirContext( env );
- }
- catch ( NamingException ne )
- {
- fail();
- }
-
- try
- {
- ctx.close();
- }
- catch ( NamingException ne )
- {
- fail();
- }
+ connection.bind( "uid=\"admin\",ou=\"system\"", "secret" );
+
+ Entry entry = connection.lookup( "uid=admin,ou=system" );
+ assertNotNull( entry );
}
}
Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/MigratedStockCoreISuite.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/MigratedStockCoreISuite.java?rev=1395268&r1=1395267&r2=1395268&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/MigratedStockCoreISuite.java (original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/MigratedStockCoreISuite.java Sun Oct 7 10:30:25 2012
@@ -42,6 +42,7 @@ import org.apache.directory.server.core.
import org.apache.directory.server.core.operations.add.AddIT;
import org.apache.directory.server.core.operations.add.DIRSERVER783IT;
import org.apache.directory.server.core.operations.add.PasswordHashingInterceptorTest;
+import org.apache.directory.server.core.operations.bind.SimpleBindIT;
import org.apache.directory.server.core.operations.move.MoveIT;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@@ -88,11 +89,14 @@ import org.junit.runners.Suite;
// exception
ExceptionServiceIT.class,
- // Operations
+ // Operations add
AddIT.class,
DIRSERVER783IT.class,
- // Operations
+ // Operations.bind
+ SimpleBindIT.class,
+
+ // Operations move
MoveIT.class
})
public class MigratedStockCoreISuite
Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/StockCoreISuite.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/StockCoreISuite.java?rev=1395268&r1=1395267&r2=1395268&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/StockCoreISuite.java (original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/StockCoreISuite.java Sun Oct 7 10:30:25 2012
@@ -34,6 +34,7 @@ import org.apache.directory.server.core.
import org.apache.directory.server.core.jndi.RFC2713IT;
import org.apache.directory.server.core.jndi.ReferralIT;
import org.apache.directory.server.core.jndi.RootDSEIT;
+import org.apache.directory.server.core.jndi.SimpleBindJndiIT;
import org.apache.directory.server.core.jndi.UniqueMemberIT;
import org.apache.directory.server.core.jndi.referral.AddReferralIT;
import org.apache.directory.server.core.jndi.referral.CompareReferralIT;
@@ -46,7 +47,6 @@ import org.apache.directory.server.core.
import org.apache.directory.server.core.jndi.referral.SearchReferralIT;
import org.apache.directory.server.core.normalization.NormalizationServiceIT;
import org.apache.directory.server.core.operational.OperationalAttributeServiceIT;
-import org.apache.directory.server.core.operations.bind.SimpleBindIT;
import org.apache.directory.server.core.operations.compare.CompareDirserver1139IT;
import org.apache.directory.server.core.operations.exists.ExistsIT;
import org.apache.directory.server.core.operations.lookup.LookupIT;
@@ -125,6 +125,7 @@ import org.junit.runners.Suite;
RenameReferralIgnoreIT.class,
RenameReferralIT.class,
SearchReferralIT.class,
+ SimpleBindJndiIT.class,
// normalization
NormalizationServiceIT.class,
@@ -132,12 +133,6 @@ import org.junit.runners.Suite;
// operational
OperationalAttributeServiceIT.class,
- // operations.add
- // AddPerfIT.class
-
- // operations.bind
- SimpleBindIT.class,
-
// operations.compare
CompareDirserver1139IT.class,