blob: c53809a69dedb7fc34289e8631fe20d131e697f0 [file] [log] [blame]
/*
* 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;
import java.util.Hashtable;
import javax.naming.AuthenticationException;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import org.apache.directory.server.unit.AbstractServerTest;
/**
* Tests the effects of using a bad dn in various operations.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
public class BadDnTest extends AbstractServerTest
{
/**
* Bind as a user.
*
* @param bindDn
* @param password
* @return The {@link LdapContext} for the bound user.
* @throws Exception
*/
public LdapContext bind( String bindDn, String password ) throws Exception
{
Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put( "java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory" );
env.put( "java.naming.provider.url", "ldap://localhost:" + port + "/ou=system" );
env.put( "java.naming.security.principal", bindDn );
env.put( "java.naming.security.credentials", password );
env.put( "java.naming.security.authentication", "simple" );
LdapContext ctx = new InitialLdapContext( env, null );
assertNotNull( ctx );
return ctx;
}
/**
* Test with bindDn which is not even found under any namingContext of the
* server.
*
* @throws Exception
*/
public void testBadBindDnNotInContext() throws Exception
{
try
{
bind( "cn=bogus", "blah" );
fail( "should never get here due to a " );
}
catch ( AuthenticationException e )
{
}
}
/**
* Test with bindDn that is under a naming context but points to non-existant user.
* @todo make this pass: see http://issues.apache.org/jira/browse/DIREVE-339
*/
// public void testBadBindDnMalformed() throws Exception
// {
// try
// {
// bind( "system", "blah" );
// fail( "should never get here due to a " );
// }
// catch ( InvalidNameException e ){}
// }
/**
* Test with bindDn that is under a naming context but points to non-existant user.
*
* @throws Exception
*/
public void testBadBindDnInContext() throws Exception
{
try
{
bind( "cn=bogus,ou=system", "blah" );
fail( "should never get here due to a " );
}
catch ( AuthenticationException e )
{
}
}
}